From 1e5e962f45ad781b767a08913e947d3644f9f439 Mon Sep 17 00:00:00 2001 From: leodube-aot <122323255+leodube-aot@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:00:21 -0600 Subject: [PATCH] 21953 Update Address model for furnishings job (#2820) * Update dissolutions to use legislation datetime * Undo refactor * Add furnishing address type * Add Address.find_by method --- legal-api/src/legal_api/models/address.py | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/legal-api/src/legal_api/models/address.py b/legal-api/src/legal_api/models/address.py index 28182ed8f0..b8ce59188d 100644 --- a/legal-api/src/legal_api/models/address.py +++ b/legal-api/src/legal_api/models/address.py @@ -32,7 +32,8 @@ class Address(db.Model): # pylint: disable=too-many-instance-attributes MAILING = 'mailing' DELIVERY = 'delivery' - ADDRESS_TYPES = [MAILING, DELIVERY] + FURNISHING = 'furnishing' + ADDRESS_TYPES = [MAILING, DELIVERY, FURNISHING] JSON_MAILING = 'mailingAddress' JSON_DELIVERY = 'deliveryAddress' JSON_ADDRESS_TYPES = [JSON_MAILING, JSON_DELIVERY] @@ -101,3 +102,24 @@ def find_by_id(cls, internal_id: int = None): if internal_id: address = cls.query.filter_by(id=internal_id).one_or_none() return address + + @classmethod + def find_by(cls, + business_id: int = None, + furnishings_id: int = None, + office_id: int = None) -> dict: + """Return the address matching.""" + query = db.session.query(Address) + addresses = [] + + if business_id: + query = query.filter(Address.business_id == business_id) + + if furnishings_id: + query = query.filter(Address.furnishings_id == furnishings_id) + + if office_id: + query = query.filter(Address.office_id == office_id) + + addresses = query.order_by(Address.id).all() + return addresses