Merge pull request #63 from odoomrp/8.0-fix-mrp_bom_reference_selection

[FIX] mrp_bom_reference_selection: Fixed onchange error closes #62
This commit is contained in:
Pedro M. Baeza
2015-12-10 16:27:06 +01:00
10 changed files with 106 additions and 252 deletions

View File

@@ -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 <https://github.com/OCA/manufacture/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 <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_reference%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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.

View File

@@ -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',

View File

@@ -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 ""

View File

@@ -1,26 +1,8 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# 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")

View File

@@ -1,32 +1,15 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# 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",
)

View File

@@ -1,34 +1,15 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# 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)

View File

@@ -1,29 +1,8 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# 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

View File

@@ -1,29 +1,12 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# 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')

View File

@@ -1,24 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp.tests import common

View File

@@ -19,8 +19,7 @@
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='bom_line_ids']//field[@name='product_id']" position="replace">
<field name="product_id" on_change="onchange_product_id(product_id)"/>
<xpath expr="//field[@name='bom_line_ids']//field[@name='product_id']" position="after">
<field name="product_tmpl_id" invisible="1"/>
<field name="reference_id"
domain="[