summaryrefslogtreecommitdiff
path: root/addons/product
diff options
context:
space:
mode:
authorRémy Voet (ryv) <ryv@odoo.com>2021-02-02 11:15:46 +0000
committerWilliam Henrotin <whe@odoo.com>2021-05-06 13:38:12 +0000
commitf91ba797469f4a132b145b907c056a1acd6805de (patch)
treef54be25e23e78292116301dcb77707a78a774200 /addons/product
parentdb062738c690dc5e553de3a9c600ef34878fb119 (diff)
[FIX] product: `_prepare_seller` reuse the orm cache
Make `seller_ids` `depends_context` of company to avoid shared cache with different company. The purpose is to avoid making a SQL search for each `_prepare_seller` and use the ORM cache (which depends of the company in env). Also change the `_order` of `product.supplierinfo` to be determinist and consistent with the `_prepare_seller`. task-2439019
Diffstat (limited to 'addons/product')
-rw-r--r--addons/product/models/product.py6
-rw-r--r--addons/product/models/product_template.py2
2 files changed, 3 insertions, 5 deletions
diff --git a/addons/product/models/product.py b/addons/product/models/product.py
index fe745db7685..b983695960d 100644
--- a/addons/product/models/product.py
+++ b/addons/product/models/product.py
@@ -591,9 +591,7 @@ class ProductProduct(models.Model):
'target': 'new'}
def _prepare_sellers(self, params=False):
- # This search is made to avoid retrieving seller_ids from the cache.
- return self.env['product.supplierinfo'].search([('product_tmpl_id', '=', self.product_tmpl_id.id),
- ('name.active', '=', True)]).sorted(lambda s: (s.sequence, -s.min_qty, s.price, s.id))
+ return self.seller_ids.filtered(lambda s: s.name.active).sorted(lambda s: (s.sequence, -s.min_qty, s.price, s.id))
def _select_seller(self, partner_id=False, quantity=0.0, date=None, uom_id=False, params=False):
self.ensure_one()
@@ -727,7 +725,7 @@ class ProductPackaging(models.Model):
class SupplierInfo(models.Model):
_name = "product.supplierinfo"
_description = "Supplier Pricelist"
- _order = 'sequence, min_qty desc, price'
+ _order = 'sequence, min_qty DESC, price, id'
name = fields.Many2one(
'res.partner', 'Vendor',
diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py
index e5c4588c5d6..ed51decebf4 100644
--- a/addons/product/models/product_template.py
+++ b/addons/product/models/product_template.py
@@ -110,7 +110,7 @@ class ProductTemplate(models.Model):
packaging_ids = fields.One2many(
'product.packaging', string="Product Packages", compute="_compute_packaging_ids", inverse="_set_packaging_ids",
help="Gives the different ways to package the same product.")
- seller_ids = fields.One2many('product.supplierinfo', 'product_tmpl_id', 'Vendors', help="Define vendor pricelists.")
+ seller_ids = fields.One2many('product.supplierinfo', 'product_tmpl_id', 'Vendors', depends_context=('company',), help="Define vendor pricelists.")
variant_seller_ids = fields.One2many('product.supplierinfo', 'product_tmpl_id')
active = fields.Boolean('Active', default=True, help="If unchecked, it will allow you to hide the product without removing it.")