Skip to content

Commit

Permalink
[IMP]pms_api_rest: improve GET partner documment mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Apr 22, 2024
1 parent 50dad1d commit 5496377
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pms_api_rest/services/pms_partner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,27 @@ def get_partners(self, pms_partner_search_params):
.filtered(lambda x: x.checkout)
.mapped("checkout")
)
doc_number = False
doc_record = False
document_number = False
document_type = False
document_support_number = False
document_country_id = False
document_expedition_date = False
if partner.id_numbers:
doc_number = partner.id_numbers[0]
if doc_number:
if doc_number.name:
document_number = doc_number.name
if doc_number.category_id:
document_type = doc_number.category_id.id
if doc_number.support_number:
document_support_number = doc_number.support_number
doc_record = partner.id_numbers[0]
if doc_record:
if doc_record.name:
document_number = doc_record.name
if doc_record.category_id:
document_type = doc_record.category_id.id
if doc_record.support_number:
document_support_number = doc_record.support_number
if doc_record.country_id:
document_country_id = doc_record.country_id.id
if doc_record.valid_from:
document_expedition_date = datetime.combine(
doc_record.valid_from, datetime.min.time()
).isoformat()
result_partners.append(
PmsPartnerInfo(
id=partner.id,
Expand Down Expand Up @@ -260,7 +268,9 @@ def get_partners(self, pms_partner_search_params):
documentSupportNumber=document_support_number
if document_support_number
else None,
documentCountryId=doc_number.country_id.id if doc_number.country_id else None,
documentCountryId=document_country_id
if document_country_id
else None,
vatNumber=partner.vat
if partner.vat
else partner.aeat_identification
Expand All @@ -271,10 +281,8 @@ def get_partners(self, pms_partner_search_params):
else partner.aeat_identification_type
if partner.aeat_identification_type
else None,
documentExpeditionDate=datetime.combine(
doc_number.valid_from, datetime.min.time()
).isoformat()
if doc_number and doc_number.valid_from
documentExpeditionDate=document_expedition_date
if document_expedition_date
else None,
comment=partner.comment if partner.comment else None,
language=partner.lang if partner.lang else None,
Expand Down Expand Up @@ -506,7 +514,7 @@ def get_partner_by_doc_number(self, document_type, document_number):
)
partners = []
if partner:
doc_number = partner.id_numbers.filtered(
doc_record = partner.id_numbers.filtered(
lambda doc: doc.category_id.id == doc_type.id
)
PmsCheckinPartnerInfo = self.env.datamodels["pms.checkin.partner.info"]
Expand All @@ -520,14 +528,14 @@ def get_partner_by_doc_number(self, document_type, document_number):
email=partner.email or None,
mobile=partner.mobile or None,
documentType=doc_type.id or None,
documentNumber=doc_number.name or None,
documentNumber=doc_record.name or None,
documentExpeditionDate=datetime.combine(
doc_number.valid_from, datetime.min.time()
doc_record.valid_from, datetime.min.time()
).isoformat()
if doc_number.valid_from
if doc_record.valid_from
else None,
documentSupportNumber=doc_number.support_number or None,
documentCountryId=doc_number.country_id.id or None,
documentSupportNumber=doc_record.support_number or None,
documentCountryId=doc_record.country_id.id or None,
gender=partner.gender or None,
birthdate=datetime.combine(
partner.birthdate_date, datetime.min.time()
Expand Down

0 comments on commit 5496377

Please sign in to comment.