Skip to content

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

Merged
Qlasta merged 1 commit into17.0-versadafrom
17.0-fix-product-secondary-unit-not-trigger-sec-qty
Apr 30, 2025
Merged

[17.0][FIX] product_secondary_unit: unnecessary sec_uom_qty set.#9
Qlasta merged 1 commit into17.0-versadafrom
17.0-fix-product-secondary-unit-not-trigger-sec-qty

Conversation

@Qlasta
Copy link

@Qlasta Qlasta commented Apr 29, 2025

Setting sec uom qty, triggers unnecessary calculation on lines, where sec uom id is not set (used).
task id - 25342

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 Qlasta force-pushed the 17.0-fix-product-secondary-unit-not-trigger-sec-qty branch from 380db4f to c1377db Compare April 29, 2025 08:38
@Qlasta Qlasta marked this pull request as ready for review April 29, 2025 08:41
@Qlasta Qlasta changed the base branch from 17.0 to 17.0-versada April 29, 2025 08:42
@Qlasta Qlasta requested a review from oerp-odoo April 29, 2025 08:43
for line in self:
if not line.secondary_uom_id:
line.secondary_uom_qty = 0.0
if self.secondary_uom_qty != 0.0:

Choose a reason for hiding this comment

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

shouldn't we use float_is_zero when checking this?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, updated.

@Qlasta Qlasta force-pushed the 17.0-fix-product-secondary-unit-not-trigger-sec-qty branch 2 times, most recently from 7f9f85b to 89bebfd Compare April 29, 2025 13:40
@Qlasta Qlasta force-pushed the 17.0-fix-product-secondary-unit-not-trigger-sec-qty branch from 89bebfd to c1e63df Compare April 29, 2025 13:45
@Qlasta Qlasta requested a review from oerp-odoo April 29, 2025 13:48
@Qlasta Qlasta merged commit 3f43059 into 17.0-versada Apr 30, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants