Skip to content

Conversation

@sergio-teruel
Copy link
Contributor

@sergio-teruel sergio-teruel force-pushed the 15.0-FIX-purchase_order_secondary_unit-non-default-sec-uom-variant branch from 9609dfd to e08e853 Compare November 3, 2025 20:49
Copy link
Contributor

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Comment on lines 9 to 23
# Set default purchase secondary uom from template to variants
# Step 1: For templates with >1 variants, nullify purchase_secondary_uom_id
sql = """
WITH multi AS (
SELECT product_tmpl_id AS id
FROM product_product
GROUP BY product_tmpl_id
HAVING COUNT(*) > 1
)
UPDATE product_template pt
SET purchase_secondary_uom_id = NULL
FROM multi
WHERE pt.id = multi.id
AND pt.purchase_secondary_uom_id IS NOT NULL;
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the compute, you consider that a template can have more than one variant, but if all variants have the same purchase_secondary_uom_id, it should be set on the template. Why didn’t you consider this case in the migration script?

Comment on lines 27 to 42
sql = """
WITH single AS (
SELECT product_tmpl_id AS id
FROM product_product
GROUP BY product_tmpl_id
HAVING COUNT(*) = 1
)
UPDATE product_product pp
SET purchase_secondary_uom_id = pt.purchase_secondary_uom_id
FROM product_template pt
JOIN single s ON s.id = pt.id
WHERE pp.product_tmpl_id = pt.id
AND pt.purchase_secondary_uom_id IS NOT NULL
-- avoid writing unchanged rows
AND COALESCE(pp.purchase_secondary_uom_id, 0) <> pt.purchase_secondary_uom_id;
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you consider the case mentioned above and later set null on templates with more than a single variant, I think the remaining cases don’t require a complex query, because the remaining records have a single variant. So, the UPDATE can be done directly without the WITH clause.

@sergio-teruel sergio-teruel force-pushed the 15.0-FIX-purchase_order_secondary_unit-non-default-sec-uom-variant branch from e08e853 to d63f98f Compare November 4, 2025 15:34
@sergio-teruel
Copy link
Contributor Author

@carlos-lopez-tecnativa changes done!! Finally I have used orm

Copy link
Contributor

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the improvement. Please forward-port to the upper versions.

@pedrobaeza pedrobaeza added this to the 15.0 milestone Nov 5, 2025
help="In order to set a value, please first add at least one record"
" in 'Secondary Unit of Measure'",
domain="[('product_tmpl_id', '=', id), ('product_id', '=', False)]",
store=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why being stored if it has inverse?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants