From 8cc20fa84f4764d4070e0cce1efaf813a169f00e Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 20 May 2025 10:09:43 +0200 Subject: [PATCH] [IMP] product_usability: forward-port seller_id now a computed field with search method stock_usability: Add seller_id on orderpoints. --- product_usability/models/product_template.py | 22 ++++++++++++++----- product_usability/views/product_product.xml | 10 +++++++++ .../views/product_template_view.xml | 2 +- .../models/stock_warehouse_orderpoint.py | 17 ++++++++++++++ .../views/stock_warehouse_orderpoint.xml | 12 ++++++++++ 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/product_usability/models/product_template.py b/product_usability/models/product_template.py index e68ad56..3d22903 100644 --- a/product_usability/models/product_template.py +++ b/product_usability/models/product_template.py @@ -9,12 +9,12 @@ from odoo import api, models, fields class ProductTemplate(models.Model): _inherit = 'product.template' - # restore v8 native field - # https://github.com/odoo/odoo/blob/8.0/addons/product/product.py#L592 - # 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 cannot be stored, because its value may be different + # from one company to another seller_id = fields.Many2one( - 'res.partner', related='seller_ids.partner_id', store=True, + '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 @@ -35,6 +35,18 @@ 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 template in self: + template.seller_id = fields.first(template.seller_ids).partner_id + # precompute=True doesn't work on product.template # (works fine on product.product), probably because we don't depend # on 'barcode' diff --git a/product_usability/views/product_product.xml b/product_usability/views/product_product.xml index ce9bcd3..1bb36db 100644 --- a/product_usability/views/product_product.xml +++ b/product_usability/views/product_product.xml @@ -32,5 +32,15 @@ + + usability.product.product.tree + product.product + + + + + + + diff --git a/product_usability/views/product_template_view.xml b/product_usability/views/product_template_view.xml index 140722d..8b84aed 100644 --- a/product_usability/views/product_template_view.xml +++ b/product_usability/views/product_template_view.xml @@ -14,7 +14,7 @@ - + {'group_by': 'detailed_type'} diff --git a/stock_usability/models/stock_warehouse_orderpoint.py b/stock_usability/models/stock_warehouse_orderpoint.py index 83f734c..bd59346 100644 --- a/stock_usability/models/stock_warehouse_orderpoint.py +++ b/stock_usability/models/stock_warehouse_orderpoint.py @@ -15,6 +15,23 @@ class StockWarehouseOrderpoint(models.Model): # but all the Odoo deployments I've seen so far need 'manual' by default trigger = fields.Selection(default='manual') product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode") + seller_id = fields.Many2one( + "res.partner", + compute="_compute_seller_id", + search="_search_seller_id", + string="Main Supplier") + + 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([("product_id.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 orderpoint in self: + orderpoint.seller_id = fields.first(orderpoint.product_id.seller_ids).partner_id def _procure_orderpoint_confirm( self, use_new_cursor=False, company_id=None, raise_user_error=True): diff --git a/stock_usability/views/stock_warehouse_orderpoint.xml b/stock_usability/views/stock_warehouse_orderpoint.xml index 3e99b9b..b0bed17 100644 --- a/stock_usability/views/stock_warehouse_orderpoint.xml +++ b/stock_usability/views/stock_warehouse_orderpoint.xml @@ -28,8 +28,20 @@ + + + + + stock.warehouse.orderpoint + + + + + + +