diff --git a/stock_account_valuation_report/models/product_product.py b/stock_account_valuation_report/models/product_product.py index ab80125..8d4868f 100644 --- a/stock_account_valuation_report/models/product_product.py +++ b/stock_account_valuation_report/models/product_product.py @@ -4,6 +4,7 @@ from odoo import _, api, fields, models +from odoo.tools import float_compare class ProductProduct(models.Model): @@ -48,21 +49,35 @@ class ProductProduct(models.Model): @api.model def _search_qty_discrepancy(self, operator, value): - products = self.env["product.product"].search([("type", "=", "product")]) - pp_list = [] - for pp in products: - if pp.qty_at_date != pp.account_qty_at_date: - pp_list.append(pp.id) - return [("id", "in", pp_list)] + products = self.with_context(active_test=False).search( + [ + ("type", "=", "product"), + ] + ) + dp = self.env["decimal.precision"].precision_get("Product Price") + products_with_discrepancy = products.filtered( + lambda pp: float_compare( + pp.qty_at_date, pp.account_qty_at_date, precision_digits=dp + ) + != 0 + ) + return [("id", "in", products_with_discrepancy.ids)] @api.model def _search_valuation_discrepancy(self, operator, value): - products = self.env["product.product"].search([("type", "=", "product")]) - pp_list = [] - for pp in products: - if pp.stock_value != pp.account_value: - pp_list.append(pp.id) - return [("id", "in", pp_list)] + products = self.with_context(active_test=False).search( + [ + ("type", "=", "product"), + ] + ) + dp = self.env.ref("product.decimal_discount").precision_get("Discount") + products_with_discrepancy = products.filtered( + lambda pp: float_compare( + pp.stock_value, pp.account_value, precision_digits=dp + ) + != 0 + ) + return [("id", "in", products_with_discrepancy.ids)] def _compute_inventory_value(self): self.env["account.move.line"].check_access_rights("read") diff --git a/stock_account_valuation_report/views/product_product_views.xml b/stock_account_valuation_report/views/product_product_views.xml index bd733b4..b977565 100644 --- a/stock_account_valuation_report/views/product_product_views.xml +++ b/stock_account_valuation_report/views/product_product_views.xml @@ -94,6 +94,12 @@ name="valuation_discrepancy_not_null" domain="[('valuation_discrepancy', '!=', 0.0), ('valuation', '=', 'real_time')]" /> + +