Skip to content

Commit

Permalink
fixup! [ADD] Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed May 29, 2024
1 parent e83a1fd commit aade86a
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
96 changes: 95 additions & 1 deletion l10n_br_delivery_nfe/tests/test_delivery_nfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _change_user_company(self, company):
self.env.user.company_ids += company
self.env.user.company_id = company

# Testando o Lucro Presumido
# Testing Lucro Presumido - wo pack
def test_invoicing_picking_volume_lucro_presumido(self):
"""Test Invoicing Picking NFe volume - Lucro Presumido"""
self._change_user_company(self.env.ref("l10n_br_base.empresa_lucro_presumido"))
Expand All @@ -41,6 +41,7 @@ def test_invoicing_picking_volume_lucro_presumido(self):
# Force product availability
for move in picking.move_ids_without_package:
move.quantity_done = move.product_uom_qty
# Validate
picking.button_validate()
self.assertEqual(picking.state, "done")
wizard_obj = self.invoice_wizard.with_context(
Expand Down Expand Up @@ -111,3 +112,96 @@ def test_invoicing_picking_volume_lucro_presumido(self):
["4.0"],
"Unexpected value for the field nfe40_qVol in Fiscal Details.",
)

# Testing Lucro Presumido - with pack
def test_invoicing_picking_volume_with_package_lucro_presumido(self):
"""Test Invoicing Picking NFe volume - Lucro Presumido - with package"""
self._change_user_company(self.env.ref("l10n_br_base.empresa_lucro_presumido"))
picking = self.env.ref("l10n_br_stock_account.lucro_presumido-picking_2")

# Set product volume data
self.prod1.product_nfe40_esp = "esp teste"
self.prod1.product_nfe40_marca = "marca teste"
self.prod1.weight = 2
self.prod2.weight = 4
self.prod1.net_weight = 3
self.prod2.net_weight = 6

# Invoice
picking.set_to_be_invoiced()
picking.action_confirm()
# Check product availability
picking.action_assign()
# Put in pack
picking.action_put_in_pack()
# Validate
picking.button_validate()
self.assertEqual(picking.state, "done")
wizard_obj = self.invoice_wizard.with_context(
active_ids=picking.ids,
active_model=picking._name,
active_id=picking.id,
)
fields_list = wizard_obj.fields_get().keys()
wizard_values = wizard_obj.default_get(fields_list)
wizard = wizard_obj.create(wizard_values)
wizard.onchange_group()

self.assertEqual(
wizard.vol_ids.mapped("nfe40_esp"),
["esp teste"],
"Unexpected value for the field nfe40_esp in Stock Invoice Onshipping.",
)
self.assertEqual(
wizard.vol_ids.mapped("nfe40_marca"),
["marca teste"],
"Unexpected value for the field nfe40_marca in Stock Invoice Onshipping.",
)
self.assertEqual(
wizard.vol_ids.mapped("nfe40_pesoB"),
[12],
"Unexpected value for the field nfe40_pesoB in Stock Invoice Onshipping.",
)
self.assertEqual(
wizard.vol_ids.mapped("nfe40_pesoL"),
[18],
"Unexpected value for the field nfe40_pesoL in Stock Invoice Onshipping.",
)
self.assertEqual(
wizard.vol_ids.mapped("nfe40_qVol"),
["1"],
"Unexpected value for the field nfe40_qVol in Stock Invoice Onshipping.",
)

wizard.fiscal_operation_journal = False
wizard.action_generate()

self.assertEqual(picking.invoice_state, "invoiced")

# Fiscal details
volume_ids = picking.invoice_ids.fiscal_document_id.nfe40_vol
self.assertEqual(
volume_ids.mapped("nfe40_esp"),
["esp teste"],
"Unexpected value for the field nfe40_esp in Fiscal Details.",
)
self.assertEqual(
volume_ids.mapped("nfe40_marca"),
["marca teste"],
"Unexpected value for the field nfe40_marca in Fiscal Details.",
)
self.assertEqual(
volume_ids.mapped("nfe40_pesoB"),
[12],
"Unexpected value for the field nfe40_pesoB in Fiscal Details.",
)
self.assertEqual(
volume_ids.mapped("nfe40_pesoL"),
[18],
"Unexpected value for the field nfe40_pesoL in Fiscal Details.",
)
self.assertEqual(
volume_ids.mapped("nfe40_qVol"),
["1"],
"Unexpected value for the field nfe40_qVol in Fiscal Details.",
)
9 changes: 7 additions & 2 deletions l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def _get_volume_data_package_level(self):
def _get_volume_data_wo_package(self):
"""Generate a single volume for lines without package"""
picking_id = self._get_picking()
if not picking_id.move_line_ids_without_package:
# Filter out move lines with in a package
if not picking_id.move_line_ids_without_package.filtered(
lambda ml: not ml.package_level_id
):
return []

vols_data = [
Expand All @@ -91,7 +94,9 @@ def _get_volume_data_wo_package(self):
"nfe40_pesoB": 0,
}
]
for line in picking_id.move_line_ids_without_package:
for line in picking_id.move_line_ids_without_package.filtered(
lambda ml: not ml.package_level_id
):
vols_data[0]["nfe40_qVol"] += line.qty_done
vols_data[0]["nfe40_esp"] = (
vols_data[0]["nfe40_esp"] or line.product_id.product_nfe40_esp
Expand Down

0 comments on commit aade86a

Please sign in to comment.