product-attribute icon indicating copy to clipboard operation
product-attribute copied to clipboard

[17.0][FIX] product_secondary_unit: unnecessary sec_uom_qty set.

Open Qlasta opened this issue 8 months ago • 1 comments

Setting secondary uom qty, triggers unnecessary calculation on lines, where secondary uom id is not set (used).

Description Problem noticed with sale_order_secondary_unit module, sale.order.line which inherits product_secondary_unit_mixin. By creating sale order line from backend (not using UI, using connection) without secondary_uom_id and setting custom price_unit results wrong price_subtotal - not using custom price_unit, but using price from pricelist.

Current Behaviour Run simple test on sale_order_secondary_unit module:

class TestSaleOrderLine(TransactionCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.SaleOrder = cls.env["sale.order"]
        cls.SaleOrderLine = cls.env["sale.order.line"]
        cls.ProductProduct = cls.env["product.product"]
        cls.partner_1 = cls.env.ref("base.res_partner_1")
        cls.product_1 = cls.ProductProduct.create(
            {
                "name": "test",
                "lst_price": 13.00,
            }
        )

    def test_01_sale_order_create_custom_price_subtotal_wo_sec_unit(self):
        # GIVEN
        order_vals = {
            "partner_id": self.partner_1.id,
            "order_line": [
                Command.create(
                    {
                        "product_id": self.product_1.id,
                        "product_uom_qty": 1,
                        "price_unit": 2000.00,
                    }
                )
            ],
        }
        # WHEN
        self.order = self.SaleOrder.create(order_vals)
        # THEN
        self.order_lines = self.SaleOrderLine.search([("order_id", "=", self.order.id)])
        self.assertEqual(self.order_lines.price_unit, 2000.00)
        self.assertEqual(self.order_lines.price_subtotal, 2000.00)
        self.assertFalse(self.order_lines.secondary_uom_id)
        self.assertFalse(self.order_lines.secondary_uom_qty)

Test fails:

 test_01_sale_order_create_custom_price_subtotal_wo_sec_unit
odoo-1  |     self.assertEqual(self.order_lines.price_subtotal, 2000.00)
odoo-1  | AssertionError: 13.0 != 2000.0

Expected Behavior Test does not fail. Possible to set custom price unit with correct subtotal.

Proposed implementation Remove unnecessary trigger: Set secondary_uom_qty when secondary_uom_id is not set, only if it is not 0.

Qlasta avatar Apr 30 '25 10:04 Qlasta

Hi @sergio-teruel, some modules you are maintaining are being modified, check this out!

OCA-git-bot avatar Apr 30 '25 10:04 OCA-git-bot