From b9379390fb056c60d07d0606aff3b996c600aed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Arturo=20Garci=CC=81a?= Date: Thu, 1 Oct 2026 00:48:17 -0400 Subject: [PATCH] Guard invoice fiscal defaults on partial records --- invoice.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/invoice.py b/invoice.py index 50ae30a..f4ed5d4 100755 --- a/invoice.py +++ b/invoice.py @@ -799,8 +799,9 @@ class Invoice(metaclass=PoolMeta): "Return an invoice default configured on account configuration." Configuration = Pool().get('account.configuration') config = Configuration(1) + company = getattr(self, 'company', None) company_id = ( - self.company.id if self.company + company.id if company else Transaction().context.get('company')) if company_id: @@ -814,16 +815,26 @@ class Invoice(metaclass=PoolMeta): Apply configured fiscal reporting defaults without replacing values already selected by the user or copied from another invoice. """ - if self.type == 'out' and not self.revenue_type: + invoice_type = getattr(self, 'type', None) + + if ( + invoice_type == 'out' + and 'revenue_type' in self.__class__._fields + and not getattr(self, 'revenue_type', None)): self.revenue_type = ( self._ncf_get_configuration_default_invoice_field( 'default_customer_revenue_type')) - elif self.type == 'in' and not self.expense_type: + elif ( + invoice_type == 'in' + and 'expense_type' in self.__class__._fields + and not getattr(self, 'expense_type', None)): self.expense_type = ( self._ncf_get_configuration_default_invoice_field( 'default_supplier_expense_type')) - if not self.payment_method: + if ( + 'payment_method' in self.__class__._fields + and not getattr(self, 'payment_method', None)): self.payment_method = ( self._ncf_get_configuration_default_invoice_field( 'default_payment_method'))