Merge pull request #40 from odoomrp/8.0-mrp_bom_version

[MIG] mrp_bom_version: migrated from odoomrp-wip
This commit is contained in:
Pedro M. Baeza
2015-10-26 16:48:56 +01:00
17 changed files with 923 additions and 3 deletions

View File

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

View File

@@ -2,7 +2,7 @@
<openerp>
<data>
<record id="mrp_bom_tree_view" model="ir.ui.view">
<record id="mrp.mrp_bom_tree_parent_view" model="ir.ui.view">
<field name="name">mrp.bom.tree</field>
<field name="model">mrp.bom</field>
<field name="arch" type="xml">

View File

@@ -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 <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
`here <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_version%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Ana Juaristi <anajuaristi@avanzosc.es>
* Alfredo de la Fuente <alfredodelafuente@avanzosc.es>
* Oihane Crucelaegui <oihanecrucelaegui@avanzosc.es>

View File

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

View File

@@ -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 <pedro.baeza@serviciosbaeza.com>",
"Ana Juaristi <anajuaristi@avanzosc.es>",
"Alfredo de la Fuente <alfredodelafuente@avanzosc.es>",
"Oihane Crucelaegui <oihanecrucelaegui@avanzosc.es>",
],
"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",
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="mt_active" model="mail.message.subtype">
<field name="name">MRP BoM Active</field>
<field name="res_model">mrp.bom</field>
<field name="default" eval="False"/>
<field name="description">MRP BoM Active</field>
</record>
</data>
</openerp>

125
mrp_bom_version/i18n/es.po Normal file
View File

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

View File

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

126
mrp_bom_version/i18n/sl.po Normal file
View File

@@ -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 <m.mozetic@matmoz.si>\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?"

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data noupdate="1">
<record id="group_mrp_bom_version" model="res.groups">
<field name="name">MRP BoM version</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>
</data>
</openerp>

View File

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

View File

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

View File

@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.actions.act_window" id="mrp.mrp_bom_form_action">
<field name="domain">['|',('active','=',True),('active','=',False)]</field>
</record>
<record id="mrp.mrp_bom_tree_parent_view" model="ir.ui.view">
<field name="name">mrp.bom.tree</field>
<field name="model">mrp.bom</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="code"/>
<field name="sequence"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="mrp_bom_version_tree_view">
<field name="name">mrp.bom.version.tree</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_tree_parent_view"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="active" />
<field name="version" />
<field name="state" />
<field name="historical_date"/>
<button name="button_draft" type="object" string="Draft"
groups="mrp_bom_version.group_mrp_bom_version"
attrs="{'invisible':[('state','!=','active')]}"
icon="terp-document-new" />
<button name="button_activate" type="object" string="Activate"
attrs="{'invisible':[('state','not in',(False, 'draft'))]}"
icon="terp-camera_test"
confirm="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?"/>
<button name="button_new_version" type="object" string="New version"
attrs="{'invisible':[('state','==','historical')]}"
icon="gtk-execute"
confirm="You are going to create a new version of this BoM. Are you sure?"/>
<button name="button_historical" type="object" string="Historical"
attrs="{'invisible':[('state','!=','active')]}"
icon="gtk-convert"
confirm="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?"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="mrp_bom_version_form_view">
<field name="name">mrp.bom.version.form</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//form/group" position="before">
<header>
<button name="button_draft" type="object" string="Draft"
groups="mrp_bom_version.group_mrp_bom_version"
attrs="{'invisible':[('state','!=','active')]}"
class="oe_highlight" />
<button name="button_activate" type="object" string="Activate"
attrs="{'invisible':[('state','not in',(False, 'draft'))]}"
class="oe_highlight"
confirm="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?"/>
<button name="button_new_version" type="object" string="New version"
attrs="{'invisible':[('state','==','historical')]}"
class="oe_highlight"
confirm="You are going to create a new version of this BoM. Are you sure?"/>
<button name="button_historical" type="object" string="Historical"
attrs="{'invisible':[('state','!=','active')]}"
class="oe_highlight"
confirm="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?"/>
<field name="state" widget="statusbar" statusbar_visible="draft,active,historical" />
</header>
</xpath>
<field name="company_id" position="after">
<field name="version" />
<field name="historical_date" attrs="{'invisible': [('state','!=','historical')]}"/>
</field>
<notebook position="inside">
<page string="Versions">
<field name="old_versions" />
</page>
</notebook>
</field>
</record>
<record model="ir.ui.view" id="mrp_bom_version_search_view">
<field name="name">mrp.bom.version.search</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.view_mrp_bom_filter"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="active" />
<field name="state" />
</field>
<group string="Group By..." position="before">
<filter string="Active" domain="[('active','=',True)]" name="is_active_filter"/>
<filter string="Inactive" domain="[('active','=',False)]" name="is_inactive_filter"/>
</group>
<group string="Group By..." position="inside">
<filter string="Active" domain="[]" context="{'group_by':'active'}"/>
<filter string="State" domain="[]" context="{'group_by':'state'}"/>
</group>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="mrp_config_settings_versioning">
<field name="name">mrp.config.settings.versioning</field>
<field name="model">mrp.config.settings</field>
<field name="inherit_id" ref="mrp.view_mrp_config" />
<field name="arch" type="xml">
<xpath expr="//field[@name='module_mrp_repair']/.." position="after">
<div>
<field name="group_mrp_bom_version" class="oe_inline"/>
<label for="group_mrp_bom_version"/>
</div>
<div attrs="{'invisible': [('group_mrp_bom_version', '=', False)]}">
<field name="active_draft" class="oe_inline"/>
<label for="active_draft"/>
</div>
</xpath>
</field>
</record>
</data>
</openerp>