Skip to content

Commit

Permalink
[MIG] mrp_bom_version: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Jan 2, 2025
1 parent db97d2a commit 26bb434
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 54 deletions.
4 changes: 2 additions & 2 deletions mrp_bom_version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from . import models


def set_active_bom_active_state(cr, registry):
def set_active_bom_active_state(env):
"""Set those active BoMs to state 'active'"""
cr.execute(
env.cr.execute(
"""UPDATE mrp_bom
SET state = 'active'
WHERE active = True"""
Expand Down
2 changes: 1 addition & 1 deletion mrp_bom_version/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "MRP - BoM version",
"summary": "BoM versioning",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "OdooMRP team,"
"AvanzOSC,"
Expand Down
47 changes: 17 additions & 30 deletions mrp_bom_version/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def _default_state(self):
res = "active"
return res

active = fields.Boolean(
default=_default_active, readonly=True, states={"draft": [("readonly", False)]}
)
active = fields.Boolean(default=_default_active, readonly=True)
historical_date = fields.Date(readonly=True, copy=False)
state = fields.Selection(
selection=[
Expand All @@ -47,31 +45,21 @@ def _default_state(self):
default=_default_state,
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)]})
code = fields.Char(states={"historical": [("readonly", True)]})
type = fields.Selection(states={"historical": [("readonly", True)]})
company_id = fields.Many2one(states={"historical": [("readonly", True)]})
product_uom_id = fields.Many2one(states={"historical": [("readonly", True)]})
bom_line_ids = fields.One2many(
readonly=True, states={"draft": [("readonly", False)]}
)
byproduct_ids = fields.One2many(
readonly=True, states={"draft": [("readonly", False)]}
)
sequence = fields.Integer(states={"historical": [("readonly", True)]})
operation_ids = fields.One2many(
readonly=True, states={"draft": [("readonly", False)]}
)
ready_to_produce = fields.Selection(states={"historical": [("readonly", True)]})
picking_type_id = fields.Many2one(states={"historical": [("readonly", True)]})
consumption = fields.Selection(states={"historical": [("readonly", True)]})
version = fields.Integer(
states={"historical": [("readonly", True)]}, copy=False, default=1
)
product_tmpl_id = fields.Many2one()
product_id = fields.Many2one()
product_qty = fields.Float()
code = fields.Char()
type = fields.Selection()
company_id = fields.Many2one()
product_uom_id = fields.Many2one()
bom_line_ids = fields.One2many()
byproduct_ids = fields.One2many()
sequence = fields.Integer()
operation_ids = fields.One2many()
ready_to_produce = fields.Selection()
picking_type_id = fields.Many2one()
consumption = fields.Selection()
version = fields.Integer(copy=False, default=1)
previous_bom_id = fields.Many2one(
comodel_name="mrp.bom", string="Previous BoM", copy=False
)
Expand Down Expand Up @@ -132,7 +120,7 @@ def button_historical(self):
)

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def search(self, args, offset=0, limit=None, order=None):
"""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.
"""
Expand All @@ -144,7 +132,6 @@ def search(self, args, offset=0, limit=None, order=None, count=False):
offset=offset,
limit=limit,
order=order,
count=count,
)

@api.model
Expand Down
1 change: 1 addition & 0 deletions mrp_bom_version/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Heliconia Solutions Pvt. Ltd. \<<https://www.heliconia.io>\>
74 changes: 59 additions & 15 deletions mrp_bom_version/views/mrp_bom_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<odoo>
<record model="ir.actions.act_window" id="mrp.mrp_bom_form_action">
<field name="domain">['|',('active','=',True),('active','=',False)]</field>
<field name="context">{'active_test': False}</field>
</record>

