diff --git a/mrp_bom_reference_selection/README.rst b/mrp_bom_reference_selection/README.rst index 2c106cbab..a464a1973 100644 --- a/mrp_bom_reference_selection/README.rst +++ b/mrp_bom_reference_selection/README.rst @@ -1,30 +1,46 @@ +.. 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 Bill of Material Reference Selection ======================================== -This module allows to select the component in a bom when you have several bom for one product. +This module allows to select the component in a BoM when you have several BoM for one product. This is used to manage versions of a product. Produced lot contains a reference to the bill of material used to compute the lot. Installation ============ -To install this module, you just need to select the module and insure yourself dependancies are available. +To install this module, you just need to select the module and ensure yourself dependencies are available. Configuration ============= No particular configuration to use this module. - Usage ===== To use this module, you need to : -- create a product -- create a bom from this product (ie : AA), give a reference to this bom (ie : A1) -- create an other bom for the same product, give a reference to this bom (ie : A2) -- now, you can create an other bom for an other product (ie : BB) with products AA as component. You will have to choose the bom you want between A1 or A2 +- create a product +- create a BoM from this product (ie : AA), give a reference to this BoM (ie : A1) +- create an other BoM for the same product, give a reference to this BoM (ie : A2) +- now, you can create an other BoM for an other product (ie : BB) with products AA as component. You will have to choose the BoM you want between A1 or A2 + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/129/8.0 + + +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 smashing it by providing a detailed and welcomed `feedback `_. Credits ======= @@ -46,10 +62,14 @@ Icon Maintainer ---------- -Odoo Community Association +.. 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. +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 http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/mrp_bom_reference_selection/__openerp__.py b/mrp_bom_reference_selection/__openerp__.py index 642b997f5..61949464e 100644 --- a/mrp_bom_reference_selection/__openerp__.py +++ b/mrp_bom_reference_selection/__openerp__.py @@ -23,7 +23,8 @@ { 'name': 'Bill of Material Selection Reference', 'version': '8.0.1.1.0', - 'author': 'Savoir-faire Linux', + 'author': 'Savoir-faire Linux, ' + 'Odoo Community Association (OCA)', 'license': 'AGPL-3', 'category': 'Others', 'summary': 'Bill of Material Selection Reference', diff --git a/mrp_bom_reference_selection/i18n/mrp_bom_reference_selection.pot b/mrp_bom_reference_selection/i18n/mrp_bom_reference_selection.pot deleted file mode 100644 index ff58455bf..000000000 --- a/mrp_bom_reference_selection/i18n/mrp_bom_reference_selection.pot +++ /dev/null @@ -1,68 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * mrp_bom_reference_selection -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-02-25 13:19+0000\n" -"PO-Revision-Date: 2015-02-25 13:19+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: mrp_bom_reference_selection -#: model:ir.model,name:mrp_bom_reference_selection.model_mrp_bom -#: field:mrp.bom.reference,bom_id:0 -msgid "Bill of Material" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom,reference_id:0 -msgid "BoM Reference" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.reference,create_uid:0 -msgid "Created by" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.reference,create_date:0 -msgid "Created on" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.reference,id:0 -msgid "ID" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.reference,write_uid:0 -msgid "Last Updated by" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.reference,write_date:0 -msgid "Last Updated on" -msgstr "" - -#. module: mrp_bom_reference_selection -#: model:ir.model,name:mrp_bom_reference_selection.model_mrp_bom_reference -msgid "MRP Bill of Material Reference" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.line,product_tmpl_id:0 -msgid "Product Template" -msgstr "" - -#. module: mrp_bom_reference_selection -#: field:mrp.bom.reference,name:0 -msgid "Reference" -msgstr "" - diff --git a/mrp_bom_reference_selection/models/mrp_bom.py b/mrp_bom_reference_selection/models/mrp_bom.py index 550fa197a..a675df9f1 100644 --- a/mrp_bom_reference_selection/models/mrp_bom.py +++ b/mrp_bom_reference_selection/models/mrp_bom.py @@ -1,26 +1,8 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# (c) 2015 Savoir-faire Linux - +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from openerp import models, fields, api +from openerp import api, fields, models class MrpBillOfMaterial(models.Model): @@ -34,4 +16,5 @@ class MrpBillOfMaterial(models.Model): return res reference_id = fields.One2many( - 'mrp.bom.reference', 'bom_id', string="BoM Reference") + comodel_name='mrp.bom.reference', inverse_name='bom_id', + string="BoM Reference") diff --git a/mrp_bom_reference_selection/models/mrp_bom_line.py b/mrp_bom_reference_selection/models/mrp_bom_line.py index 5f2c73a35..88510f89e 100644 --- a/mrp_bom_reference_selection/models/mrp_bom_line.py +++ b/mrp_bom_reference_selection/models/mrp_bom_line.py @@ -1,32 +1,15 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# (c) 2015 Savoir-faire Linux - +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from openerp import models, fields, api +from openerp import api, exceptions, fields, models, _ class MrpBillOfMaterialLine(models.Model): _inherit = 'mrp.bom.line' - reference_id = fields.Many2one('mrp.bom.reference', 'Ref') + reference_id = fields.Many2one( + comodel_name='mrp.bom.reference', string='Ref') product_tmpl_id = fields.Many2one( 'product.template', 'Product Template', related='product_id.product_tmpl_id', store=True) @@ -34,38 +17,53 @@ class MrpBillOfMaterialLine(models.Model): product_id = fields.Many2one( 'product.product', required=True, string='Product') + @api.constrains('reference_id') + def _check_reference_id(self): + if (self.reference_id and + (self.reference_id.bom_id.product_tmpl_id != + self.product_id.product_tmpl_id)): + raise exceptions.Warning( + _('Product %s from %s reference BoM must be equal to product' + ' %s in BoM line.' % + (self.reference_id.bom_id.product_tmpl_id.name, + self.reference_id.name, + self.product_id.product_tmpl_id.name))) + @api.multi - def onchange_product_id(self, product_id): - product = self.env['product.product'].browse(product_id) - - res = {'value': {}} - - if not product: - res['value']['reference_id'] = False - else: + def onchange_product_id(self, product_id, product_qty=0): + res = super(MrpBillOfMaterialLine, self).onchange_product_id( + product_id, product_qty=product_qty) + if 'value' not in res: + res['value'] = {} + if 'domain' not in res: + res['domain'] = {} + if product_id: + product = self.env['product.product'].browse(product_id) refs = self.env['mrp.bom.reference'].search( [('bom_id.product_tmpl_id', '=', product.product_tmpl_id.id)]) - res['value']['reference_id'] = refs and refs[0] - + res['value']['reference_id'] = refs[:1] + res['domain']['reference_id'] = [('id', 'in', refs.ids)] + else: + res['value']['reference_id'] = False + res['domain']['reference_id'] = False return res - @api.one @api.depends('product_id') - def _get_child_bom_lines(self): - if self.reference_id: - self.child_line_ids = self.reference_id.bom_id.bom_line_ids.ids - else: - bom_obj = self.env['mrp.bom'] - bom_id = bom_obj._bom_find( - product_tmpl_id=self.product_id.product_tmpl_id.id, - product_id=self.product_id.id) - self.child_line_ids = bom_id and [ - (6, 0, child_id) for child_id in - bom_obj.browse(bom_id).bom_line_ids.ids - ] or False + def _compute_child_bom_lines(self): + for record in self: + if record.reference_id: + record.child_line_ids = record.reference_id.bom_id.bom_line_ids + else: + bom_obj = self.env['mrp.bom'] + bom_id = bom_obj._bom_find( + product_tmpl_id=record.product_id.product_tmpl_id.id, + product_id=record.product_id.id) + record.child_line_ids = bom_id and [ + (6, 0, child_id) for child_id in + bom_obj.browse(bom_id).bom_line_ids.ids + ] or False child_line_ids = fields.One2many( - relation='mrp.bom.line', - compute='_get_child_bom_lines', - string="BOM lines of the referred bom", + relation='mrp.bom.line', compute='_compute_child_bom_lines', + string="BoM lines of the referred BoM", ) diff --git a/mrp_bom_reference_selection/models/mrp_bom_reference.py b/mrp_bom_reference_selection/models/mrp_bom_reference.py index 8059c25f9..be9b9df59 100644 --- a/mrp_bom_reference_selection/models/mrp_bom_reference.py +++ b/mrp_bom_reference_selection/models/mrp_bom_reference.py @@ -1,34 +1,15 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# (c) 2015 Savoir-faire Linux - +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from openerp import models, fields +from openerp import fields, models class MrpBillOfMaterialReference(models.Model): - _name = 'mrp.bom.reference' _description = 'MRP Bill of Material Reference' bom_id = fields.Many2one( - 'mrp.bom', required=True, ondelete='cascade', + comodel_name='mrp.bom', required=True, ondelete='cascade', string='Bill of Material') name = fields.Char(related='bom_id.code', store=True) diff --git a/mrp_bom_reference_selection/models/mrp_production.py b/mrp_bom_reference_selection/models/mrp_production.py index 931a7cd73..39e4469ad 100644 --- a/mrp_bom_reference_selection/models/mrp_production.py +++ b/mrp_bom_reference_selection/models/mrp_production.py @@ -1,29 +1,8 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# (c) 2015 Savoir-faire Linux - +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -import logging -from openerp import models, api - -_logger = logging.getLogger(__name__) +from openerp import api, models class MrpProduction(models.Model): @@ -37,11 +16,7 @@ class MrpProduction(models.Model): """ res = super(MrpProduction, self).action_produce( production_id, production_qty, production_mode, wiz) - production = self.browse(production_id) - - for move in production.move_created_ids2: - prod_lots = move.lot_ids - prod_lots.write({'bom_id': production.bom_id.id}) - + prod_lots = production.mapped('move_created_ids2.lot_ids') + prod_lots.write({'bom_id': production.bom_id.id}) return res diff --git a/mrp_bom_reference_selection/models/stock_production_lot.py b/mrp_bom_reference_selection/models/stock_production_lot.py index a1c38988e..e3771314a 100644 --- a/mrp_bom_reference_selection/models/stock_production_lot.py +++ b/mrp_bom_reference_selection/models/stock_production_lot.py @@ -1,29 +1,12 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# (c) 2015 Savoir-faire Linux - +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from openerp import models, fields +from openerp import fields, models class StockProductionLot(models.Model): _inherit = 'stock.production.lot' - bom_id = fields.Many2one('mrp.bom', 'Bill of Material') + bom_id = fields.Many2one( + comodel_name='mrp.bom', string='Bill of Material') diff --git a/mrp_bom_reference_selection/tests/test_mrp_bom.py b/mrp_bom_reference_selection/tests/test_mrp_bom.py index 1cee04866..bc73a50f2 100644 --- a/mrp_bom_reference_selection/tests/test_mrp_bom.py +++ b/mrp_bom_reference_selection/tests/test_mrp_bom.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# (c) 2015 Savoir-faire Linux - +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html from openerp.tests import common diff --git a/mrp_bom_reference_selection/views/mrp_bom_view.xml b/mrp_bom_reference_selection/views/mrp_bom_view.xml index 25e408cef..df085c006 100644 --- a/mrp_bom_reference_selection/views/mrp_bom_view.xml +++ b/mrp_bom_reference_selection/views/mrp_bom_view.xml @@ -19,8 +19,7 @@ mrp.bom - - +