From 3a03fa7bb0f2f748d27a849f91a282d080f91db2 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Wed, 15 Jan 2025 15:32:49 -0300 Subject: [PATCH] [IMP] l10n_br_purchase: improving the search by fiscal document type --- l10n_br_purchase/models/purchase_order.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/l10n_br_purchase/models/purchase_order.py b/l10n_br_purchase/models/purchase_order.py index 1a71866a9227..9a9e0d73ddbf 100644 --- a/l10n_br_purchase/models/purchase_order.py +++ b/l10n_br_purchase/models/purchase_order.py @@ -108,11 +108,22 @@ def _prepare_invoice(self): invoice_vals = super()._prepare_invoice() if self.fiscal_operation_id: # O caso Brasil se caracteriza por ter a Operação Fiscal + document_type_id = ( + self.order_line[0].fiscal_operation_line_id.document_type_id.id + if self.order_line + and self.order_line[0].fiscal_operation_line_id.document_type_id + else ( + self.fiscal_operation_id.document_type_ids[0].document_type_id.id + if self.fiscal_operation_id + and self.fiscal_operation_id.document_type_ids + else self.company_id.document_type_id.id + ) + ) invoice_vals.update( { "ind_final": self.ind_final, "fiscal_operation_id": self.fiscal_operation_id.id, - "document_type_id": self.company_id.document_type_id.id, + "document_type_id": document_type_id, } ) return invoice_vals