Skip to content
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

[IMP] sale_invoice_policy: Several improvements #3376

Open
wants to merge 8 commits into
base: 16.0
Choose a base branch
from

Conversation

rousseldenis
Copy link
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:

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
@rousseldenis rousseldenis force-pushed the 16.0-imp-sale-invoice-policy-dro branch from fb39a75 to 7b26e33 Compare October 24, 2024 11:00
…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 added this to the 16.0 milestone Oct 24, 2024
…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.
@rousseldenis
Copy link
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
…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 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
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

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

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
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.

Comment on lines 23 to 26
help="Ordered Quantity: Invoice based on the quantity the customer "
"ordered.\n"
"Delivered Quantity: Invoiced based on the quantity the vendor "
"delivered (time or deliveries).",
Copy link
Contributor

Choose a reason for hiding this comment

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

Add that is applies only for stock products

Copy link
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' 

"data": [
"views/res_config_settings_view.xml",
"views/sale_view.xml",
],
"pre_init_hook": "pre_init_hook",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"pre_init_hook": "pre_init_hook",
"pre_init_hook": "pre_init_hook",
"external_dependencies": {"python": ["openupgradelib"]},

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.

7 participants