diff --git a/mrp_bom_version/README.rst b/mrp_bom_version/README.rst new file mode 100644 index 000000000..f66a2b32c --- /dev/null +++ b/mrp_bom_version/README.rst @@ -0,0 +1,18 @@ +MRP - BoM version +================= + +This module performs the following: + +1.- In the MRP BoM list object, 2 new fields are added: + + 1.1.- Historical Date, of type date. + 1.2.- Status, of type selection, with these values: draft, in active + and historical. This new field has gotten because it has added a + workflow to MRP BoM list object. + +You can only modify the components and / or production process if it is in +draft status. The other fields can only be changed if they are not in +historical state. +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. diff --git a/mrp_bom_version/__openerp__.py b/mrp_bom_version/__openerp__.py index 5f24fba0d..a9b57c916 100644 --- a/mrp_bom_version/__openerp__.py +++ b/mrp_bom_version/__openerp__.py @@ -16,32 +16,17 @@ # ############################################################################## { - "name": "MRP BoM Version", + "name": "MRP - BoM Version", "version": "1.0", "author": "OdooMRP team", "category": "Manufacturing", "website": "http://www.odoomrp.com", - "description": """ - This module performs the following: - - 1.- In the MRP BoM list object, 2 new fields are added: - - 1.1.- Historical Date, of type date. - 1.2.- Status, of type selection, with these values: draft, in active - and historical. This new field has gotten because it has added a - workflow to MRP BoM list object. - - You can only modify the components and / or production process if it is in - draft status. The other fields can only be changed if they are not in - historical state. - when the MRP BoM list is put to active, a record of who has activated, - and when will include in chatter/log. - Also creates a constraint for the sequence field to be unique. - """, - "depends": ['mrp', - ], - "data": ['data/mrp_bom_data.xml', - 'views/mrp_bom_view.xml', - ], + "depends": [ + "mrp", + ], + "data": [ + "data/mrp_bom_data.xml", + "views/mrp_bom_view.xml", + ], "installable": True } diff --git a/mrp_bom_version/models/mrp.py b/mrp_bom_version/models/mrp.py index 61d2caf86..644e33fe5 100644 --- a/mrp_bom_version/models/mrp.py +++ b/mrp_bom_version/models/mrp.py @@ -28,35 +28,32 @@ class MrpBom(models.Model): }, } + def _get_max_sequence(self): + bom = self.search([], order='sequence desc', limit=1) + maxseq = bom.sequence + 1 + return maxseq + historical_date = fields.Date(string='Historical Date', readonly=True) state = fields.Selection([('draft', 'Draft'), ('active', 'Active'), ('historical', 'Historical'), ], string='Status', index=True, readonly=True, default='draft', copy=False) + sequence = fields.Integer(default=_get_max_sequence) @api.one @api.constrains('sequence') def check_mrp_bom_sequence(self): - domain = [('id', '!=', self.id), ('sequence', '=', self.sequence)] - if self.product_tmpl_id: - domain.append(('product_tmpl_id', '=', self.product_tmpl_id.id)) - else: - domain.append(('product_tmpl_id', '=', False)) - if self.product_id: - domain.append(('product_id', '=', self.product_id.id)) - else: - domain.append(('product_id', '=', False)) - found = self.search(domain) - if found: + domain = [('id', '!=', self.id), ('sequence', '=', self.sequence), + ('product_tmpl_id', '=', self.product_tmpl_id.id), + ('product_id', '=', self.product_id.id)] + if self.search(domain): raise exceptions.Warning( _('The sequence must be unique')) @api.one def copy(self, default=None): - bom = self.search([], order='sequence desc', limit=1) - maxseq = bom.sequence + 1 - default.update({'sequence': maxseq}) + default.update({'sequence': self._get_max_sequence()}) return super(MrpBom, self).copy(default=default) @api.multi