From 0fa2024dab401c1232b0ae2abc87083c75d94582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Fri, 31 May 2024 10:00:33 +0200 Subject: [PATCH 1/2] product_usability: seller_id can not be store as muti-company will be broken do not store the field as shared product can have different supplier depending on the company logged Use compute as related will always pick the first one whatever the company logged --- product_usability/models/product_template.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/product_usability/models/product_template.py b/product_usability/models/product_template.py index ca8238e..f249289 100644 --- a/product_usability/models/product_template.py +++ b/product_usability/models/product_template.py @@ -14,7 +14,8 @@ class ProductTemplate(models.Model): # in v10, that field was defined in procurement_suggest, but we will # probably not port procurement_suggest because it is native in v14 seller_id = fields.Many2one( - 'res.partner', related='seller_ids.name', store=True, + 'res.partner', + compute="_compute_seller_id", string='Main Supplier') # in v14, I noticed that the tracking of the fields of product.template @@ -33,6 +34,10 @@ class ProductTemplate(models.Model): company_id = fields.Many2one(tracking=110) barcode_type = fields.Char(compute='_compute_template_barcode_type') + def _compute_seller_id(self): + for record in self: + record.seller_id = fields.first(record.seller_ids).name + @api.depends('product_variant_ids.barcode') def _compute_template_barcode_type(self): ppo = self.env['product.product'] From a1f8ab32dd35ae51fb2f0a64e0926df278a656ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 12 Dec 2024 01:38:25 +0100 Subject: [PATCH 2/2] product_usability: make the field seller_id searcheable --- product_usability/models/product_template.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/product_usability/models/product_template.py b/product_usability/models/product_template.py index f249289..11485b9 100644 --- a/product_usability/models/product_template.py +++ b/product_usability/models/product_template.py @@ -16,6 +16,7 @@ class ProductTemplate(models.Model): seller_id = fields.Many2one( 'res.partner', compute="_compute_seller_id", + search="_search_seller_id", string='Main Supplier') # in v14, I noticed that the tracking of the fields of product.template @@ -34,6 +35,15 @@ class ProductTemplate(models.Model): company_id = fields.Many2one(tracking=110) barcode_type = fields.Char(compute='_compute_template_barcode_type') + + def _search_seller_id(self, operator, value): + # searching on the first line of a o2m is not that easy + # So we search all potential matching products + # Then we filter on the seller_id + records = self.search([("seller_ids.partner_id", operator, value)]) + records = records.filtered_domain([("seller_id", operator, value)]) + return [("id", "in", records.ids)] + def _compute_seller_id(self): for record in self: record.seller_id = fields.first(record.seller_ids).name