[IMP] sale_invoice_policy: Services qty to invoice calculation#3956
[IMP] sale_invoice_policy: Services qty to invoice calculation#3956
Conversation
| other_lines = self.filtered( | ||
| lambda l: l.product_id.type == "service" | ||
| or not l.order_id.invoice_policy | ||
| lambda l: not l.order_id.invoice_policy |
There was a problem hiding this comment.
From reading previous PRs adding this condition, it seems like ignoring services so that they're handled with their product config is intended behaviour. Mostly likely because depending on your setup, you might be using service_policy from sale_project for services and it's easier to just let the product handle it.
I think it'll be a hard sell to get this merged, if you need it I suggest extracting the condition to a function and modifying it in your personal repo.
In any case you would also need to adapt _compute_untaxed_amount_to_invoice as well
alexey-pelykh
left a comment
There was a problem hiding this comment.
Thank you for the contribution. The bug report is well-documented with screenshots showing the inconsistency between service and non-service lines. However, the change as implemented has gaps that should be addressed before this can be merged.
Key findings:
-
Incomplete fix —
_compute_untaxed_amount_to_invoicenot updated (blocking)
As @hildickethan already flagged, the sameproduct_id.type == "service"exclusion remains in_compute_untaxed_amount_to_invoice(line 43). Removing it from_compute_qty_to_invoicealone creates a new inconsistency:qty_to_invoicewill reflect the order-level policy for services, butuntaxed_amount_to_invoicewill not. Both computed fields need to be aligned. -
No test coverage for the fixed scenario (blocking)
The test class createsproduct3as a service product insetUpClassbut never uses it in any test. This PR should add a test that places a service product on an order with an explicitinvoice_policy, confirms the order, and asserts thatqty_to_invoiceanduntaxed_amount_to_invoiceon the service line respect the order-level policy rather than the product-level one. -
Behavioral risk — interaction with
sale_project/service_policy
The original service exclusion was intentional: it allows standard Odoo service invoicing logic (andsale_project'sservice_policyfield) to govern services independently. Removing it meanssale_invoice_policywill now override the product-level behavior for all product types when the order policy is set. Consider whether this should be opt-in (e.g. a config flag) or whether the PR description should explicitly acknowledge this trade-off so maintainers can make an informed decision.
CI is green (all 14 checks pass). The direction of the fix makes sense for the reported use case, but please address the consistency gap and add tests before this is ready for merge.
| other_lines = self.filtered( | ||
| lambda l: l.product_id.type == "service" | ||
| or not l.order_id.invoice_policy | ||
| lambda l: not l.order_id.invoice_policy |
There was a problem hiding this comment.
Removing the service exclusion here is consistent with the stated goal, but the same condition (line.product_id.type == "service") still exists in _compute_untaxed_amount_to_invoice (line 43 of the same file). These two computed fields must stay aligned — otherwise qty_to_invoice will use the order policy for services but untaxed_amount_to_invoice will not, creating a different inconsistency than the one being fixed.
6316ff5 to
f30fe5c
Compare
alexey-pelykh
left a comment
There was a problem hiding this comment.
Thank you for the significant rework (removing base_partition, openupgradelib, and the pre_init_hook). The simplification is welcome.
However, the two blocking issues from my previous review remain:
-
_compute_untaxed_amount_to_invoicestill excludes services. Theproduct_id.type == "service"condition is still in theother_linesfilter for the amount computation, while it has been removed from_compute_qty_to_invoice. This creates an inconsistency —qty_to_invoicerespects the order-level policy for services, butuntaxed_amount_to_invoicedoes not. -
No test for the service product scenario.
product3(service type) is created insetUpClassbut never used in any test. Please add a test that places a service product on an order with an explicitinvoice_policyand asserts bothqty_to_invoiceanduntaxed_amount_to_invoice.
Co-Reviewed-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
283bc95 to
2ac0b84
Compare
Module
sale_invoice_policy
Describe the bug
The calculation of the quantity to invoice for service is different compared to other types of products, with an invoicing policy based on delivered quantities in the order and ordered quantities in the product.
This causes inconsistencies between the order and its lines and the generation of unwanted invoices.
To Reproduce
(image from runboat OCA)
With this change, the calculation of quantity to invoice is always based on the invoice policy of the order in case it is filled and the configuration of "Sale Invoice Policy" is checked.
Affected versions:
16.0