Skip to content

[IMP] sale_invoice_policy: Several improvements#3376

Merged
OCA-git-bot merged 8 commits intoOCA:16.0from
acsone:16.0-imp-sale-invoice-policy-dro
Mar 17, 2026
Merged

[IMP] sale_invoice_policy: Several improvements#3376
OCA-git-bot merged 8 commits intoOCA:16.0from
acsone:16.0-imp-sale-invoice-policy-dro

Conversation

@rousseldenis
Copy link
Copy Markdown
Contributor

@rousseldenis rousseldenis commented Oct 24, 2024

  • Don't use the required parameter to compute the quantity to invoice
  • Simplify depends()
  • Don't use the required parameter to compute the untaxed amount to invoice
  • Don't rewrite the Odoo core compute method
  • Improve README

Refactor:

I think the default policy that was applied on sale orders from the default product configuration (defined in sale module) was the wrong approach as it is not contextually correct (products are not sale orders).

That said, I introduced an invoice policy on sale order level more explicitly than before (void) which is 'Products Invoicing Policy'. That let the user free to choose between standard behavior or sale order level configuration.

The question is:

  • As the required attribute was used before means that the sale order invoicing policy should not use the product configurations. Should we reintroduce that behavior (to constrain sale orders to NOT use product configuration at all ?) ? @ioans73 @fuentes73 @sergio-teruel @ACheung-FactorLibre @Cedric-Pigeon @acsonefho

@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch 2 times, most recently from fb39a75 to 7b26e33 Compare October 24, 2024 11:00
@rousseldenis rousseldenis added this to the 16.0 milestone Oct 24, 2024
@rousseldenis
Copy link
Copy Markdown
Contributor Author

Don't hesitate to test it on runboat

@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch from 655eb48 to f4ea1a1 Compare October 25, 2024 08:13
@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch from f4ea1a1 to dd6f488 Compare October 25, 2024 13:19
@rousseldenis rousseldenis marked this pull request as ready for review October 25, 2024 16:03
@rousseldenis rousseldenis requested a review from lmignon October 25, 2024 16:05
Copy link
Copy Markdown
Contributor

@ferran-S73 ferran-S73 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 OK. As per your question I see no problem in allowing product configuration for sale orders' invoice policy. It adds more flexibility to the module

Copy link
Copy Markdown

@phschmidt phschmidt left a comment

Choose a reason for hiding this comment

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

Functionary review

Copy link
Copy Markdown
Contributor

@marielejeune marielejeune left a comment

Choose a reason for hiding this comment

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

LGTM (code + functional review)
Thanks for the work

@anajuaristi
Copy link
Copy Markdown

Don't hesitate to test it on runboat

Hello @rousseldenis
I was trying to test in runboat but I can´t find or see the build for this PR. Could you help me with that please?

Thank you!!!

Copy link
Copy Markdown
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

Can you add in the readme that the SO invoice policy affects only stock products. Service products continue to be invoiced based on the product invoice policy.

Copy link
Copy Markdown
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

And generate requirement.txt as it is not part of it in this repo

2025-01-25 16:00:20,521 417 INFO odoo odoo.modules.loading: Loading module sale_invoice_policy (66/67) 
2025-01-25 16:00:20,522 417 CRITICAL odoo odoo.modules.module: Couldn't load module sale_invoice_policy 
2025-01-25 16:00:20,522 417 CRITICAL odoo odoo.modules.module: No module named 'openupgradelib' 

@marielejeune
Copy link
Copy Markdown
Contributor

@rousseldenis Could you have a look at the last reviews please?

@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch from dd6f488 to f734e36 Compare May 30, 2025 09:27
Don't use the 'required' parameter to compute the quantities to invoice or not.
In fact, this should only depends on the invoice policy itself.
As ORM appends new depends() parameters to existing ones, simplify the writing
…he amount

As for the 'qty_to_invoice' field, the 'untaxed_amount_to_invoice' field should not
depends on the required option to compute its value
As we don't want to rewrite Odoo core method inside this module, we
should not rewrite the method to compute the untaxed amount to invoice.

Instead, save the product invoice policy, change it to sale order one without
recomputing context, call the super() method and then, restore its former value.
@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch 2 times, most recently from 86ca255 to a24b407 Compare May 30, 2025 09:33
@rousseldenis
Copy link
Copy Markdown
Contributor Author

@jbaudoux Could you update your review ?

…olicy

With default behavior in Odoo, the invoicing policy depends on products configuration.
So, include this as possible value for sale order invoicing policy. Possible values are so:

  - Products Invoice Policy: each product applies its invoicing policy (by sale line)
  - Ordered quantities: the whole sale order will apply the invoicing policy on ordered quantities
  - Delivered Quantities: the whole sale order will apply the invoicing policy on delivered quantities

That said, the 'required' configuration is no more useful as the invoicing policy is now required
on sale order level.
…ecompute()

To avoid marking 'invoice_policy' product field as dirty for products temporary value,
use the working context manager 'protecting()' instead of deprecated 'norecompute() one.

Put the whole process in its own contextmanager.
@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch from a24b407 to f707990 Compare May 30, 2025 09:40
Copy link
Copy Markdown
Member

@hildickethan hildickethan left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Copy Markdown
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

Can you drop auto-generated files from the commits?

Copy link
Copy Markdown

@alexey-pelykh alexey-pelykh left a comment

Choose a reason for hiding this comment

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

Thanks for the refactor Denis, the move to a proper three-valued selection with "product" as a default is a much cleaner design than the old invoice_policy_required boolean approach. The delegation to Odoo core in _compute_untaxed_amount_to_invoice instead of reimplementing the whole calculation is a welcome simplification too.

A few things I noticed:

There is a copy-paste typo in readme/CONTEXT.rst (and consequently in the generated README.rst and index.html) -- the two bullet points both say "Invoicing on ordered quantities". The second one should be "Invoicing on delivered quantities".

In _sale_invoice_policy, a bare Exception is raised when called with mixed policies. Using ValueError (or UserError if the intent is to surface this to the UI) would be more conventional.

As @jbaudoux mentioned in his last review, the auto-generated files (README.rst, static/description/index.html) should be dropped from the commits. OCA CI regenerates them.

One note on the context manager pattern: the env.protecting + temporary product field patching approach is clever, but it does mean that if an exception occurs between setting the new values and the yield, the old values would not be restored. In practice this seems unlikely to cause issues since any such exception would typically roll back the transaction, but worth being aware of.

Otherwise the implementation looks solid -- pre_init_hook with openupgradelib for the migration, the company-level default, tests covering both policy paths and the context manager guard. Nice work.

@rousseldenis
Copy link
Copy Markdown
Contributor Author

/ocabot merge major

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-3376-by-rousseldenis-bump-major, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit dcc7cde into OCA:16.0 Mar 17, 2026
12 of 13 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 05c66dc. Thanks a lot for contributing to OCA. ❤️

amarcosg added a commit to factorlibre/sale-workflow that referenced this pull request Mar 17, 2026
This reverts commit dcc7cde, reversing
changes made to bd8ce5c.
@acsonefho acsonefho deleted the 16.0-imp-sale-invoice-policy-dro branch March 18, 2026 06:24
ljsalvatierra-factorlibre added a commit to factorlibre/sale-workflow that referenced this pull request Mar 18, 2026
This reverts commit dcc7cde, reversing
changes made to bd8ce5c.
ljsalvatierra-factorlibre added a commit to factorlibre/sale-workflow that referenced this pull request Mar 23, 2026
This reverts commit dcc7cde, reversing
changes made to bd8ce5c.
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.

10 participants