diff --git a/l10n_br_delivery_nfe/__manifest__.py b/l10n_br_delivery_nfe/__manifest__.py index 60ae594d1ae1..441037155633 100644 --- a/l10n_br_delivery_nfe/__manifest__.py +++ b/l10n_br_delivery_nfe/__manifest__.py @@ -24,6 +24,7 @@ "views/nfe_document_view.xml", "views/view_product_product.xml", "views/view_product_template.xml", + "views/view_stock_picking.xml", # Wizards "wizards/stock_invoice_onshipping_view.xml", ], diff --git a/l10n_br_delivery_nfe/i18n/pt_BR.po b/l10n_br_delivery_nfe/i18n/pt_BR.po index ed197d6455f1..acea0fdf2d5f 100644 --- a/l10n_br_delivery_nfe/i18n/pt_BR.po +++ b/l10n_br_delivery_nfe/i18n/pt_BR.po @@ -91,3 +91,8 @@ msgstr "Dados dos volumes" #: model:ir.model.fields,field_description:l10n_br_delivery_nfe.field_product_template__product_nfe40_esp msgid "Type of transported volumes" msgstr "Espécie dos volumes transportados" + +#. module: l10n_br_delivery_nfe +#: model:ir.model.fields,field_description:l10n_br_delivery_nfe.field_stock_picking__number_of_volumes +msgid "Number of Volumes" +msgstr "Número de Volumes" diff --git a/l10n_br_delivery_nfe/models/__init__.py b/l10n_br_delivery_nfe/models/__init__.py index 9c2d7e53227a..bd4db85cdb48 100644 --- a/l10n_br_delivery_nfe/models/__init__.py +++ b/l10n_br_delivery_nfe/models/__init__.py @@ -1,3 +1,4 @@ from . import document from . import product_product from . import product_template +from . import stock_picking diff --git a/l10n_br_delivery_nfe/models/stock_picking.py b/l10n_br_delivery_nfe/models/stock_picking.py new file mode 100644 index 000000000000..a65f76a49438 --- /dev/null +++ b/l10n_br_delivery_nfe/models/stock_picking.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 Diego Paradeda - KMEE +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + number_of_volumes = fields.Integer( + string="Number of Volumes", + compute="_compute_number_of_volumes", + store=False, + default=0, + copy=False, + ) + + def _compute_number_of_volumes(self): + for picking in self: + if len(picking.invoice_ids) == 1: + picking.number_of_volumes = sum( + [ + float(v) + for v in picking.invoice_ids.mapped("nfe40_vol.nfe40_qVol") + ] + ) + else: + picking.number_of_volumes = 0 diff --git a/l10n_br_delivery_nfe/tests/test_delivery_nfe.py b/l10n_br_delivery_nfe/tests/test_delivery_nfe.py index 2b72b8385fd0..a895d1fe102d 100644 --- a/l10n_br_delivery_nfe/tests/test_delivery_nfe.py +++ b/l10n_br_delivery_nfe/tests/test_delivery_nfe.py @@ -31,6 +31,13 @@ def test_invoicing_picking_volume_lucro_presumido(self): self.prod1.net_weight = 1 self.prod2.net_weight = 5 + # Number of Volumes - zero before invoice + self.assertEqual( + picking.number_of_volumes, + 0, + "No of Vols must be zero before invoicing.", + ) + # Invoice picking.set_to_be_invoiced() self.picking_move_state(picking) @@ -105,6 +112,14 @@ def test_invoicing_picking_volume_lucro_presumido(self): "Unexpected value for the field nfe40_qVol in Fiscal Details.", ) + # Number of Volumes + picking._compute_number_of_volumes() + self.assertEqual( + picking.number_of_volumes, + 4, + "Wrong number of volumes.", + ) + # Testing Lucro Presumido - with pack def test_invoicing_picking_volume_with_package_lucro_presumido(self): """Test Invoicing Picking NFe volume - Lucro Presumido - with package""" @@ -124,6 +139,13 @@ def test_invoicing_picking_volume_with_package_lucro_presumido(self): self.prod1.net_weight = 3 self.prod2.net_weight = 6 + # Number of Volumes - zero before invoice + self.assertEqual( + picking.number_of_volumes, + 0, + "No of Vols must be zero before invoicing.", + ) + # Invoice picking.set_to_be_invoiced() picking.action_confirm() @@ -203,3 +225,11 @@ def test_invoicing_picking_volume_with_package_lucro_presumido(self): ["1"], "Unexpected value for the field nfe40_qVol in Fiscal Details.", ) + + # Number of Volumes + picking._compute_number_of_volumes() + self.assertEqual( + picking.number_of_volumes, + 1, + "Wrong number of volumes.", + ) diff --git a/l10n_br_delivery_nfe/views/view_stock_picking.xml b/l10n_br_delivery_nfe/views/view_stock_picking.xml new file mode 100644 index 000000000000..4936c7ebd57d --- /dev/null +++ b/l10n_br_delivery_nfe/views/view_stock_picking.xml @@ -0,0 +1,14 @@ + + + stock.picking + + + + + + + +