Skip to content

[19.0][FIX] stock_account: product.value and stock.valuation.layer have different semantics - #5881

Open
hbrunn wants to merge 84 commits into
OCA:19.0from
hbrunn:19.0-stock_account-fix-product.value
Open

[19.0][FIX] stock_account: product.value and stock.valuation.layer have different semantics#5881
hbrunn wants to merge 84 commits into
OCA:19.0from
hbrunn:19.0-stock_account-fix-product.value

Conversation

@hbrunn

@hbrunn hbrunn commented Aug 4, 2026

Copy link
Copy Markdown
Member

this deals with the issue hinted at in #5855

hbrunn and others added 30 commits July 28, 2026 15:31
[19.0][MIG] auth_passkey_portal: nothing to do
[19.0][MIG] project_hr_skills: nothing to do
[19.0][MIG] hr_skills_event: nothing to do
[19.0][OU-ADD] mail_plugin: Nothing to do
[19.0][OU-ADD] crm_mail_plugin: Nothing to do
[19.0][MIG] website_sale_stock: nothing to do
[19.0][MIG] website_sale_slides: nothing to do
[19.0][OU-ADD] theme_default: Nothing to do
[19.0][OU-ADD] crm_sms: Nothing to do
…lrelay

[19.0][OU-ADD] delivery_mondialrelay: Nothing to do
…list

[19.0][MIG] website_sale_wishlist: nothing to do
pedrobaeza and others added 15 commits August 10, 2026 17:51
…_forum

[19.0][OU-ADD] website_slides_forum: Nothing to do
…ation on PostgreSQL 13

stock_move_value() in stock_account/19.0.1.1/post-migration.py builds an
UPDATE ... FROM (SELECT ... sum(value) value ...) aggregate subquery with
a bare-word column alias (no AS) immediately after the aggregate call.

PostgreSQL 13 rejects this as a syntax error:

    ERROR:  syntax error at or near "value"
    LINE 5:     move_id, sum(value) value
                                    ^

PostgreSQL 16 accepts the same statement, which is why this is easy to
miss when re-testing on a newer engine — it is PostgreSQL-version
dependent, not data-dependent. Any 18.0 -> 19.0 migration of a database
with stock_account installed, run against a PostgreSQL 13 backend, hits
this unconditionally partway through the post-migration step.

Fix: alias the aggregate column explicitly (agg_value) and reference the
aliased name in the outer UPDATE ... SET, instead of relying on the bare
column name colliding with the outer table's own value column.

Found and reproduced during a real 15.0 -> 19.0 OpenUpgrade migration
(PostgreSQL 13 source engine). Confirmed the exact failing statement
against a live PostgreSQL 13.23 database inside a BEGIN;...ROLLBACK; and
confirmed the patched statement runs clean against the same database.
…t-migration-value-alias

[19.0][FIX] stock_account: fix syntax error in stock_move_value() post-migration on PostgreSQL 13
[19.0][OU-ADD] payment_paypal: Nothing to do
Doing it by ORM is not advised due to performance, but also because some
business constraints can be triggered, like in this case
`_check_can_approve`, provoking a crash in the migration.

There's also a problem in executing it in post-migration instead of
end-migration: if the extra modules changing
`_get_invoice_in_payment_state` are not yet loaded, you won't get
`in_payment` state, so the logic has been converted to SQL, and move to
end-migration.

TT61992
[19.0][OU-FIX] hr_expense: Compute expense state by SQL
In odoo/odoo@72fffca,
Odoo has changed the preference of the routes to warehouse level, but
on migrated DBs, there may be more than one warehouse, and the check
is not set for all the warehouses right now.

Although this can be done in migration scripts, it's safer to simply
keep it as it was, because when you have both Buy/Manufacture, there
will be a change of behavior, selecting by priority the incorrect route.

TT61992
…ner_assign

[MIG] website_crm_partner_assign
[19.0][OU-FIX] mrp/purchase_stock: Don't change routes configuration
Signed-off-by hbrunn
Signed-off-by hbrunn
@hbrunn
hbrunn force-pushed the 19.0-stock_account-fix-product.value branch 2 times, most recently from ad5ba2c to 86e52c4 Compare August 18, 2026 17:19
@hbrunn
hbrunn marked this pull request as ready for review August 18, 2026 17:21
@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

BTW, is this PR ready to review and merge?

"""
Set stock.move#value to sum of product.value#value for this move
"""
env.cr.execute(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logging

Set stock.location#valuation_account_id from valuation_in_account_id and
valuation_out_account_id if they are the same
"""
env.cr.execute(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logging

(=manual valuations)
"""
# simple case: the valuation layer has unit_cost set
openupgrade.logged_query(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, better env.cr.execute here, sorry

@hbrunn

hbrunn commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

I forgot some details like lifting constraints on the svl table and linking product_value records to the svl they come from, but by and large, that's what I think should happen

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

@hbrunn please, rebase. I made an error when force pushing to 19.0 (it's already amended)

@hbrunn

hbrunn commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

why is anyone allowed to force push in the first place?

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

I have just removed the force push permissions.

@hbrunn

hbrunn commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

https://github.com/OCA/OpenUpgrade/settings/branch_protection_rules/5942394 looked like this:

image

I've changed that to

image

@MiquelRForgeFlow

MiquelRForgeFlow commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The option was marked in "Specify who can force push". I only removed the people there. So I suppose that when the list of people there is empty, github changes it to Everyone.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.