From 5255cb3fdc2f5199558b3baf369e4b9104e03f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20Mil=C3=A9o?= Date: Sun, 26 May 2024 21:05:53 -0300 Subject: [PATCH] [IMP] Reserve document number on picking pack operation --- l10n_br_stock_account/models/stock_picking.py | 21 ++++++++++++++++++ l10n_br_stock_account/views/stock_picking.xml | 20 +++++++++++++++++ .../wizards/stock_invoice_onshipping.py | 22 ++++++++++--------- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/l10n_br_stock_account/models/stock_picking.py b/l10n_br_stock_account/models/stock_picking.py index 9d459d07199b..68358e26851b 100644 --- a/l10n_br_stock_account/models/stock_picking.py +++ b/l10n_br_stock_account/models/stock_picking.py @@ -87,3 +87,24 @@ def fields_view_get( } return order_view + + def _put_in_pack(self, move_line_ids, create_package_level=True): + package = super()._put_in_pack(move_line_ids, create_package_level) + + # [x]. Número da nota fiscal e série; + # [x] Salvar informação no picking; + # [x] Adaptar wizard para copiar essas informações para a fatura; + # [x] Verificar que ao confirmar a fatura um nº não é gerado novamente; + # 5. Colocar a informação do nº e série na etiqueta; + + if self.company_id.document_type_id and self.fiscal_operation_id: + # 6. Deixar esta opção configurável por operação fiscal ou por picking type? + + self.document_type_id = self.company_id.document_type_id + self.document_serie_id = self.document_type_id.get_document_serie( + self.company_id, self.fiscal_operation_id + ) + self.document_serie = self.document_serie_id.code + self.document_number = self.document_serie_id.next_seq_number() + + return package diff --git a/l10n_br_stock_account/views/stock_picking.xml b/l10n_br_stock_account/views/stock_picking.xml index 8362fd7a4dc6..2db34c735590 100644 --- a/l10n_br_stock_account/views/stock_picking.xml +++ b/l10n_br_stock_account/views/stock_picking.xml @@ -221,6 +221,26 @@ + + + + + + + + + + + + + + + + diff --git a/l10n_br_stock_account/wizards/stock_invoice_onshipping.py b/l10n_br_stock_account/wizards/stock_invoice_onshipping.py index 3e16530bfbe4..ab2cd07334d2 100644 --- a/l10n_br_stock_account/wizards/stock_invoice_onshipping.py +++ b/l10n_br_stock_account/wizards/stock_invoice_onshipping.py @@ -76,16 +76,18 @@ def _build_invoice_values_from_pickings(self, pickings): fiscal_vals = picking._prepare_br_fiscal_dict() - document_type = picking.company_id.document_type_id - document_type_id = picking.company_id.document_type_id.id - - fiscal_vals["document_type_id"] = document_type_id - - document_serie = document_type.get_document_serie( - picking.company_id, picking.fiscal_operation_id - ) - if document_serie: - fiscal_vals["document_serie_id"] = document_serie.id + if not fiscal_vals.get("document_type_id"): + # não sobrescreve os dados caso ás informações já tenham sido geradas + # nó método _put_in_pack + document_type_id = picking.company_id.document_type_id + + fiscal_vals["document_type_id"] = document_type_id.id + + document_serie = document_type_id.get_document_serie( + picking.company_id, picking.fiscal_operation_id + ) + if document_serie: + fiscal_vals["document_serie_id"] = document_serie.id if picking.fiscal_operation_id and picking.fiscal_operation_id.journal_id: fiscal_vals["journal_id"] = picking.fiscal_operation_id.journal_id.id