From 260e66853ffcc63b53c75b43ce95b5dc9d051631 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Tue, 10 Oct 2023 12:35:26 +0200 Subject: [PATCH] [FIX] base_delivery_carrier_label : qty from operation for any uom --- .../models/stock_move_line.py | 23 +++---- .../tests/test_get_weight.py | 63 ------------------- 2 files changed, 7 insertions(+), 79 deletions(-) diff --git a/base_delivery_carrier_label/models/stock_move_line.py b/base_delivery_carrier_label/models/stock_move_line.py index 9bc5f252c3..7e48010fc9 100644 --- a/base_delivery_carrier_label/models/stock_move_line.py +++ b/base_delivery_carrier_label/models/stock_move_line.py @@ -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 diff --git a/base_delivery_carrier_label/tests/test_get_weight.py b/base_delivery_carrier_label/tests/test_get_weight.py index febdfa9bc5..17c19a36c8 100644 --- a/base_delivery_carrier_label/tests/test_get_weight.py +++ b/base_delivery_carrier_label/tests/test_get_weight.py @@ -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