Skip to content

Commit efc2739

Browse files
Merge pull request #5472 from hbrunn/19.0-initialize+openupgrade_framework+base+uom
[19.0][MIG] uom
2 parents d83288f + 454c83a commit efc2739

File tree

7 files changed

+433
-1
lines changed

7 files changed

+433
-1
lines changed

docsource/modules180-190.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ Module coverage 18.0 -> 19.0
11101110
+---------------------------------------------------+----------------------+-------------------------------------------------+
11111111
| transifex | |No DB layout changes. |
11121112
+---------------------------------------------------+----------------------+-------------------------------------------------+
1113-
| uom | | |
1113+
| uom |Done | |
11141114
+---------------------------------------------------+----------------------+-------------------------------------------------+
11151115
| utm | | |
11161116
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<odoo>
3+
<record id="product_uom_cm" model="uom.uom">
4+
<!--
5+
<field name="factor"/>
6+
<field name="active" eval="False"/>
7+
-->
8+
<field name="relative_factor" eval="10"/>
9+
<field name="relative_uom_id" ref="uom.product_uom_millimeter"/>
10+
</record>
11+
<record id="product_uom_cubic_foot" model="uom.uom">
12+
<!--
13+
<field name="active" eval="False"/>
14+
-->
15+
<field name="relative_factor" eval="1728"/>
16+
<field name="relative_uom_id" ref="uom.product_uom_cubic_inch"/>
17+
</record>
18+
<record id="product_uom_cubic_inch" model="uom.uom">
19+
<!--
20+
<field name="factor"/>
21+
<field name="active" eval="False"/>
22+
-->
23+
<field name="relative_factor" eval="0.0163871"/>
24+
<field name="relative_uom_id" ref="uom.product_uom_litre"/>
25+
</record>
26+
<record id="product_uom_cubic_meter" model="uom.uom">
27+
<!--
28+
<field name="active" eval="False"/>
29+
-->
30+
<field name="relative_factor">1000</field>
31+
<field name="relative_uom_id" ref="uom.product_uom_litre"/>
32+
</record>
33+
<record id="product_uom_day" model="uom.uom">
34+
<!--
35+
<field name="factor"/>
36+
-->
37+
<field name="relative_factor" eval="8.0"/>
38+
<field name="relative_uom_id" ref="uom.product_uom_hour"/>
39+
</record>
40+
<record id="product_uom_dozen" model="uom.uom">
41+
<!--
42+
<field name="active" eval="False"/>
43+
-->
44+
<field name="relative_factor" eval="12"/>
45+
<field name="relative_uom_id" ref="uom.product_uom_unit"/>
46+
</record>
47+
<record id="product_uom_floz" model="uom.uom">
48+
<!--
49+
<field name="factor"/>
50+
<field name="active" eval="False"/>
51+
-->
52+
<field name="relative_factor" eval="0.0295735"/>
53+
<field name="relative_uom_id" ref="uom.product_uom_litre"/>
54+
</record>
55+
<record id="product_uom_foot" model="uom.uom">
56+
<!--
57+
<field name="factor"/>
58+
<field name="active" eval="False"/>
59+
-->
60+
<field name="relative_factor" eval="12"/>
61+
<field name="relative_uom_id" ref="uom.product_uom_inch"/>
62+
</record>
63+
<record id="product_uom_gal" model="uom.uom">
64+
<!--
65+
<field name="active" eval="False"/>
66+
-->
67+
<field name="relative_factor" eval="4"/>
68+
<field name="relative_uom_id" ref="uom.product_uom_qt"/>
69+
</record>
70+
<record id="product_uom_gram" model="uom.uom">
71+
<!--
72+
<field name="factor"/>
73+
-->
74+
<field name="relative_factor" eval="1"/>
75+
</record>
76+
<record id="product_uom_hour" model="uom.uom">
77+
<!--
78+
<field name="factor"/>
79+
-->
80+
<field name="relative_factor" eval="1"/>
81+
</record>
82+
<record id="product_uom_inch" model="uom.uom">
83+
<!--
84+
<field name="factor"/>
85+
<field name="active" eval="False"/>
86+
-->
87+
<field name="relative_factor" eval="2.54"/>
88+
<field name="relative_uom_id" ref="uom.product_uom_cm"/>
89+
</record>
90+
<record id="product_uom_kgm" model="uom.uom">
91+
<!--
92+
<field name="factor"/>
93+
-->
94+
<field name="relative_factor" eval="1000"/>
95+
<field name="relative_uom_id" ref="uom.product_uom_gram"/>
96+
</record>
97+
<record id="product_uom_km" model="uom.uom">
98+
<!--
99+
<field name="active" eval="False"/>
100+
-->
101+
<field name="relative_factor" eval="1000"/>
102+
<field name="relative_uom_id" ref="uom.product_uom_meter"/>
103+
</record>
104+
<record id="product_uom_kwh" model="uom.uom">
105+
<!--
106+
<field name="factor"/>
107+
-->
108+
<field name="relative_factor" eval="1.0"/>
109+
</record>
110+
<record id="product_uom_lb" model="uom.uom">
111+
<!--
112+
<field name="factor"/>
113+
<field name="active" eval="False"/>
114+
-->
115+
<field name="relative_factor" eval="16"/>
116+
<field name="relative_uom_id" ref="uom.product_uom_oz"/>
117+
</record>
118+
<record id="product_uom_litre" model="uom.uom">
119+
<!--
120+
<field name="factor"/>
121+
-->
122+
<field name="relative_factor">1000</field>
123+
<field name="relative_uom_id" ref="uom.product_uom_milliliter"/>
124+
</record>
125+
<record id="product_uom_meter" model="uom.uom">
126+
<!--
127+
<field name="factor"/>
128+
-->
129+
<field name="relative_factor" eval="100.0"/>
130+
<field name="relative_uom_id" ref="uom.product_uom_cm"/>
131+
</record>
132+
<record id="product_uom_mile" model="uom.uom">
133+
<!--
134+
<field name="active" eval="False"/>
135+
-->
136+
<field name="relative_factor" eval="1760"/>
137+
<field name="relative_uom_id" ref="uom.product_uom_yard"/>
138+
</record>
139+
<record id="product_uom_millimeter" model="uom.uom">
140+
<!--
141+
<field name="factor"/>
142+
-->
143+
<field name="relative_factor" eval="1"/>
144+
</record>
145+
<record id="product_uom_minute" model="uom.uom">
146+
<!--
147+
<field name="factor"/>
148+
-->
149+
<field name="relative_factor" eval="0.0166667"/>
150+
<field name="relative_uom_id" ref="uom.product_uom_hour"/>
151+
</record>
152+
<record id="product_uom_oz" model="uom.uom">
153+
<!--
154+
<field name="factor"/>
155+
<field name="active" eval="False"/>
156+
-->
157+
<field name="relative_factor" eval="28.3495"/>
158+
<field name="relative_uom_id" ref="uom.product_uom_gram"/>
159+
</record>
160+
<record id="product_uom_qt" model="uom.uom">
161+
<!--
162+
<field name="factor"/>
163+
<field name="active" eval="False"/>
164+
-->
165+
<field name="relative_factor" eval="32"/>
166+
<field name="relative_uom_id" ref="uom.product_uom_floz"/>
167+
</record>
168+
<record id="product_uom_ton" model="uom.uom">
169+
<field name="name">Ton</field>
170+
<field name="relative_factor" eval="1000"/>
171+
<field name="relative_uom_id" ref="uom.product_uom_kgm"/>
172+
</record>
173+
<record id="product_uom_unit" model="uom.uom">
174+
<!--
175+
<field name="factor"/>
176+
-->
177+
<field name="relative_factor" eval="1.0"/>
178+
</record>
179+
<record id="product_uom_yard" model="uom.uom">
180+
<!--
181+
<field name="factor"/>
182+
<field name="active" eval="False"/>
183+
-->
184+
<field name="relative_factor" eval="3"/>
185+
<field name="relative_uom_id" ref="uom.product_uom_foot"/>
186+
</record>
187+
</odoo>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2025 Hunki Enterprises BV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from openupgradelib import openupgrade
5+
6+
7+
def _uom_relative_uom_id_relative_factor(env):
8+
"""
9+
UOM categories have been obsoleted, UOMs are a tree now with the reference
10+
unit as root and relative_factor giving the ratio to the UOM linked in
11+
relative_uom_id
12+
"""
13+
14+
Uom = env["uom.uom"]
15+
16+
env.cr.execute(
17+
"SELECT res_id FROM ir_model_data WHERE "
18+
"model='uom.uom' AND module != '__export__'"
19+
)
20+
with_xml_id = Uom.browse(set(_id for (_id,) in env.cr.fetchall()))
21+
22+
env.cr.execute(
23+
f"""
24+
SELECT
25+
array_agg(id),
26+
array_agg({openupgrade.get_legacy_name("factor")}),
27+
array_agg({openupgrade.get_legacy_name("uom_type")})
28+
FROM
29+
uom_uom
30+
WHERE {openupgrade.get_legacy_name("category_id")} IS NOT NULL
31+
GROUP BY {openupgrade.get_legacy_name("category_id")}
32+
"""
33+
)
34+
for ids, factors, uom_types in env.cr.fetchall():
35+
uoms = Uom.browse(ids)
36+
uom2factor = dict(zip(uoms, factors, strict=True))
37+
uom2type = dict(zip(uoms, uom_types, strict=True))
38+
39+
old_reference = uoms.filtered(
40+
lambda x, uom2type=uom2type: uom2type[x] == "reference"
41+
)
42+
43+
for uom in uoms - old_reference - with_xml_id:
44+
# uoms with xmlid will be updated by the migration of the module
45+
# providing them
46+
relative_factor = (
47+
uom2factor[uom] if uom2type[uom] == "bigger" else (1 / uom2factor[uom])
48+
)
49+
50+
uom.write(
51+
{
52+
"relative_uom_id": old_reference,
53+
"relative_factor": relative_factor,
54+
}
55+
)
56+
57+
58+
@openupgrade.migrate()
59+
def migrate(env, version):
60+
openupgrade.load_data(env, "uom", "19.0.1.0/noupdate_changes_work.xml")
61+
_uom_relative_uom_id_relative_factor(env)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 Hunki Enterprises BV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from openupgradelib import openupgrade
5+
6+
7+
@openupgrade.migrate()
8+
def migrate(env, version):
9+
openupgrade.copy_columns(
10+
env.cr,
11+
{
12+
"uom_uom": [
13+
("category_id", None, None),
14+
("factor", None, None),
15+
("rounding", None, None),
16+
("uom_type", None, None),
17+
]
18+
},
19+
)
20+
openupgrade.rename_xmlids(
21+
env.cr,
22+
[
23+
("product.decimal_product_uom", "uom.decimal_product_uom"),
24+
("uom.uom_square_foot", "uom.product_uom_square_foot"),
25+
("uom.uom_square_meter", "uom.product_uom_square_meter"),
26+
],
27+
)
28+
# this would be cleaned up after the migration, but we can't have it during
29+
# migration
30+
openupgrade.delete_sql_constraint_safely(
31+
env, "uom", "uom_uom", "factor_reference_is_one"
32+
)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---Models in module 'uom'---
2+
obsolete model uom.category
3+
---Fields in module 'uom'---
4+
uom / uom.category / name (char) : DEL required
5+
uom / uom.category / reference_uom_id (many2one) : DEL relation: uom.uom, stored: False
6+
uom / uom.category / uom_ids (one2many) : DEL relation: uom.uom
7+
8+
# NOTHING TO DO
9+
10+
uom / uom.uom / _order : _order is now 'sequence, relative_uom_id, id' ('factor DESC, id')
11+
12+
# NOTHING TO DO
13+
14+
uom / uom.uom / category_id (many2one) : DEL relation: uom.category, required
15+
16+
# NOTHING TO DO
17+
18+
uom / uom.uom / factor (float) : now a function
19+
uom / uom.uom / parent_path (char) : NEW
20+
uom / uom.uom / related_uom_ids (one2many) : NEW relation: uom.uom
21+
uom / uom.uom / relative_factor (float) : NEW required, hasdefault: default
22+
uom / uom.uom / relative_uom_id (many2one) : NEW relation: uom.uom
23+
24+
# DONE: compute relative_factor, relative_uom_id for custom UOMs in post-migration
25+
26+
uom / uom.uom / rounding (float) : not stored anymore
27+
28+
# DONE: copied to legacy column in pre-migration
29+
30+
uom / uom.uom / rounding (float) : now a function
31+
uom / uom.uom / sequence (integer) : NEW hasdefault: compute
32+
33+
# NOTHING TO DO
34+
35+
uom / uom.uom / uom_type (selection) : DEL required, selection_keys: ['bigger', 'reference', 'smaller']
36+
37+
# DONE: copied to legacy column in pre-migration
38+
39+
---XML records in module 'uom'---
40+
NEW decimal.precision: uom.decimal_product_uom [renamed from product module] (noupdate)
41+
42+
# DONE: renamed in pre-migration
43+
44+
DEL ir.actions.act_window: uom.product_uom_categ_form_action
45+
DEL ir.model.access: uom.access_uom_category_manager
46+
DEL ir.model.access: uom.access_uom_category_user
47+
ir.model.constraint: uom.constraint_uom_uom_factor_gt_zero (changed definition: is now 'CHECK (relative_factor!=0)' ('check(factor!=0)'))
48+
DEL ir.model.constraint: uom.constraint_uom_uom_factor_reference_is_one
49+
DEL ir.model.constraint: uom.constraint_uom_uom_rounding_gt_zero
50+
DEL ir.ui.view: uom.product_uom_categ_form_view
51+
DEL ir.ui.view: uom.product_uom_categ_tree_view
52+
DEL ir.ui.view: uom.uom_categ_view_search
53+
DEL uom.category: uom.product_uom_categ_energy (noupdate)
54+
DEL uom.category: uom.product_uom_categ_kgm (noupdate)
55+
DEL uom.category: uom.product_uom_categ_unit (noupdate)
56+
DEL uom.category: uom.product_uom_categ_vol (noupdate)
57+
DEL uom.category: uom.uom_categ_length (noupdate)
58+
DEL uom.category: uom.uom_categ_surface (noupdate)
59+
DEL uom.category: uom.uom_categ_wtime (noupdate)
60+
NEW uom.uom: uom.product_uom_milliliter (noupdate)
61+
NEW uom.uom: uom.product_uom_pack_6 (noupdate)
62+
63+
# NOTHING TO DO
64+
65+
NEW uom.uom: uom.product_uom_square_foot (noupdate)
66+
NEW uom.uom: uom.product_uom_square_meter (noupdate)
67+
DEL uom.uom: uom.uom_square_foot (noupdate)
68+
DEL uom.uom: uom.uom_square_meter (noupdate)
69+
70+
# DONE: renamed in pre-migration

0 commit comments

Comments
 (0)