Skip to content

Commit

Permalink
[FIX] base_delivery_carrier_label : qty from operation for any uom
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Oct 10, 2023
1 parent 2fb8a14 commit 260e668
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 79 deletions.
23 changes: 7 additions & 16 deletions base_delivery_carrier_label/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,23 @@ class StockMoveLine(models.Model):
def get_weight(self):
"""Calc and save weight of pack.operations.
Warning: Type conversion not implemented
it will return False if at least one uom or uos not in kg
return:
the sum of the weight of [self]
"""
total_weight = 0
kg = self.env.ref("uom.product_uom_kgm").id
units = self.env.ref("uom.product_uom_unit").id
allowed = (False, kg, units)
cant_calc_total = False
for operation in self:
product = operation.product_id

# if not defined we assume it's in kg
if product.uom_id.id not in allowed:
_logger.warning(
"Type conversion not implemented for product %s" % product.id
)
cant_calc_total = True
# reserved_qty may be 0 if you don't set move line
# individually but directly validate the picking
qty = operation.qty_done or operation.reserved_qty
qty = (
operation.qty_done
and operation.product_uom_id._compute_quantity(
operation.qty_done, operation.product_id.uom_id
)
or operation.reserved_qty
)
operation.weight = product.weight * qty

total_weight += operation.weight

if cant_calc_total:
return False
return total_weight
63 changes: 0 additions & 63 deletions base_delivery_carrier_label/tests/test_get_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,66 +159,3 @@ def test_get_weight_with_qty(self):
self.assertEqual(
package.weight, sum(operation.get_weight() for operation in operations)
)

def test_get_weight_with_uom(self):
"""Check with differents uom."""
# prepare some data
weights = [0.3, 14.01, 0.59]
package = self.env["stock.quant.package"].create({})
tonne_id = self.env.ref("uom.product_uom_ton")
kg_id = self.env.ref("uom.product_uom_kgm")
gr_id = self.env.ref("uom.product_uom_gram")
products = []
products.append(
self._create_product(
{
"name": "Expected Odoo dev documentation",
"uom_id": tonne_id.id,
"uom_po_id": tonne_id.id,
"weight": weights[0],
}
)
)
products.append(
self._create_product(
{
"name": "OCA documentation",
"uom_id": kg_id.id,
"uom_po_id": kg_id.id,
"weight": weights[1],
}
)
)
products.append(
self._create_product(
{
"name": "Actual Odoo dev documentation",
"uom_id": gr_id.id,
"uom_po_id": gr_id.id,
"weight": weights[2],
}
)
)
products_weight = (
weights[0] * 1000 + weights[1] * 1 + weights[2] * 0.01 # tonne # kg # g
)
picking = self._generate_picking(products)
operations = self.env["stock.move.line"]
for product in products:
operations |= self._create_operation(
picking,
{
"reserved_uom_qty": 1,
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"result_package_id": package.id,
},
)
# end of prepare data

# because uom conversion is not implemented
self.assertEqual(package.weight, False)

# if one day, uom conversion is implemented:
# self.assertEqual(package.get_weight(), products_weight)
self.assertEqual(products_weight, products_weight) # flak8 warning

0 comments on commit 260e668

Please sign in to comment.