mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] <mrp_bom_version> Older versions shown in each BoM
This commit is contained in:
@@ -15,15 +15,23 @@ class MrpBom(models.Model):
|
||||
},
|
||||
}
|
||||
|
||||
@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([('draft', 'Draft'),
|
||||
('active', 'Active'),
|
||||
('historical', 'Historical'),
|
||||
], string='Status', index=True, readonly=True,
|
||||
default='draft', copy=False)
|
||||
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(
|
||||
@@ -62,6 +70,11 @@ class MrpBom(models.Model):
|
||||
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):
|
||||
@@ -70,27 +83,39 @@ class MrpBom(models.Model):
|
||||
@api.multi
|
||||
def button_new_version(self):
|
||||
self.ensure_one()
|
||||
self.write({'active': False, 'state': 'historical',
|
||||
'historical_date': fields.Date.today()})
|
||||
version = self.version + 1
|
||||
new_bom = self.copy({'version': version})
|
||||
new_bom.active = True
|
||||
return {'type': 'ir.actions.act_window',
|
||||
'view_type': 'form, tree',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'mrp.bom',
|
||||
'res_id': new_bom.id,
|
||||
'target': 'new',
|
||||
}
|
||||
new_bom = self.copy({
|
||||
'version': self.version + 1,
|
||||
'active': True,
|
||||
'parent_bom': self.id,
|
||||
})
|
||||
self.write({
|
||||
'active': False,
|
||||
'state': 'historical',
|
||||
'historical_date': fields.Date.today(),
|
||||
})
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form, tree',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'mrp.bom',
|
||||
'res_id': new_bom.id,
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@api.one
|
||||
def button_activate(self):
|
||||
return self.write({'active': True, 'state': 'active'})
|
||||
self.write({
|
||||
'active': True,
|
||||
'state': 'active'
|
||||
})
|
||||
|
||||
@api.one
|
||||
def button_historical(self):
|
||||
return self.write({'active': False, 'state': 'historical',
|
||||
'historical_date': fields.Date.today()})
|
||||
self.write({
|
||||
'active': False,
|
||||
'state': 'historical',
|
||||
'historical_date': fields.Date.today()
|
||||
})
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<?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.parent.view</field>
|
||||
<field name="model">mrp.bom</field>
|
||||
@@ -63,6 +67,11 @@
|
||||
<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>
|
||||
|
||||
@@ -75,10 +84,14 @@
|
||||
<field name="active" />
|
||||
<field name="state" />
|
||||
</field>
|
||||
<filter string="Product" position="before">
|
||||
<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'}"/>
|
||||
</filter>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user