Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16][FIX] base_delivery_carrier_label : qty from operation for any uom #719

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the quantity is converted only if it's done ; if it's only reserved there is no convertion ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qty done is meant to be consistent with the uom of the stock move (it should named uom_qty_done actually) while reserved_qty consistent with the uom of the product. (reserved_uom_qty exists and is consistent with the uom of the stock move).

)
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
Loading