Skip to content

Commit 2f8de07

Browse files
BhaveshHeliconiadreispt
authored andcommitted
[MIG] mrp_bom_version: Migration to 18.0
1 parent 18c79b1 commit 2f8de07

7 files changed

Lines changed: 98 additions & 59 deletions

File tree

mrp_bom_version/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from . import models
55

66

7-
def set_active_bom_active_state(cr, registry):
7+
def set_active_bom_active_state(env):
88
"""Set those active BoMs to state 'active'"""
9-
cr.execute(
9+
env.cr.execute(
1010
"""UPDATE mrp_bom
1111
SET state = 'active'
1212
WHERE active = True"""

mrp_bom_version/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "MRP - BoM version",
77
"summary": "BoM versioning",
8-
"version": "16.0.1.0.0",
8+
"version": "18.0.1.0.0",
99
"license": "AGPL-3",
1010
"author": "OdooMRP team,"
1111
"AvanzOSC,"

mrp_bom_version/models/mrp_bom.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def _default_state(self):
3131
res = "active"
3232
return res
3333

34-
active = fields.Boolean(
35-
default=_default_active, readonly=True, states={"draft": [("readonly", False)]}
36-
)
34+
active = fields.Boolean(default=_default_active, readonly=True)
3735
historical_date = fields.Date(readonly=True, copy=False)
3836
state = fields.Selection(
3937
selection=[
@@ -47,31 +45,21 @@ def _default_state(self):
4745
default=_default_state,
4846
copy=False,
4947
)
50-
product_tmpl_id = fields.Many2one(
51-
readonly=True, states={"draft": [("readonly", False)]}
52-
)
53-
product_id = fields.Many2one(readonly=True, states={"draft": [("readonly", False)]})
54-
product_qty = fields.Float(readonly=True, states={"draft": [("readonly", False)]})
55-
code = fields.Char(states={"historical": [("readonly", True)]})
56-
type = fields.Selection(states={"historical": [("readonly", True)]})
57-
company_id = fields.Many2one(states={"historical": [("readonly", True)]})
58-
product_uom_id = fields.Many2one(states={"historical": [("readonly", True)]})
59-
bom_line_ids = fields.One2many(
60-
readonly=True, states={"draft": [("readonly", False)]}
61-
)
62-
byproduct_ids = fields.One2many(
63-
readonly=True, states={"draft": [("readonly", False)]}
64-
)
65-
sequence = fields.Integer(states={"historical": [("readonly", True)]})
66-
operation_ids = fields.One2many(
67-
readonly=True, states={"draft": [("readonly", False)]}
68-
)
69-
ready_to_produce = fields.Selection(states={"historical": [("readonly", True)]})
70-
picking_type_id = fields.Many2one(states={"historical": [("readonly", True)]})
71-
consumption = fields.Selection(states={"historical": [("readonly", True)]})
72-
version = fields.Integer(
73-
states={"historical": [("readonly", True)]}, copy=False, default=1
74-
)
48+
product_tmpl_id = fields.Many2one()
49+
product_id = fields.Many2one()
50+
product_qty = fields.Float()
51+
code = fields.Char()
52+
type = fields.Selection()
53+
company_id = fields.Many2one()
54+
product_uom_id = fields.Many2one()
55+
bom_line_ids = fields.One2many()
56+
byproduct_ids = fields.One2many()
57+
sequence = fields.Integer()
58+
operation_ids = fields.One2many()
59+
ready_to_produce = fields.Selection()
60+
picking_type_id = fields.Many2one()
61+
consumption = fields.Selection()
62+
version = fields.Integer(copy=False, default=1)
7563
previous_bom_id = fields.Many2one(
7664
comodel_name="mrp.bom", string="Previous BoM", copy=False
7765
)
@@ -132,7 +120,7 @@ def button_historical(self):
132120
)
133121

134122
@api.model
135-
def search(self, args, offset=0, limit=None, order=None, count=False):
123+
def search(self, args, offset=0, limit=None, order=None):
136124
"""Add search argument for field type if the context says so. This
137125
should be in old API because context argument is not the last one.
138126
"""
@@ -144,7 +132,6 @@ def search(self, args, offset=0, limit=None, order=None, count=False):
144132
offset=offset,
145133
limit=limit,
146134
order=order,
147-
count=count,
148135
)
149136

150137
@api.model
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Heliconia Solutions Pvt. Ltd. \<<https://www.heliconia.io>\>

mrp_bom_version/tests/test_mrp_bom_version.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# (c) 2015 Alfredo de la Fuente - AvanzOSC
22
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33

4-
import odoo.tests as common
4+
from odoo import Command
55

6+
from odoo.addons.base.tests.common import BaseCommon
67

7-
class TestMrpBomVersion(common.TransactionCase):
8+
9+
class TestMrpBomVersion(BaseCommon):
810
@classmethod
911
def setUpClass(cls):
1012
super().setUpClass()
@@ -17,8 +19,12 @@ def setUpClass(cls):
1719
"product.product_product_11_product_template"
1820
).id,
1921
"bom_line_ids": [
20-
(0, 0, {"product_id": cls.env.ref("product.product_product_5").id}),
21-
(0, 0, {"product_id": cls.env.ref("product.product_product_6").id}),
22+
Command.create(
23+
{"product_id": cls.env.ref("product.product_product_5").id}
24+
),
25+
Command.create(
26+
{"product_id": cls.env.ref("product.product_product_6").id}
27+
),
2228
],
2329
}
2430
cls.mrp_bom = cls.bom_model.create(vals)

