From 0a7b957bdb1786a0c28a69e5e4f0860a7c7c9e36 Mon Sep 17 00:00:00 2001 From: sergio-teruel Date: Mon, 22 Jun 2026 15:04:42 +0200 Subject: [PATCH] [FIX] purchase_order_secondary_unit: avoid price recomputation from rounded secondary price --- purchase_order_secondary_unit/README.rst | 40 +++++++----- purchase_order_secondary_unit/__manifest__.py | 1 + .../models/product_supplierinfo.py | 13 ++++ .../models/purchase_order.py | 13 ++++ .../static/description/index.html | 62 +++++++++---------- ...est_product_supplierinfo_secondary_unit.py | 20 ++++++ .../test_purchase_order_secondary_unit.py | 26 ++++++++ 7 files changed, 128 insertions(+), 47 deletions(-) diff --git a/purchase_order_secondary_unit/README.rst b/purchase_order_secondary_unit/README.rst index f0dc232..86ff201 100644 --- a/purchase_order_secondary_unit/README.rst +++ b/purchase_order_secondary_unit/README.rst @@ -7,7 +7,7 @@ Purchase Order Secondary Unit !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:2b71909b287e9e5c437aea172c4c165ed1bee7b3e981d1c44d99c8bfaae5740d + !! source digest: sha256:3060215436f72f80719f51c8b70f79ff92b39bde293b9739bd47588e74ad8b30 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -81,13 +81,13 @@ To use this module you need to: **Vendor Pricelist Integration** -- When adding a vendor to a product's pricelist (via *Purchase tab > - Vendors*), the secondary unit of measure is automatically defaulted - from the product variant's purchase secondary UOM, or from the - product template if not set on the variant. -- When a new vendor pricelist record is created from purchase order - confirmation, the secondary UOM from the purchase order line is - automatically stored in the vendor pricelist entry. +- When adding a vendor to a product's pricelist (via *Purchase tab > + Vendors*), the secondary unit of measure is automatically defaulted + from the product variant's purchase secondary UOM, or from the product + template if not set on the variant. +- When a new vendor pricelist record is created from purchase order + confirmation, the secondary UOM from the purchase order line is + automatically stored in the vendor pricelist entry. Known issues / Roadmap ====================== @@ -118,17 +118,17 @@ Authors Contributors ------------ -- `Tecnativa `__: +- `Tecnativa `__: - - Sergio Teruel - - Ernesto Tejeda + - Sergio Teruel + - Ernesto Tejeda -- Nikul Chaudhary -- Pimolnat Suntian -- Miguel Ángel Gómez -- `Quartile `__: +- Nikul Chaudhary +- Pimolnat Suntian +- Miguel Ángel Gómez +- `Quartile `__: - - Yoshi Tashiro + - Yoshi Tashiro Maintainers ----------- @@ -143,6 +143,14 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. +.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px + :target: https://github.com/sergio-teruel + :alt: sergio-teruel + +Current `maintainer `__: + +|maintainer-sergio-teruel| + This module is part of the `OCA/purchase-workflow `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_secondary_unit/__manifest__.py b/purchase_order_secondary_unit/__manifest__.py index 7368f53..21ae10d 100644 --- a/purchase_order_secondary_unit/__manifest__.py +++ b/purchase_order_secondary_unit/__manifest__.py @@ -8,6 +8,7 @@ "category": "Purchase", "website": "https://github.com/OCA/purchase-workflow", "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["sergio-teruel"], "license": "AGPL-3", "application": False, "installable": True, diff --git a/purchase_order_secondary_unit/models/product_supplierinfo.py b/purchase_order_secondary_unit/models/product_supplierinfo.py index e5c3ad7..fcfddb1 100644 --- a/purchase_order_secondary_unit/models/product_supplierinfo.py +++ b/purchase_order_secondary_unit/models/product_supplierinfo.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.tools import float_compare class ProductSupplierinfo(models.Model): @@ -30,8 +31,20 @@ def _compute_secondary_uom_price(self): @api.onchange("secondary_uom_price") def _inverse_secondary_uom_price(self): + precision = self.env["decimal.precision"].precision_get("Product Price") for rec in self: if rec.secondary_uom_id: + expected_secondary_price = rec.price * rec.secondary_uom_id.factor + if ( + rec.price + and float_compare( + rec.secondary_uom_price, + expected_secondary_price, + precision_digits=precision, + ) + == 0 + ): + continue rec.price = rec.secondary_uom_price / rec.secondary_uom_id.factor @api.onchange("product_tmpl_id", "product_id") diff --git a/purchase_order_secondary_unit/models/purchase_order.py b/purchase_order_secondary_unit/models/purchase_order.py index 37cece5..e80edeb 100644 --- a/purchase_order_secondary_unit/models/purchase_order.py +++ b/purchase_order_secondary_unit/models/purchase_order.py @@ -1,6 +1,7 @@ # Copyright 2018 Tecnativa - Sergio Teruel # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.tools import float_compare class PurchaseOrder(models.Model): @@ -58,8 +59,20 @@ def _compute_secondary_uom_price(self): @api.onchange("secondary_uom_price") def _inverse_secondary_uom_price(self): + precision = self.env["decimal.precision"].precision_get("Product Price") for rec in self: if rec.secondary_uom_id: + expected_secondary_price = rec.price_unit * rec.secondary_uom_id.factor + if ( + rec.price_unit + and float_compare( + rec.secondary_uom_price, + expected_secondary_price, + precision_digits=precision, + ) + == 0 + ): + continue rec.price_unit = rec.secondary_uom_price / rec.secondary_uom_id.factor @api.onchange("product_uom") diff --git a/purchase_order_secondary_unit/static/description/index.html b/purchase_order_secondary_unit/static/description/index.html index 27a815c..53e3418 100644 --- a/purchase_order_secondary_unit/static/description/index.html +++ b/purchase_order_secondary_unit/static/description/index.html @@ -1,20 +1,20 @@ + - + Purchase Order Secondary Unit