diff --git a/.travis.yml b/.travis.yml index fe17be62f..aca905878 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ addons: apt: packages: - expect-dev # provides unbuffer utility - - python-lxml # because pip installation is slow + - python-lxml # because pip installation is slow env: global: @@ -17,7 +17,7 @@ env: - TRANSIFEX_USER='transbot@odoo-community.org' - secure: cnskjzYSLkdeEoUDIhwkwqWsNKIj36JyoA/H7ByNLBphAm9Xrs/ZE8Y5AHxsXp8zQjIGnzw4fpEEO8oakmaueFTaAKlzWS2KH8NWxTjNHkIv/+TFwYsayWNG6O39021wSMQnTRDVERNlBdTwjCTBne81a50NqCeUIrtgcwycwzU= -matrix: + matrix: - LINT_CHECK="1" - TRANSIFEX="1" - TESTS="1" ODOO_REPO="odoo/odoo" diff --git a/mrp_bom_reference_selection/views/mrp_bom_view.xml b/mrp_bom_reference_selection/views/mrp_bom_view.xml index 04ed63a7e..25e408cef 100644 --- a/mrp_bom_reference_selection/views/mrp_bom_view.xml +++ b/mrp_bom_reference_selection/views/mrp_bom_view.xml @@ -2,7 +2,7 @@ - + mrp.bom.tree mrp.bom diff --git a/mrp_bom_version/README.rst b/mrp_bom_version/README.rst new file mode 100644 index 000000000..4fd4702b4 --- /dev/null +++ b/mrp_bom_version/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +================= +MRP - BoM Version +================= + +This module provides a state in the BoM whether to allow their use in +manufacturing. + + +Usage +===== + +The following states are defined: + +* **Draft**: + The form will be available for data entry, and may move to "active" state. +* **Active**: + You can modify all of the form fields except for the fields: routing, BoM + lines, and the new field Active, for false default when you create a new BoM. + The "active" state may be passed back to state "draft", if we mark the new + field "Allow re-edit the BoM list", this new field is defined in + *Configuration > Configuration > Manufacturing*. You can configure there also + if those BoM will continue with active check marked as True or not. + The active state may move to state "Historical". +* **Historical**: + This is the last state of the LdM, you can not change any field on the form. + +When the MRP BoM list is put to active, a record of who has activated, and when +will include in chatter/log. It also adds a constraint for the sequence field +to be unique. + +* **New version** : + By clicking the button version, current BOM is moved to historical state, + and a new BOM is creating based on this but with version number +1 and + changing state to draft + + +.. 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 +`here `_. + + +Credits +======= + +Contributors +------------ +* Pedro M. Baeza +* Ana Juaristi +* Alfredo de la Fuente +* Oihane Crucelaegui + diff --git a/mrp_bom_version/__init__.py b/mrp_bom_version/__init__.py new file mode 100644 index 000000000..f2dc1b552 --- /dev/null +++ b/mrp_bom_version/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import models + + +def set_active_bom_active_state(cr, registry): + """Set those active BoMs to state 'active'""" + cr.execute("""UPDATE mrp_bom + SET state = 'active' + WHERE active = True""") diff --git a/mrp_bom_version/__openerp__.py b/mrp_bom_version/__openerp__.py new file mode 100644 index 000000000..00f1fd1dd --- /dev/null +++ b/mrp_bom_version/__openerp__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alfredo de la Fuente - AvanzOSC +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + "name": "MRP - BoM version", + "summary": "BoM versioning", + "version": "8.0.1.0.0", + "license": "AGPL-3", + "author": "OdooMRP team," + "AvanzOSC," + "Serv. Tecnol. Avanzados - Pedro M. Baeza, " + "Odoo Community Association (OCA)", + "website": "http://www.odoomrp.com", + "contributors": [ + "Pedro M. Baeza ", + "Ana Juaristi ", + "Alfredo de la Fuente ", + "Oihane Crucelaegui ", + ], + "category": "Manufacturing", + "depends": [ + "mrp", + ], + "data": [ + "data/mrp_bom_data.xml", + "security/mrp_bom_version_security.xml", + "views/res_config_view.xml", + "views/mrp_bom_view.xml", + ], + "installable": True, + "post_init_hook": "set_active_bom_active_state", +} diff --git a/mrp_bom_version/data/mrp_bom_data.xml b/mrp_bom_version/data/mrp_bom_data.xml new file mode 100644 index 000000000..2fe6424ca --- /dev/null +++ b/mrp_bom_version/data/mrp_bom_data.xml @@ -0,0 +1,11 @@ + + + + + MRP BoM Active + mrp.bom + + MRP BoM Active + + + diff --git a/mrp_bom_version/i18n/es.po b/mrp_bom_version/i18n/es.po new file mode 100644 index 000000000..31933bf3d --- /dev/null +++ b/mrp_bom_version/i18n/es.po @@ -0,0 +1,125 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_version +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-22 08:58+0000\n" +"PO-Revision-Date: 2015-05-22 11:02+0100\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.5.4\n" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "Activate" +msgstr "Activar" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +#: selection:mrp.bom,state:0 +msgid "Active" +msgstr "Activa" + +#. module: mrp_bom_version +#: field:mrp.config.settings,group_mrp_bom_state:0 +msgid "Allow to re-edit BoMs" +msgstr "Permitir re-editar las listas de materiales." + +#. module: mrp_bom_version +#: model:ir.model,name:mrp_bom_version.model_mrp_bom +msgid "Bill of Material" +msgstr "Lista de material" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +#: selection:mrp.bom,state:0 +msgid "Draft" +msgstr "Borrador" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +#: selection:mrp.bom,state:0 +msgid "Historical" +msgstr "Histórica" + +#. module: mrp_bom_version +#: field:mrp.bom,historical_date:0 +msgid "Historical Date" +msgstr "Fecha historificación" + +#. module: mrp_bom_version +#: model:mail.message.subtype,description:mrp_bom_version.mt_active +#: model:mail.message.subtype,name:mrp_bom_version.mt_active +msgid "MRP BoM Active" +msgstr "Estado LdM" + +#. module: mrp_bom_version +#: model:res.groups,name:mrp_bom_version.group_mrp_bom_version +msgid "MRP BoM version" +msgstr "Version LdM" + +#. module: mrp_bom_version +#: model:ir.model,name:mrp_bom_version.model_mrp_production +msgid "Manufacturing Order" +msgstr "Órden de producción" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "New version" +msgstr "Nueva versión" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +msgid "Product" +msgstr "Producto" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +msgid "State" +msgstr "Estado" + +#. module: mrp_bom_version +#: field:mrp.bom,state:0 +msgid "Status" +msgstr "Estado" + +#. module: mrp_bom_version +#: help:mrp.config.settings,group_mrp_bom_state:0 +msgid "The active state may be passed back to state draft" +msgstr "El estado activo puede ser devuelto al estado de borrador" + +#. module: mrp_bom_version +#: field:mrp.bom,version:0 +msgid "Version" +msgstr "Versión" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "You are going to create a new version of this BoM. Are you sure?" +msgstr "" +" Está a punto de crear una nueva versión de esta LdM. ¿Desea continuar?" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "" +"You are going to historize an BoM. Doing, not be able to unlock it unless " +"you make a copy. Are you sure you want to proceed?" +msgstr "" +"Va a historificar una LdM. Si lo hace, no podrá volver a activarla a no ser " +"que saque una copia ¿Está seguro de que desea proceder?" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "" +"You will activate the BoM. If you haven't set a route yet, then you won't be " +"able to do it after this. Are you sure you want to proceed?" +msgstr "" +"Va a activar la LdM. Si no ha puesto ruta, no podrá ya ponerla. ¿Está seguro " +"de que desea proceder?" diff --git a/mrp_bom_version/i18n/mrp_bom_version.pot b/mrp_bom_version/i18n/mrp_bom_version.pot new file mode 100644 index 000000000..b37901133 --- /dev/null +++ b/mrp_bom_version/i18n/mrp_bom_version.pot @@ -0,0 +1,116 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_version +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-22 08:58+0000\n" +"PO-Revision-Date: 2015-05-22 08:58+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_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "Activate" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +#: selection:mrp.bom,state:0 +msgid "Active" +msgstr "" + +#. module: mrp_bom_version +#: field:mrp.config.settings,group_mrp_bom_state:0 +msgid "Allow to re-edit BoMs" +msgstr "" + +#. module: mrp_bom_version +#: model:ir.model,name:mrp_bom_version.model_mrp_bom +msgid "Bill of Material" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +#: selection:mrp.bom,state:0 +msgid "Draft" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +#: selection:mrp.bom,state:0 +msgid "Historical" +msgstr "" + +#. module: mrp_bom_version +#: field:mrp.bom,historical_date:0 +msgid "Historical Date" +msgstr "" + +#. module: mrp_bom_version +#: model:mail.message.subtype,description:mrp_bom_version.mt_active +#: model:mail.message.subtype,name:mrp_bom_version.mt_active +msgid "MRP BoM Active" +msgstr "" + +#. module: mrp_bom_version +#: model:res.groups,name:mrp_bom_version.group_mrp_bom_version +msgid "MRP BoM version" +msgstr "" + +#. module: mrp_bom_version +#: model:ir.model,name:mrp_bom_version.model_mrp_production +msgid "Manufacturing Order" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "New version" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +msgid "Product" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +msgid "State" +msgstr "" + +#. module: mrp_bom_version +#: field:mrp.bom,state:0 +msgid "Status" +msgstr "" + +#. module: mrp_bom_version +#: help:mrp.config.settings,group_mrp_bom_state:0 +msgid "The active state may be passed back to state draft" +msgstr "" + +#. module: mrp_bom_version +#: field:mrp.bom,version:0 +msgid "Version" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "You are going to create a new version of this BoM. Are you sure?" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "You are going to historize an BoM. Doing, not be able to unlock it unless you make a copy. Are you sure you want to proceed?" +msgstr "" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "You will activate the BoM. If you haven't set a route yet, then you won't be able to do it after this. Are you sure you want to proceed?" +msgstr "" + diff --git a/mrp_bom_version/i18n/sl.po b/mrp_bom_version/i18n/sl.po new file mode 100644 index 000000000..5078a3cd8 --- /dev/null +++ b/mrp_bom_version/i18n/sl.po @@ -0,0 +1,126 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_version +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-01 21:03+0200\n" +"PO-Revision-Date: 2015-08-01 21:07+0200\n" +"Last-Translator: Matjaz Mozetic \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" +"%100==4 ? 2 : 3);\n" +"X-Generator: Poedit 1.8.2\n" +"Language: sl\n" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "Activate" +msgstr "Aktiviraj" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +#: selection:mrp.bom,state:0 +msgid "Active" +msgstr "Aktivno" + +#. module: mrp_bom_version +#: field:mrp.config.settings,group_mrp_bom_state:0 +msgid "Allow to re-edit BoMs" +msgstr "Dovoli preurejanje kosovnic" + +#. module: mrp_bom_version +#: model:ir.model,name:mrp_bom_version.model_mrp_bom +msgid "Bill of Material" +msgstr "Kosovnica" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +#: selection:mrp.bom,state:0 +msgid "Draft" +msgstr "Osnutek" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +#: selection:mrp.bom,state:0 +msgid "Historical" +msgstr "Zastarelo" + +#. module: mrp_bom_version +#: field:mrp.bom,historical_date:0 +msgid "Historical Date" +msgstr "Datum zastaranja" + +#. module: mrp_bom_version +#: model:mail.message.subtype,description:mrp_bom_version.mt_active +#: model:mail.message.subtype,name:mrp_bom_version.mt_active +msgid "MRP BoM Active" +msgstr "Proizvodna kosovnica aktivna" + +#. module: mrp_bom_version +#: model:res.groups,name:mrp_bom_version.group_mrp_bom_version +msgid "MRP BoM version" +msgstr "Verzija proizvodne kosovnice" + +#. module: mrp_bom_version +#: model:ir.model,name:mrp_bom_version.model_mrp_production +msgid "Manufacturing Order" +msgstr "Proizvodni nalog" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "New version" +msgstr "Nova verzija" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +msgid "Product" +msgstr "Proizvod" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.view_mrp_bom_filter_inh_state +msgid "State" +msgstr "Stanje" + +#. module: mrp_bom_version +#: field:mrp.bom,state:0 +msgid "Status" +msgstr "Status" + +#. module: mrp_bom_version +#: help:mrp.config.settings,group_mrp_bom_state:0 +msgid "The active state may be passed back to state draft" +msgstr "Aktivno stanje se lahko povrne v stanje osnutek" + +#. module: mrp_bom_version +#: field:mrp.bom,version:0 +msgid "Version" +msgstr "Verzija" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "You are going to create a new version of this BoM. Are you sure?" +msgstr "Ste prepričani, da želite ustvariti novo verzijo te kosovnice?" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "" +"You are going to historize an BoM. Doing, not be able to unlock it unless " +"you make a copy. Are you sure you want to proceed?" +msgstr "" +"Kosovnico postavljate v zastaranje. Ne boste je mogli odkleniti, razen, če " +"naredite kopijo. Želite nadaljevati?" + +#. module: mrp_bom_version +#: view:mrp.bom:mrp_bom_version.mrp_bom_form_view_inh_state +msgid "" +"You will activate the BoM. If you haven't set a route yet, then you won't be " +"able to do it after this. Are you sure you want to proceed?" +msgstr "" +"Aktivirali boste kosovnico. Če še niste nastavili proge, tega ne boste mogli " +"narediti po tem. Želite nadaljevati?" diff --git a/mrp_bom_version/models/__init__.py b/mrp_bom_version/models/__init__.py new file mode 100644 index 000000000..fa22f90a6 --- /dev/null +++ b/mrp_bom_version/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import mrp_bom +from . import res_config diff --git a/mrp_bom_version/models/mrp_bom.py b/mrp_bom_version/models/mrp_bom.py new file mode 100644 index 000000000..2298f8be2 --- /dev/null +++ b/mrp_bom_version/models/mrp_bom.py @@ -0,0 +1,153 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import models, fields, api + + +class MrpBom(models.Model): + _inherit = 'mrp.bom' + + _track = { + 'state': { + 'mrp_bom_version.mt_active': lambda self, cr, uid, obj, + ctx=None: obj.state == 'active', + }, + } + + @api.one + def _get_old_versions(self): + parent = self.parent_bom + old_version = self.env['mrp.bom'] + while parent: + old_version += parent + parent = parent.parent_bom + self.old_versions = old_version + + active = fields.Boolean( + string='Active', default=False, readonly=True, + states={'draft': [('readonly', False)]}) + historical_date = fields.Date(string='Historical Date', readonly=True) + state = fields.Selection( + selection=[('draft', 'Draft'), ('active', 'Active'), + ('historical', 'Historical')], string='State', + index=True, readonly=True, default='draft', copy=False) + product_tmpl_id = fields.Many2one( + readonly=True, states={'draft': [('readonly', False)]}) + product_id = fields.Many2one( + readonly=True, states={'draft': [('readonly', False)]}) + product_qty = fields.Float( + readonly=True, states={'draft': [('readonly', False)]}) + name = fields.Char( + states={'historical': [('readonly', True)]}) + code = fields.Char( + states={'historical': [('readonly', True)]}) + type = fields.Selection( + states={'historical': [('readonly', True)]}) + company_id = fields.Many2one( + states={'historical': [('readonly', True)]}) + product_uom = fields.Many2one( + states={'historical': [('readonly', True)]}) + routing_id = fields.Many2one( + readonly=True, states={'draft': [('readonly', False)]}) + bom_line_ids = fields.One2many( + readonly=True, states={'draft': [('readonly', False)]}) + position = fields.Char( + states={'historical': [('readonly', True)]}) + date_start = fields.Date( + states={'historical': [('readonly', True)]}) + date_stop = fields.Date( + states={'historical': [('readonly', True)]}) + property_ids = fields.Many2many( + states={'historical': [('readonly', True)]}) + product_rounding = fields.Float( + states={'historical': [('readonly', True)]}) + product_efficiency = fields.Float( + states={'historical': [('readonly', True)]}) + message_follower_ids = fields.Many2many( + states={'historical': [('readonly', True)]}) + message_ids = fields.One2many( + states={'historical': [('readonly', True)]}) + version = fields.Integer(states={'historical': [('readonly', True)]}, + copy=False, default=1) + parent_bom = fields.Many2one( + comodel_name='mrp.bom', string='Parent BoM') + old_versions = fields.Many2many( + comodel_name='mrp.bom', string='Old Versions', + compute='_get_old_versions') + + @api.multi + def button_draft(self): + active_draft = self.env['mrp.config.settings']._get_parameter( + 'active.draft') + self.write({ + 'active': active_draft and active_draft.value or False, + 'state': 'draft', + }) + + @api.multi + def button_new_version(self): + self.ensure_one() + new_bom = self._copy_bom() + self.button_historical() + return { + 'type': 'ir.actions.act_window', + 'view_type': 'form, tree', + 'view_mode': 'form', + 'res_model': 'mrp.bom', + 'res_id': new_bom.id, + 'target': 'current', + } + + def _copy_bom(self): + active_draft = self.env['mrp.config.settings']._get_parameter( + 'active.draft') + new_bom = self.copy({ + 'version': self.version + 1, + 'active': active_draft and active_draft.value or False, + 'parent_bom': self.id, + }) + return new_bom + + @api.multi + def button_activate(self): + self.write({ + 'active': True, + 'state': 'active' + }) + + @api.multi + def button_historical(self): + self.write({ + 'active': False, + 'state': 'historical', + 'historical_date': fields.Date.today() + }) + + def search(self, cr, uid, args, offset=0, limit=None, order=None, + context=None, count=False): + """Add search argument for field type if the context says so. This + should be in old API because context argument is not the last one. + """ + if context is None: + context = {} + search_state = context.get('state', False) + if search_state: + args += [('state', '=', search_state)] + return super(MrpBom, self).search( + cr, uid, args, offset=offset, limit=limit, order=order, + context=context, count=count) + + @api.model + def _bom_find( + self, product_tmpl_id=None, product_id=None, properties=None): + """ Finds BoM for particular product and product uom. + @param product_tmpl_id: Selected product. + @param product_uom: Unit of measure of a product. + @param properties: List of related properties. + @return: False or BoM id. + """ + bom_id = super(MrpBom, self.with_context(state='active'))._bom_find( + product_tmpl_id=product_tmpl_id, product_id=product_id, + properties=properties) + return bom_id diff --git a/mrp_bom_version/models/res_config.py b/mrp_bom_version/models/res_config.py new file mode 100644 index 000000000..67cd714d4 --- /dev/null +++ b/mrp_bom_version/models/res_config.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, fields, models + + +class MrpConfigSettings(models.TransientModel): + _inherit = 'mrp.config.settings' + + group_mrp_bom_version = fields.Boolean( + string='Allow to re-edit BoMs', + implied_group='mrp_bom_version.group_mrp_bom_version', + help='The active state may be passed back to state draft') + active_draft = fields.Boolean( + string='Keep re-editing BoM active', + help='This will allow you to define if those BoM passed back to draft' + ' are still activated or not') + + def _get_parameter(self, key, default=False): + param_obj = self.env['ir.config_parameter'] + rec = param_obj.search([('key', '=', key)]) + return rec or default + + def _write_or_create_param(self, key, value): + param_obj = self.env['ir.config_parameter'] + rec = self._get_parameter(key) + if rec: + if not value: + rec.unlink() + else: + rec.value = value + elif value: + param_obj.create({'key': key, 'value': value}) + + @api.multi + def get_default_parameters(self): + def get_value(key, default=''): + rec = self._get_parameter(key) + return rec and rec.value or default + return { + 'active_draft': get_value('active.draft', False), + } + + @api.multi + def set_parameters(self): + self._write_or_create_param('active.draft', self.active_draft) diff --git a/mrp_bom_version/security/mrp_bom_version_security.xml b/mrp_bom_version/security/mrp_bom_version_security.xml new file mode 100644 index 000000000..a0ea08559 --- /dev/null +++ b/mrp_bom_version/security/mrp_bom_version_security.xml @@ -0,0 +1,9 @@ + + + + + MRP BoM version + + + + diff --git a/mrp_bom_version/tests/__init__.py b/mrp_bom_version/tests/__init__.py new file mode 100644 index 000000000..12e4e76f0 --- /dev/null +++ b/mrp_bom_version/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_mrp_bom_version diff --git a/mrp_bom_version/tests/test_mrp_bom_version.py b/mrp_bom_version/tests/test_mrp_bom_version.py new file mode 100644 index 000000000..62a159284 --- /dev/null +++ b/mrp_bom_version/tests/test_mrp_bom_version.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +import openerp.tests.common as common + + +class TestMrpBomVersion(common.TransactionCase): + + def setUp(self): + super(TestMrpBomVersion, self).setUp() + self.parameter_model = self.env['ir.config_parameter'] + self.bom_model = self.env['mrp.bom'] + self.company = self.env.ref('base.main_company') + vals = { + 'company_id': self.company.id, + 'product_tmpl_id': + self.env.ref('product.product_product_11_product_template').id, + 'bom_line_ids': + [(0, 0, {'product_id': + self.env.ref('product.product_product_5').id}), + (0, 0, {'product_id': + self.env.ref('product.product_product_6').id})], + } + self.mrp_bom = self.bom_model.create(vals) + + def test_mrp_bom(self): + self.assertEqual( + self.mrp_bom.state, 'draft', "New BoM must be in state 'draft'") + self.assertEqual( + self.mrp_bom.version, 1, 'Incorrect version for new BoM') + self.assertFalse( + self.mrp_bom.active, 'New BoMs must be created inactive') + self.mrp_bom.button_activate() + self.assertTrue( + self.mrp_bom.active, 'Incorrect activation, check must be True') + self.assertEqual( + self.mrp_bom.state, 'active', + "Incorrect state, it should be 'active'") + self.mrp_bom.button_historical() + self.assertFalse( + self.mrp_bom.active, 'Check must be False, after historification') + self.assertEqual( + self.mrp_bom.state, 'historical', + "Incorrect state, it should be 'historical'") + + def test_mrp_bom_back2draft_default(self): + self.mrp_bom.button_activate() + self.mrp_bom.button_draft() + self.assertFalse( + self.mrp_bom.active, 'Check must be False') + + def test_mrp_bom_back2draft_active(self): + self.parameter_model.create({'key': 'active.draft', 'value': True}) + self.mrp_bom.button_activate() + self.mrp_bom.button_draft() + self.assertTrue( + self.mrp_bom.active, 'Check must be True, as set in parameters') + + def test_mrp_bom_versioning(self): + self.mrp_bom.button_activate() + self.mrp_bom.button_new_version() + self.assertFalse( + self.mrp_bom.active, + 'Check must be False, it must have been historified') + self.assertEqual( + self.mrp_bom.state, 'historical', + 'Incorrect state, it must have been historified') + new_boms = self.bom_model.search( + [('parent_bom', '=', self.mrp_bom.id)]) + for new_bom in new_boms: + self.assertEqual( + new_bom.version, self.mrp_bom.version + 1, + 'New BoM version must be +1 from origin BoM version') + self.assertEqual( + new_bom.active, + self.parameter_model.search( + [('key', '=', 'active.draft')]).value, + 'It does not match active draft check state set in company') + self.assertEqual( + new_bom.state, 'draft', + "New version must be created in 'draft' state") diff --git a/mrp_bom_version/views/mrp_bom_view.xml b/mrp_bom_version/views/mrp_bom_view.xml new file mode 100644 index 000000000..e96b51c9b --- /dev/null +++ b/mrp_bom_version/views/mrp_bom_view.xml @@ -0,0 +1,109 @@ + + + + + ['|',('active','=',True),('active','=',False)] + + + + mrp.bom.tree + mrp.bom + + + + + + + + + + + mrp.bom.version.tree + mrp.bom + + + + + + + +