diff --git a/mrp_bom_equivalent/README.rst b/mrp_bom_equivalent/README.rst new file mode 100644 index 000000000..ab53ed30a --- /dev/null +++ b/mrp_bom_equivalent/README.rst @@ -0,0 +1,61 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +===================== +MRP BoM Equivalences +===================== + +This module allows the user to specify non-equivalent products to a part on a BOM. + +Other modules can assume that products in the same category are equivalent and can be used in a Manufacturing Order if the main part is not available. Those non-equivalent products can be excluded. + +Usage +===== + +* Go to Manufacturing > Master Data > Bill of Materials +* Create or update a BOM to check the box "Use Equivalences" +* Set the non-equivalent products among the products of the same category + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Bhavesh Odedra + +Funders +------- + +The development of this module has been financially supported by: + +* Open Source Integrators + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/mrp_bom_equivalent/__init__.py b/mrp_bom_equivalent/__init__.py new file mode 100644 index 000000000..631bd4893 --- /dev/null +++ b/mrp_bom_equivalent/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mrp_bom_equivalent/__manifest__.py b/mrp_bom_equivalent/__manifest__.py new file mode 100644 index 000000000..bc0141713 --- /dev/null +++ b/mrp_bom_equivalent/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "MRP BoM Equivalences", + "summary": "Specify non-equivalent products to a part on a BOM", + "version": "11.0.1.0.0", + "license": "AGPL-3", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "category": "MRP", + "website": "http://www.opensourceintegrators.com", + "depends": ["mrp", "product_priority"], + "data": [ + "views/mrp_view.xml", + ], + "installable": True, +} diff --git a/mrp_bom_equivalent/models/__init__.py b/mrp_bom_equivalent/models/__init__.py new file mode 100644 index 000000000..ef18d0d7e --- /dev/null +++ b/mrp_bom_equivalent/models/__init__.py @@ -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 diff --git a/mrp_bom_equivalent/models/mrp.py b/mrp_bom_equivalent/models/mrp.py new file mode 100644 index 000000000..e3e183b38 --- /dev/null +++ b/mrp_bom_equivalent/models/mrp.py @@ -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" + ) diff --git a/mrp_bom_equivalent/models/product.py b/mrp_bom_equivalent/models/product.py new file mode 100644 index 000000000..c1137a0a4 --- /dev/null +++ b/mrp_bom_equivalent/models/product.py @@ -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) diff --git a/mrp_bom_equivalent/static/description/icon.png b/mrp_bom_equivalent/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_bom_equivalent/static/description/icon.png differ diff --git a/mrp_bom_equivalent/views/mrp_view.xml b/mrp_bom_equivalent/views/mrp_view.xml new file mode 100644 index 000000000..7f07c7eb7 --- /dev/null +++ b/mrp_bom_equivalent/views/mrp_view.xml @@ -0,0 +1,17 @@ + + + + + mrp.bom.form + mrp.bom + + + + + + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 000000000..5d557e554 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1,3 @@ +# List the OCA project dependencies, one per line +# Add a repository url and branch if you need a forked version +product-attribute