-
-
Notifications
You must be signed in to change notification settings - Fork 798
[19.0][MIG] uom #5472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MiquelRForgeFlow
merged 1 commit into
OCA:19.0
from
hbrunn:19.0-initialize+openupgrade_framework+base+uom
Feb 9, 2026
Merged
[19.0][MIG] uom #5472
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
openupgrade_scripts/scripts/uom/19.0.1.0/noupdate_changes_work.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
| <record id="product_uom_cm" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="10"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_millimeter"/> | ||
| </record> | ||
| <record id="product_uom_cubic_foot" model="uom.uom"> | ||
| <!-- | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="1728"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_cubic_inch"/> | ||
| </record> | ||
| <record id="product_uom_cubic_inch" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="0.0163871"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_litre"/> | ||
| </record> | ||
| <record id="product_uom_cubic_meter" model="uom.uom"> | ||
| <!-- | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor">1000</field> | ||
| <field name="relative_uom_id" ref="uom.product_uom_litre"/> | ||
| </record> | ||
| <record id="product_uom_day" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="8.0"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_hour"/> | ||
| </record> | ||
| <record id="product_uom_dozen" model="uom.uom"> | ||
| <!-- | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="12"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_unit"/> | ||
| </record> | ||
| <record id="product_uom_floz" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="0.0295735"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_litre"/> | ||
| </record> | ||
| <record id="product_uom_foot" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="12"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_inch"/> | ||
| </record> | ||
| <record id="product_uom_gal" model="uom.uom"> | ||
| <!-- | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="4"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_qt"/> | ||
| </record> | ||
| <record id="product_uom_gram" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="1"/> | ||
| </record> | ||
| <record id="product_uom_hour" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="1"/> | ||
| </record> | ||
| <record id="product_uom_inch" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="2.54"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_cm"/> | ||
| </record> | ||
| <record id="product_uom_kgm" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="1000"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_gram"/> | ||
| </record> | ||
| <record id="product_uom_km" model="uom.uom"> | ||
| <!-- | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="1000"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_meter"/> | ||
| </record> | ||
| <record id="product_uom_kwh" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="1.0"/> | ||
| </record> | ||
| <record id="product_uom_lb" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="16"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_oz"/> | ||
| </record> | ||
| <record id="product_uom_litre" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor">1000</field> | ||
| <field name="relative_uom_id" ref="uom.product_uom_milliliter"/> | ||
| </record> | ||
| <record id="product_uom_meter" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="100.0"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_cm"/> | ||
| </record> | ||
| <record id="product_uom_mile" model="uom.uom"> | ||
| <!-- | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="1760"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_yard"/> | ||
| </record> | ||
| <record id="product_uom_millimeter" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="1"/> | ||
| </record> | ||
| <record id="product_uom_minute" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="0.0166667"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_hour"/> | ||
| </record> | ||
| <record id="product_uom_oz" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="28.3495"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_gram"/> | ||
| </record> | ||
| <record id="product_uom_qt" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="32"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_floz"/> | ||
| </record> | ||
| <record id="product_uom_ton" model="uom.uom"> | ||
| <field name="name">Ton</field> | ||
| <field name="relative_factor" eval="1000"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_kgm"/> | ||
| </record> | ||
| <record id="product_uom_unit" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| --> | ||
| <field name="relative_factor" eval="1.0"/> | ||
| </record> | ||
| <record id="product_uom_yard" model="uom.uom"> | ||
| <!-- | ||
| <field name="factor"/> | ||
| <field name="active" eval="False"/> | ||
| --> | ||
| <field name="relative_factor" eval="3"/> | ||
| <field name="relative_uom_id" ref="uom.product_uom_foot"/> | ||
| </record> | ||
| </odoo> |
61 changes: 61 additions & 0 deletions
61
openupgrade_scripts/scripts/uom/19.0.1.0/post-migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Copyright 2025 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def _uom_relative_uom_id_relative_factor(env): | ||
| """ | ||
| UOM categories have been obsoleted, UOMs are a tree now with the reference | ||
| unit as root and relative_factor giving the ratio to the UOM linked in | ||
| relative_uom_id | ||
| """ | ||
|
|
||
| Uom = env["uom.uom"] | ||
|
|
||
| env.cr.execute( | ||
| "SELECT res_id FROM ir_model_data WHERE " | ||
| "model='uom.uom' AND module != '__export__'" | ||
| ) | ||
| with_xml_id = Uom.browse(set(_id for (_id,) in env.cr.fetchall())) | ||
|
|
||
| env.cr.execute( | ||
| f""" | ||
| SELECT | ||
| array_agg(id), | ||
| array_agg({openupgrade.get_legacy_name("factor")}), | ||
| array_agg({openupgrade.get_legacy_name("uom_type")}) | ||
| FROM | ||
| uom_uom | ||
| WHERE {openupgrade.get_legacy_name("category_id")} IS NOT NULL | ||
| GROUP BY {openupgrade.get_legacy_name("category_id")} | ||
| """ | ||
| ) | ||
| for ids, factors, uom_types in env.cr.fetchall(): | ||
| uoms = Uom.browse(ids) | ||
| uom2factor = dict(zip(uoms, factors, strict=True)) | ||
| uom2type = dict(zip(uoms, uom_types, strict=True)) | ||
|
|
||
| old_reference = uoms.filtered( | ||
| lambda x, uom2type=uom2type: uom2type[x] == "reference" | ||
| ) | ||
|
|
||
| for uom in uoms - old_reference - with_xml_id: | ||
| # uoms with xmlid will be updated by the migration of the module | ||
| # providing them | ||
| relative_factor = ( | ||
| uom2factor[uom] if uom2type[uom] == "bigger" else (1 / uom2factor[uom]) | ||
| ) | ||
|
|
||
| uom.write( | ||
| { | ||
| "relative_uom_id": old_reference, | ||
| "relative_factor": relative_factor, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "uom", "19.0.1.0/noupdate_changes_work.xml") | ||
| _uom_relative_uom_id_relative_factor(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright 2025 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.copy_columns( | ||
| env.cr, | ||
| { | ||
| "uom_uom": [ | ||
| ("category_id", None, None), | ||
| ("factor", None, None), | ||
| ("rounding", None, None), | ||
| ("uom_type", None, None), | ||
| ] | ||
| }, | ||
| ) | ||
| openupgrade.rename_xmlids( | ||
| env.cr, | ||
| [ | ||
| ("product.decimal_product_uom", "uom.decimal_product_uom"), | ||
| ("uom.uom_square_foot", "uom.product_uom_square_foot"), | ||
| ("uom.uom_square_meter", "uom.product_uom_square_meter"), | ||
| ], | ||
| ) | ||
| # this would be cleaned up after the migration, but we can't have it during | ||
| # migration | ||
| openupgrade.delete_sql_constraint_safely( | ||
| env, "uom", "uom_uom", "factor_reference_is_one" | ||
| ) |
70 changes: 70 additions & 0 deletions
70
openupgrade_scripts/scripts/uom/19.0.1.0/upgrade_analysis_work.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| ---Models in module 'uom'--- | ||
| obsolete model uom.category | ||
| ---Fields in module 'uom'--- | ||
| uom / uom.category / name (char) : DEL required | ||
| uom / uom.category / reference_uom_id (many2one) : DEL relation: uom.uom, stored: False | ||
| uom / uom.category / uom_ids (one2many) : DEL relation: uom.uom | ||
|
|
||
| # NOTHING TO DO | ||
|
|
||
| uom / uom.uom / _order : _order is now 'sequence, relative_uom_id, id' ('factor DESC, id') | ||
|
|
||
| # NOTHING TO DO | ||
|
|
||
| uom / uom.uom / category_id (many2one) : DEL relation: uom.category, required | ||
|
|
||
| # NOTHING TO DO | ||
|
|
||
| uom / uom.uom / factor (float) : now a function | ||
| uom / uom.uom / parent_path (char) : NEW | ||
| uom / uom.uom / related_uom_ids (one2many) : NEW relation: uom.uom | ||
| uom / uom.uom / relative_factor (float) : NEW required, hasdefault: default | ||
| uom / uom.uom / relative_uom_id (many2one) : NEW relation: uom.uom | ||
|
|
||
| # DONE: compute relative_factor, relative_uom_id for custom UOMs in post-migration | ||
|
|
||
| uom / uom.uom / rounding (float) : not stored anymore | ||
|
|
||
| # DONE: copied to legacy column in pre-migration | ||
|
|
||
| uom / uom.uom / rounding (float) : now a function | ||
| uom / uom.uom / sequence (integer) : NEW hasdefault: compute | ||
|
|
||
| # NOTHING TO DO | ||
|
|
||
| uom / uom.uom / uom_type (selection) : DEL required, selection_keys: ['bigger', 'reference', 'smaller'] | ||
|
|
||
| # DONE: copied to legacy column in pre-migration | ||
|
|
||
| ---XML records in module 'uom'--- | ||
| NEW decimal.precision: uom.decimal_product_uom [renamed from product module] (noupdate) | ||
|
|
||
| # DONE: renamed in pre-migration | ||
|
|
||
| DEL ir.actions.act_window: uom.product_uom_categ_form_action | ||
| DEL ir.model.access: uom.access_uom_category_manager | ||
| DEL ir.model.access: uom.access_uom_category_user | ||
| ir.model.constraint: uom.constraint_uom_uom_factor_gt_zero (changed definition: is now 'CHECK (relative_factor!=0)' ('check(factor!=0)')) | ||
| DEL ir.model.constraint: uom.constraint_uom_uom_factor_reference_is_one | ||
| DEL ir.model.constraint: uom.constraint_uom_uom_rounding_gt_zero | ||
| DEL ir.ui.view: uom.product_uom_categ_form_view | ||
| DEL ir.ui.view: uom.product_uom_categ_tree_view | ||
| DEL ir.ui.view: uom.uom_categ_view_search | ||
| DEL uom.category: uom.product_uom_categ_energy (noupdate) | ||
| DEL uom.category: uom.product_uom_categ_kgm (noupdate) | ||
| DEL uom.category: uom.product_uom_categ_unit (noupdate) | ||
| DEL uom.category: uom.product_uom_categ_vol (noupdate) | ||
| DEL uom.category: uom.uom_categ_length (noupdate) | ||
| DEL uom.category: uom.uom_categ_surface (noupdate) | ||
| DEL uom.category: uom.uom_categ_wtime (noupdate) | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NEW uom.uom: uom.product_uom_milliliter (noupdate) | ||
| NEW uom.uom: uom.product_uom_pack_6 (noupdate) | ||
|
|
||
| # NOTHING TO DO | ||
|
|
||
| NEW uom.uom: uom.product_uom_square_foot (noupdate) | ||
| NEW uom.uom: uom.product_uom_square_meter (noupdate) | ||
| DEL uom.uom: uom.uom_square_foot (noupdate) | ||
| DEL uom.uom: uom.uom_square_meter (noupdate) | ||
|
|
||
| # DONE: renamed in pre-migration | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.