<record model="ir.ui.view" id="mrp_bom_version_tree_view">
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_tree_view" />
<field name="arch" type="xml">
<tree position="attributes">
<list position="attributes">
<attribute name="decoration-muted">not active</attribute>
</tree>
</list>
<field name="code" position="after">
<field name="version" />
<field name="state" />
Expand All @@ -20,30 +21,30 @@
type="object"
title="Draft"
groups="mrp_bom_version.group_mrp_bom_version"
attrs="{'invisible':[('state','!=','active')]}"
invisible="state != 'active'"
icon="fa-plus-square"
/>
<button
name="button_activate"
type="object"
title="Activate"
attrs="{'invisible':[('state','not in',(False, 'draft'))]}"
invisible="state not in (False, 'draft')"
icon="fa-check-square"
confirm="You will activate the BoM, then you won't be able to edit it after this. Are you sure you want to proceed?"
/>
<button
name="button_new_version"
type="object"
title="New version"
attrs="{'invisible':[('state','==','historical')]}"
invisible="state == 'historical'"
icon="fa-gears"
confirm="You are going to create a new version of this BoM. Are you sure?"
/>
<button
name="button_historical"
type="object"
title="Historical"
attrs="{'invisible':[('state','!=','active')]}"
invisible="state != 'active'"
icon="fa-history"
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?"
/>
Expand All @@ -57,35 +58,36 @@
<field name="arch" type="xml">
<sheet position="before">
<header>
<field name="sequence" invisible="1" />
<button
name="button_draft"
type="object"
string="Draft"
groups="mrp_bom_version.group_mrp_bom_version"
attrs="{'invisible':[('state','!=','active')]}"
invisible="state != 'active'"
class="oe_highlight"
/>
<button
name="button_activate"
type="object"
string="Activate"
attrs="{'invisible':[('state','not in',(False, 'draft'))]}"
invisible="state not in (False, 'draft')"
class="oe_highlight"
confirm="YYou will activate the BoM, then you won't be able to edit it after this. Are you sure you want to proceed?"
/>
<button
name="button_new_version"
type="object"
string="New version"
attrs="{'invisible':[('state','=','historical')]}"
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')]}"
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?"
/>
Expand All @@ -97,17 +99,59 @@
</header>
</sheet>
<field name="company_id" position="before">
<field name="version" />
<field
name="historical_date"
attrs="{'invisible': [('state','!=','historical')]}"
/>
<field name="version" readonly="state == 'historical'" />
<field name="historical_date" invisible="state != 'historical'" />
</field>
<notebook position="inside">
<page string="Versions">
<field name="old_versions" />
</page>
</notebook>
<xpath
expr="//group/group[2]/field[@name='company_id']"
position="attributes"
>
<attribute name="readonly">state == 'historical'</attribute>
</xpath>
<field name="product_tmpl_id" position="attributes">
<attribute name="readonly">state != 'draft'</attribute>
</field>
<field name="product_id" position="attributes">
<attribute name="readonly">state != 'draft'</attribute>
</field>
<field name="product_qty" position="attributes">
<attribute name="readonly">state != 'draft'</attribute>
</field>
<field name="code" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
<field name="type" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
<field name="product_uom_id" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
<field name="bom_line_ids" position="attributes">
<attribute name="readonly">state != 'draft'</attribute>
</field>
<field name="byproduct_ids" position="attributes">
<attribute name="readonly">state != 'draft'</attribute>
</field>
<field name="sequence" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
<field name="operation_ids" position="attributes">
<attribute name="readonly">state != 'draft'</attribute>
</field>
<field name="ready_to_produce" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
<field name="picking_type_id" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
<field name="consumption" position="attributes">
<attribute name="readonly">state == 'historical'</attribute>
</field>
</field>
</record>

Expand Down
9 changes: 3 additions & 6 deletions mrp_bom_version/views/res_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="mrp.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="mrp_reception_report" position="after">
<setting id="mrp_reception_report" position="after">
<div class="col-12 col-lg-6 o_setting_box" id="mrp_bom_version">
<div class="o_setting_left_pane">
<field name="group_mrp_bom_version" />
Expand All @@ -14,10 +14,7 @@
<div class="text-muted">
Allow to re-edit BoMs
</div>
<div
class="row mt-2"
attrs="{'invisible': [('group_mrp_bom_version','=',False)]}"
>
<div class="row mt-2" invisible="not group_mrp_bom_version">
<field
name="active_draft"
class="col flex-grow-0 ml16 mr0 pe-2"
Expand All @@ -31,7 +28,7 @@
</div>
</div>
</div>
</div>
</setting>
</field>
</record>
</odoo>

0 comments on commit 26bb434

Please sign in to comment.