[IMP] product_usability: forward-port seller_id now a computed field with search method
stock_usability: Add seller_id on orderpoints.
This commit is contained in:
@@ -9,12 +9,12 @@ from odoo import api, models, fields
|
|||||||
class ProductTemplate(models.Model):
|
class ProductTemplate(models.Model):
|
||||||
_inherit = 'product.template'
|
_inherit = 'product.template'
|
||||||
|
|
||||||
# restore v8 native field
|
# seller_id cannot be stored, because its value may be different
|
||||||
# https://github.com/odoo/odoo/blob/8.0/addons/product/product.py#L592
|
# from one company to another
|
||||||
# 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(
|
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')
|
string='Main Supplier')
|
||||||
|
|
||||||
# in v14, I noticed that the tracking of the fields of product.template
|
# 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)
|
company_id = fields.Many2one(tracking=110)
|
||||||
barcode_type = fields.Char(compute='_compute_template_barcode_type')
|
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
|
# precompute=True doesn't work on product.template
|
||||||
# (works fine on product.product), probably because we don't depend
|
# (works fine on product.product), probably because we don't depend
|
||||||
# on 'barcode'
|
# on 'barcode'
|
||||||
|
|||||||
@@ -32,5 +32,15 @@
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="product_product_tree_view" model="ir.ui.view">
|
||||||
|
<field name="name">usability.product.product.tree</field>
|
||||||
|
<field name="model">product.product</field>
|
||||||
|
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="company_id" position="before">
|
||||||
|
<field name="seller_id" optional="hide"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<field name="inherit_id" ref="product.product_template_search_view" />
|
<field name="inherit_id" ref="product.product_template_search_view" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="categ_id" position="after">
|
<field name="categ_id" position="after">
|
||||||
<field name="seller_ids" string="Supplier" filter_domain="[('seller_ids.partner_id', 'ilike', self)]"/>
|
<field name="seller_id" domain="[('parent_id', '=', False)]"/>
|
||||||
</field>
|
</field>
|
||||||
<filter name="type" position="attributes">
|
<filter name="type" position="attributes">
|
||||||
<attribute name="context">{'group_by': 'detailed_type'}</attribute>
|
<attribute name="context">{'group_by': 'detailed_type'}</attribute>
|
||||||
|
|||||||
@@ -15,6 +15,23 @@ class StockWarehouseOrderpoint(models.Model):
|
|||||||
# but all the Odoo deployments I've seen so far need 'manual' by default
|
# but all the Odoo deployments I've seen so far need 'manual' by default
|
||||||
trigger = fields.Selection(default='manual')
|
trigger = fields.Selection(default='manual')
|
||||||
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
|
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(
|
def _procure_orderpoint_confirm(
|
||||||
self, use_new_cursor=False, company_id=None, raise_user_error=True):
|
self, use_new_cursor=False, company_id=None, raise_user_error=True):
|
||||||
|
|||||||
@@ -28,8 +28,20 @@
|
|||||||
<field name="product_id" position="after">
|
<field name="product_id" position="after">
|
||||||
<field name="product_barcode" optional="hide"/>
|
<field name="product_barcode" optional="hide"/>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="route_id" position="after">
|
||||||
|
<field name="seller_id" optional="show"/>
|
||||||
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="stock_reorder_report_search" model="ir.ui.view">
|
||||||
|
<field name="model">stock.warehouse.orderpoint</field>
|
||||||
|
<field name="inherit_id" ref="stock.stock_reorder_report_search"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="product_category_id" position="after">
|
||||||
|
<field name="seller_id" domain="[('parent_id', '=', False)]"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user