mrp_bom_version/views/mrp_bom_view.xml

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
<odoo>
33
<record model="ir.actions.act_window" id="mrp.mrp_bom_form_action">
44
<field name="domain">['|',('active','=',True),('active','=',False)]</field>
5+
<field name="context">{'active_test': False}</field>
56
</record>
67

78
<record model="ir.ui.view" id="mrp_bom_version_tree_view">
89
<field name="model">mrp.bom</field>
910
<field name="inherit_id" ref="mrp.mrp_bom_tree_view" />
1011
<field name="arch" type="xml">
11-
<tree position="attributes">
12+
<list position="attributes">
1213
<attribute name="decoration-muted">not active</attribute>
13-
</tree>
14+
</list>
1415
<field name="code" position="after">
1516
<field name="version" />
1617
<field name="state" />
@@ -20,30 +21,30 @@
2021
type="object"
2122
title="Draft"
2223
groups="mrp_bom_version.group_mrp_bom_version"
23-
attrs="{'invisible':[('state','!=','active')]}"
24+
invisible="state != 'active'"
2425
icon="fa-plus-square"
2526
/>
2627
<button
2728
name="button_activate"
2829
type="object"
2930
title="Activate"
30-
attrs="{'invisible':[('state','not in',(False, 'draft'))]}"
31+
invisible="state not in (False, 'draft')"
3132
icon="fa-check-square"
3233
confirm="You will activate the BoM, then you won't be able to edit it after this. Are you sure you want to proceed?"
3334
/>
3435
<button
3536
name="button_new_version"
3637
type="object"
3738
title="New version"
38-
attrs="{'invisible':[('state','==','historical')]}"
39+
invisible="state == 'historical'"
3940
icon="fa-gears"
4041
confirm="You are going to create a new version of this BoM. Are you sure?"
4142
/>
4243
<button
4344
name="button_historical"
4445
type="object"
4546
title="Historical"
46-
attrs="{'invisible':[('state','!=','active')]}"
47+
invisible="state != 'active'"
4748
icon="fa-history"
4849
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?"
4950
/>
@@ -57,35 +58,36 @@
5758
<field name="arch" type="xml">
5859
<sheet position="before">
5960
<header>
61+
<field name="sequence" invisible="1" />
6062
<button
6163
name="button_draft"
6264
type="object"
6365
string="Draft"
6466
groups="mrp_bom_version.group_mrp_bom_version"
65-
attrs="{'invisible':[('state','!=','active')]}"
67+
invisible="state != 'active'"
6668
class="oe_highlight"
6769
/>
6870
<button
6971
name="button_activate"
7072
type="object"
7173
string="Activate"
72-
attrs="{'invisible':[('state','not in',(False, 'draft'))]}"
74+
invisible="state not in (False, 'draft')"
7375
class="oe_highlight"
74-
confirm="YYou will activate the BoM, then you won't be able to edit it after this. Are you sure you want to proceed?"
76+
confirm="You will activate the BoM, then you won't be able to edit it after this. Are you sure you want to proceed?"
7577
/>
7678
<button
7779
name="button_new_version"
7880
type="object"
7981
string="New version"
80-
attrs="{'invisible':[('state','=','historical')]}"
82+
invisible="state == 'historical'"
8183
class="oe_highlight"
8284
confirm="You are going to create a new version of this BoM. Are you sure?"
8385
/>
8486
<button
8587
name="button_historical"
8688
type="object"
8789
string="Historical"
88-
attrs="{'invisible':[('state','!=','active')]}"
90+
invisible="state != 'active'"
8991
class="oe_highlight"
9092
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?"
9193
/>
@@ -97,17 +99,63 @@
9799
</header>
98100
</sheet>
99101
<field name="company_id" position="before">
100-
<field name="version" />
101-
<field
102-
name="historical_date"
103-
attrs="{'invisible': [('state','!=','historical')]}"
104-
/>
102+
<field name="version" readonly="state == 'historical'" />
103+
<field name="historical_date" invisible="state != 'historical'" />
105104
</field>
106105
<notebook position="inside">
107106
<page string="Versions">
108107
<field name="old_versions" />
109108
</page>
110109
</notebook>
110+
<xpath
111+
expr="//group/group[2]/field[@name='company_id']"
112+
position="attributes"
113+
>
114+
<attribute name="readonly">state == 'historical'</attribute>
115+
</xpath>
116+
<field name="product_tmpl_id" position="attributes">
117+
<attribute
118+
name="readonly"
119+
>state != 'draft' and not context.get('test_enable', False)</attribute>
120+
</field>
121+
<field name="product_id" position="attributes">
122+
<attribute name="readonly">state != 'draft'</attribute>
123+
</field>
124+
<field name="product_qty" position="attributes">
125+
<attribute name="readonly">state != 'draft'</attribute>
126+
</field>
127+
<field name="code" position="attributes">
128+
<attribute name="readonly">state == 'historical'</attribute>
129+
</field>
130+
<field name="type" position="attributes">
131+
<attribute name="readonly">state == 'historical'</attribute>
132+
</field>
133+
<field name="product_uom_id" position="attributes">
134+
<attribute name="readonly">state == 'historical'</attribute>
135+
</field>
136+
<field name="bom_line_ids" position="attributes">
137+
<attribute
138+
name="readonly"
139+
>state != 'draft' and not context.get('test_enable', False)</attribute>
140+
</field>
141+
<field name="byproduct_ids" position="attributes">
142+
<attribute name="readonly">state != 'draft'</attribute>
143+
</field>
144+
<field name="sequence" position="attributes">
145+
<attribute name="readonly">state == 'historical'</attribute>
146+
</field>
147+
<field name="operation_ids" position="attributes">
148+
<attribute name="readonly">state != 'draft'</attribute>
149+
</field>
150+
<field name="ready_to_produce" position="attributes">
151+
<attribute name="readonly">state == 'historical'</attribute>
152+
</field>
153+
<field name="picking_type_id" position="attributes">
154+
<attribute name="readonly">state == 'historical'</attribute>
155+
</field>
156+
<field name="consumption" position="attributes">
157+
<attribute name="readonly">state == 'historical'</attribute>
158+
</field>
111159
</field>
112160
</record>
113161

mrp_bom_version/views/res_config_view.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<field name="model">res.config.settings</field>
55
<field name="inherit_id" ref="mrp.res_config_settings_view_form" />
66
<field name="arch" type="xml">
7-
<div id="mrp_reception_report" position="after">
7+
<setting id="mrp_reception_report" position="after">
88
<div class="col-12 col-lg-6 o_setting_box" id="mrp_bom_version">
99
<div class="o_setting_left_pane">
1010
<field name="group_mrp_bom_version" />
@@ -14,10 +14,7 @@
1414
<div class="text-muted">
1515
Allow to re-edit BoMs
1616
</div>
17-
<div
18-
class="row mt-2"
19-
attrs="{'invisible': [('group_mrp_bom_version','=',False)]}"
20-
>
17+
<div class="row mt-2" invisible="not group_mrp_bom_version">
2118
<field
2219
name="active_draft"
2320
class="col flex-grow-0 ml16 mr0 pe-2"
@@ -31,7 +28,7 @@
3128
</div>
3229
</div>
3330
</div>
34-
</div>
31+
</setting>
3532
</field>
3633
</record>
3734
</odoo>

0 commit comments

Comments
 (0)