From 15ea753a0fdd04b5966f0bd5e62b969c22664555 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 27 Feb 2019 16:08:21 +0000 Subject: [PATCH] [FIX] stock: show product qty on searched location The location_id and warehouse_id fields on product.template are just dummy field intended to add something in the context that will be used to compute the data being rendered (eg. for location, the quantity displayed is the quantity of the product in the searched location). But the feature was broken at a point, and has been solved in 11.0 with 7c7b0992734. This solution was not implemented in 10.0 up to saas-15 since this is not acceptable for a stable version. This changeset is only for 10.0 up to saas-15 to implement the fix differently. opw-1945417 closes #31475 --- addons/stock/models/product.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 09408f6c694..804b42d3bf6 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -4,6 +4,7 @@ from odoo import api, fields, models, _ from odoo.addons import decimal_precision as dp from odoo.exceptions import UserError +from odoo.osv import expression from odoo.tools.float_utils import float_round from datetime import datetime import operator as py_operator @@ -370,6 +371,15 @@ class Product(models.Model): def action_view_routes(self): return self.mapped('product_tmpl_id').action_view_routes() + @api.model + def search(self, domain=None, *args, **kwargs): + # ONLY FOR 10.0 UP TO SAAS-15 + # ignore dummy fields used for search context² + for index in range(len(domain or [])): + if domain[index][0] in ('location_id', 'warehouse_id'): + domain[index] = expression.TRUE_LEAF + return super(Product, self).search(domain, *args, **kwargs) + @api.multi def write(self, values): res = super(Product, self).write(values) @@ -505,6 +515,15 @@ class ProductTemplate(models.Model): def onchange_tracking(self): return self.mapped('product_variant_ids').onchange_tracking() + @api.model + def search(self, domain=None, *args, **kwargs): + # ONLY FOR 10.0 UP TO SAAS-15 + # ignore dummy fields used for search context + for index in range(len(domain or [])): + if domain[index][0] in ('location_id', 'warehouse_id'): + domain[index] = expression.TRUE_LEAF + return super(ProductTemplate, self).search(domain, *args, **kwargs) + @api.multi def write(self, vals): if 'uom_id' in vals: