Skip to content

[18.0][FIX] sale_order_type: preserve manual payment term when changing inv…#4273

Open
lef-adhoc wants to merge 1 commit into
OCA:18.0from
adhoc-dev:18.0-h-113410-lef
Open

[18.0][FIX] sale_order_type: preserve manual payment term when changing inv…#4273
lef-adhoc wants to merge 1 commit into
OCA:18.0from
adhoc-dev:18.0-h-113410-lef

Conversation

@lef-adhoc
Copy link
Copy Markdown
Contributor

…oice journal

When a sale type has no payment_term_id and the user sets a manual term on the sale order, changing the invoice journal triggered a recompute chain (journal_id → company_id → sale_type_id) that caused super() to silently reset invoice_payment_term_id to the partner's default.

Skip the super() call for records where neither the partner nor the sale type changed and the sale type carries no term, so the chosen term is kept. Adds a regression test covering this scenario.

@lef-adhoc lef-adhoc changed the title [FIX] sale_order_type: preserve manual payment term when changing inv… [18.0][FIX] sale_order_type: preserve manual payment term when changing inv… Apr 14, 2026
@lef-adhoc lef-adhoc force-pushed the 18.0-h-113410-lef branch 4 times, most recently from 99cb973 to 3bd8e78 Compare April 14, 2026 23:28
Copy link
Copy Markdown
Member

@flotho flotho 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
LGTM

@lef-adhoc lef-adhoc force-pushed the 18.0-h-113410-lef branch 7 times, most recently from d6989a8 to 6d7ad4e Compare April 16, 2026 01:34
…oice journal

When a sale type has no payment_term_id and the user sets a manual term
on the sale order, changing the invoice journal triggered a recompute
chain (journal_id → company_id → sale_type_id) that caused super() to
silently reset invoice_payment_term_id to the partner's default.

Skip the super() call for records where neither the partner nor the sale
type changed and the sale type carries no term, so the chosen term is
kept. Adds a regression test covering this scenario.
@lef-adhoc
Copy link
Copy Markdown
Contributor Author

Hi @pedrobaeza, what do you think about this?

@pedrobaeza pedrobaeza added this to the 18.0 milestone Apr 16, 2026
pedrobaeza

This comment was marked as outdated.

@pedrobaeza
Copy link
Copy Markdown
Member

EDIT: Seeing that it's on moves, not orders. Trying again.

@pedrobaeza
Copy link
Copy Markdown
Member

Still no luck...

Peek 16-04-2026 08-22

@lef-adhoc
Copy link
Copy Markdown
Contributor Author

@pedrobaeza Here's a video showing it running on Runboat
https://drive.google.com/file/d/14XV3Vg_VUSRmaDPEtHt-MHmaSL4x6xvQ/view?usp=sharing

@pedrobaeza
Copy link
Copy Markdown
Member

But that's not because of sale_order_type, but the standard that restores the SO payment term.

@lef-adhoc
Copy link
Copy Markdown
Contributor Author

lef-adhoc commented Apr 16, 2026

@pedrobaeza If you delete the _compute_invoice_payment_term_id method from the sale_order_type, you’ll see that the payment term isn’t updated when you update the journal. You can test this in Odoo’s Runbot.

Comment on lines +51 to +57
for move in self:
if move.sale_type_id.payment_term_id:
move.invoice_payment_term_id = move.sale_type_id.payment_term_id
else:
previous_term = previous.get(move)
if previous_term:
move.invoice_payment_term_id = previous_term
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For me, the code should be:

Suggested change
for move in self:
if move.sale_type_id.payment_term_id:
move.invoice_payment_term_id = move.sale_type_id.payment_term_id
else:
previous_term = previous.get(move)
if previous_term:
move.invoice_payment_term_id = previous_term
for move in self:
if not move.invoice_payment_term_id and move.sale_type_id.payment_term_id:
move.invoice_payment_term_id = move.sale_type_id.payment_term_id

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this wouldn't solve the issue that motivated the PR.

In this case, after super(), invoice_payment_term_id is already filled with the partner payment term, so your condition would not apply and the manual value would still be lost.

It would also change the current behavior of the module, because sale_order_type would stop overriding the computed payment term and would only act as a fallback when the field is empty.

Copy link
Copy Markdown

@nicolascol nicolascol left a comment

Choose a reason for hiding this comment

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

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