mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[ADD] mrp_bom_equivalent
This commit is contained in:
committed by
Maxime Chambreuil
parent
c55d3fe2cd
commit
1f3c4d4f99
5
mrp_bom_equivalent/models/__init__.py
Normal file
5
mrp_bom_equivalent/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Copyright (C) 2018 - TODAY, Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import mrp
|
||||
from . import product
|
||||
19
mrp_bom_equivalent/models/mrp.py
Normal file
19
mrp_bom_equivalent/models/mrp.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright (C) 2018 - TODAY, Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MRPBoMLine(models.Model):
|
||||
_inherit = 'mrp.bom.line'
|
||||
|
||||
use_equivalences = fields.Boolean(
|
||||
string='Use equivalences'
|
||||
)
|
||||
nonequivalent_product_ids = fields.Many2many(
|
||||
"product.product",
|
||||
"mrp_bom_line_product_rel",
|
||||
"bom_line_id",
|
||||
"product_id",
|
||||
string="Non-Equivalent Products"
|
||||
)
|
||||
40
mrp_bom_equivalent/models/product.py
Normal file
40
mrp_bom_equivalent/models/product.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2018 - TODAY, Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
@api.model
|
||||
def name_search(self, name, args=None, operator='ilike', limit=100):
|
||||
if 'nonequivalent_product_id' in self._context:
|
||||
category_id = self.browse(
|
||||
self._context.get('nonequivalent_product_id')).categ_id
|
||||
recs = self.search(
|
||||
[('categ_id', '=', category_id.id),
|
||||
('id', '!=', self._context.get('nonequivalent_product_id')),
|
||||
('name', operator, name)] + args, limit=limit)
|
||||
if not recs:
|
||||
recs = self.browse()
|
||||
return recs.name_get()
|
||||
return super(ProductProduct, self).name_search(name, args=args,
|
||||
operator=operator,
|
||||
limit=limit)
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None,
|
||||
order=None):
|
||||
if 'nonequivalent_product_id' in self._context:
|
||||
category_id = self.browse(
|
||||
self._context.get('nonequivalent_product_id')).categ_id
|
||||
domain +=\
|
||||
[('categ_id', '=', category_id.id),
|
||||
('id', '!=', self._context.get('nonequivalent_product_id'))]
|
||||
order = order or self.priority
|
||||
return super(ProductProduct, self).search_read(domain=domain,
|
||||
fields=fields,
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
order=order)
|
||||
Reference in New Issue
Block a user