[FIX] sale_stock_product_pack: Add pack lines to invoices when compon…#242
[FIX] sale_stock_product_pack: Add pack lines to invoices when compon…#242matiasperalta1 wants to merge 1 commit intoOCA:18.0from
Conversation
|
Hi @pedrobaeza, |
f1ee766 to
2c90295
Compare
There was a problem hiding this comment.
Pull request overview
Fixes refund/credit-note generation for pack products so that pack parent lines (and their price) are included when components are returned, even when the parent has no stock moves.
Changes:
- Override
sale.order._get_invoiceable_linesto inject pack parent lines when component lines are being invoiced/refunded. - Override
sale.order.line._prepare_invoice_lineto compute pack parent refund quantities from returned component quantities. - Move/restore pack delivered quantity computation onto
sale.order.line(and register the new model file).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
sale_stock_product_pack/models/sale_order.py |
Adds invoiceable-lines override to include pack parents during refunds/returns. |
sale_stock_product_pack/models/sale_order_line.py |
Adds pack qty delivered computation and adjusts invoice line quantity for pack-parent refunds. |
sale_stock_product_pack/models/__init__.py |
Ensures the new sale_order_line model override is loaded. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if components_being_returned and res.get('quantity', 0) == 0: | ||
| refund_quantities = [] | ||
| for comp in components_being_returned: | ||
| qty_per_pack = comp.product_uom_qty / self.product_uom_qty if self.product_uom_qty else 0 |
There was a problem hiding this comment.
This line exceeds the configured line-length limit (ruff E501) and is hard to read/maintain. Please split the conditional expression across multiple lines (or assign intermediate variables) so formatting/linting passes.
| qty_per_pack = comp.product_uom_qty / self.product_uom_qty if self.product_uom_qty else 0 | |
| if self.product_uom_qty: | |
| qty_per_pack = ( | |
| comp.product_uom_qty / self.product_uom_qty | |
| ) | |
| else: | |
| qty_per_pack = 0 |
| def _get_invoiceable_lines(self, final=False): | ||
| """Override to ensure pack parent lines are included when their | ||
| components are being invoiced/refunded. | ||
|
|
||
| When processing returns, only component lines have stock moves, so only | ||
| they would be included in the refund. This method ensures that if pack | ||
| component lines are invoiceable (due to returns), their parent pack line | ||
| is also included if it has a price. | ||
| """ | ||
| lines = super()._get_invoiceable_lines(final=final) |
There was a problem hiding this comment.
New return/refund invoicing behavior is introduced here (injecting pack parent lines when components are refunded), but there are no tests covering the credit note/invoice line output. Please add a test that performs: deliver a pack, invoice it, process a return on components, create the refund, and assert the resulting credit note includes the pack parent line with the expected quantity/amount.
| _inherit = "sale.order.line" | ||
|
|
||
| def _compute_qty_delivered(self): | ||
| """Compute pack delivered pack quantites according to its components |
There was a problem hiding this comment.
Docstring typo: "quantites" should be "quantities".
| """Compute pack delivered pack quantites according to its components | |
| """Compute pack delivered pack quantities according to its components |
…ents are returned
2c90295 to
1f76dd8
Compare
…ents are returned
When processing returns with pack products (detailed/ignored, no stock moves), only component lines were included in credit notes, missing the pack parent line with its price. Override _get_invoiceable_lines to detect returns and include pack parents, and _prepare_invoice_line to calculate correct refund quantities based on returned components.