Skip to content

Commit

Permalink
[ADD] computed no of vols (from invoice) in stock.picking
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed Jun 4, 2024
1 parent c1194e6 commit c3d28c5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_br_delivery_nfe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
5 changes: 5 additions & 0 deletions l10n_br_delivery_nfe/i18n/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions l10n_br_delivery_nfe/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import document
from . import product_product
from . import product_template
from . import stock_picking
27 changes: 27 additions & 0 deletions l10n_br_delivery_nfe/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions l10n_br_delivery_nfe/tests/test_delivery_nfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand All @@ -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()
Expand Down Expand Up @@ -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.",
)
14 changes: 14 additions & 0 deletions l10n_br_delivery_nfe/views/view_stock_picking.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<record id="view_picking_withcarrier_out_form_inherit" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="delivery.view_picking_withcarrier_out_form" />
<field name="arch" type="xml">
<xpath expr="//group[@name='carrier_data']" position="inside">
<field
name="number_of_volumes"
attrs="{'invisible': [('invoice_ids', '=', [])]}"
/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit c3d28c5

Please sign in to comment.