From 3e73d6ac7e296481ce44ccc51681bf0564da0e6a Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sun, 15 Dec 2024 13:47:18 +0100 Subject: [PATCH] fix: construct contact's full name --- eu_einvoice/european_e_invoice/custom/sales_invoice.py | 6 +++--- eu_einvoice/utils.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/eu_einvoice/european_e_invoice/custom/sales_invoice.py b/eu_einvoice/european_e_invoice/custom/sales_invoice.py index 2b8f850..6886a27 100644 --- a/eu_einvoice/european_e_invoice/custom/sales_invoice.py +++ b/eu_einvoice/european_e_invoice/custom/sales_invoice.py @@ -16,7 +16,7 @@ from eu_einvoice.common_codes import CommonCodeRetriever from eu_einvoice.schematron import get_validation_errors -from eu_einvoice.utils import EInvoiceProfile, get_drafthorse_schema, get_guideline +from eu_einvoice.utils import EInvoiceProfile, get_drafthorse_schema, get_full_name, get_guideline if TYPE_CHECKING: from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice @@ -250,7 +250,7 @@ def _set_seller_electronic_address(self): def _set_seller_contact(self): seller_contact_phone = self.company.phone_no if self.seller_contact: - self.doc.trade.agreement.seller.contact.person_name = self.seller_contact.full_name + self.doc.trade.agreement.seller.contact.person_name = get_full_name(self.seller_contact) if self.seller_contact.department: self.doc.trade.agreement.seller.contact.department_name = self.seller_contact.department if self.seller_contact.email_id: @@ -311,7 +311,7 @@ def _set_buyer_address(self): def _set_buyer_contact(self): buyer_contact_phone = self.invoice.contact_mobile if self.buyer_contact: - self.doc.trade.agreement.buyer.contact.person_name = self.buyer_contact.full_name + self.doc.trade.agreement.buyer.contact.person_name = get_full_name(self.buyer_contact) if self.buyer_contact.department: self.doc.trade.agreement.buyer.contact.department_name = self.buyer_contact.department if self.buyer_contact.phone: diff --git a/eu_einvoice/utils.py b/eu_einvoice/utils.py index 4320299..871059a 100644 --- a/eu_einvoice/utils.py +++ b/eu_einvoice/utils.py @@ -1,5 +1,9 @@ from enum import Enum from functools import total_ordering +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from frappe.contacts.doctype.contact.contact import Contact @total_ordering @@ -58,6 +62,10 @@ def get_profile(guideline: str) -> EInvoiceProfile: return GUIDELINE_TO_PROFILE.get(guideline) +def get_full_name(contact: "Contact") -> str: + return f"{contact.first_name or ''} {contact.last_name or ''}".strip() + + def identity(value): """Used for dummy translation""" return value