Skip to content

Commit

Permalink
[ADD] product_net_weight compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed May 27, 2024
1 parent 202bdfb commit 4527e1f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
6 changes: 5 additions & 1 deletion l10n_br_delivery_nfe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"maintainers": ["mbcosta"],
"website": "https://github.com/OCA/l10n-brazil",
"version": "14.0.1.1.0",
"depends": ["l10n_br_nfe", "l10n_br_account", "l10n_br_delivery"],
"depends": [
"l10n_br_nfe",
"l10n_br_account",
"l10n_br_delivery",
],
"data": [
# Security
"security/ir.model.access.csv",
Expand Down
18 changes: 3 additions & 15 deletions l10n_br_delivery_nfe/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,11 @@
class ProductProduct(models.Model):
_inherit = "product.product"

volume_type = fields.Selection(
string="Volume Type",
# TODO: ADD DEFAULT METHOD + res.company field
selection=[
("manual", "Criar Manualmente"),
("product_qty", "Qtd. de Produtos"),
],
)

product_nfe40_esp = fields.Char(string="Espécie dos volumes transportados")

product_nfe40_marca = fields.Char(string="Marca dos volumes transportados")

product_nfe40_pesoL = fields.Float(
string="Peso L. (kg)",
)

product_nfe40_pesoB = fields.Float(
string="Peso B. (kg)",
# Manter compatibilidade com módulo: product_net_weight
net_weight = fields.Float(
string="Net Weight",
)
56 changes: 45 additions & 11 deletions l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,60 @@ def _convert_volumes_to_write(self, data):
"nfe40_pesoB": data.nfe40_pesoB,
}

def _get_single_volume_data(self):
"""Case single volume"""
def _get_picking(self):
active_ids = self.env.context.get("active_ids", [])
if active_ids:
active_ids = active_ids[0]
pick_obj = self.env["stock.picking"]
picking_id = pick_obj.browse(active_ids)
return pick_obj.browse(active_ids)

def _get_volume_data_package_level(self):
"""Generate a single volume for packages"""
picking_id = self._get_picking()

vols_data = []
if picking_id.package_ids:
for package_level_id in picking_id.package_level_ids:
# TODO: consider adding field net_weight in stock.quant.package
manual_weight = package_level_id.package_id.shipping_weight
vol_data = {

Check warning on line 57 in l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py#L56-L57

Added lines #L56 - L57 were not covered by tests
"nfe40_qVol": 0,
"nfe40_esp": "",
"nfe40_marca": "",
"nfe40_pesoL": 0,
"nfe40_pesoB": (manual_weight if manual_weight else 0),
}
for line in package_level_id.move_line_ids:
vol_data["nfe40_qVol"] += line.qty_done
pesoL = line.qty_done * line.product_id.net_weight
pesoB = line.qty_done * line.product_id.weight
vol_data["nfe40_pesoL"] += pesoL
vol_data["nfe40_pesoB"] += 0 if manual_weight else pesoB
vols_data.append(vol_data)

Check warning on line 70 in l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py#L65-L70

Added lines #L65 - L70 were not covered by tests

return vols_data

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:
return []

Check warning on line 78 in l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_delivery_nfe/wizards/stock_invoice_onshipping.py#L78

Added line #L78 was not covered by tests

vols_data = [
{
"nfe40_qVol": 0,
"nfe40_esp": "",
"nfe40_marca": 0,
"nfe40_marca": "",
"nfe40_pesoL": 0,
"nfe40_pesoB": 0,
}
]

for line in picking_id.move_line_ids:
if line.product_id.volume_type == "product_qty":
vols_data[0]["nfe40_qVol"] += line.qty_done
vols_data[0]["nfe40_pesoL"] += line.product_id.product_nfe40_pesoL
vols_data[0]["nfe40_pesoB"] += line.product_id.product_nfe40_pesoB
for line in picking_id.move_line_ids_without_package:
vols_data[0]["nfe40_qVol"] += line.qty_done
pesoL = line.qty_done * line.product_id.net_weight
pesoB = line.qty_done * line.product_id.weight
vols_data[0]["nfe40_pesoL"] += pesoL
vols_data[0]["nfe40_pesoB"] += pesoB

return vols_data

Expand All @@ -73,7 +104,10 @@ def default_get(self, fields_list):
"""
result = super().default_get(fields_list)

vols_data = self._get_single_volume_data()
vols_data = (
self._get_volume_data_wo_package() + self._get_volume_data_package_level()
)

vol_ids = [(0, 0, vol) for vol in vols_data]
result["vol_ids"] = vol_ids
return result
Expand Down

0 comments on commit 4527e1f

Please sign in to comment.