Skip to content

[FIX] sale_stock_product_pack: Add pack lines to invoices when compon…#242

Closed
matiasperalta1 wants to merge 1 commit intoOCA:18.0from
adhoc-dev:18.0-h-108957-mnp
Closed

[FIX] sale_stock_product_pack: Add pack lines to invoices when compon…#242
matiasperalta1 wants to merge 1 commit intoOCA:18.0from
adhoc-dev:18.0-h-108957-mnp

Conversation

@matiasperalta1
Copy link

@matiasperalta1 matiasperalta1 commented Feb 9, 2026

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

Copilot AI review requested due to automatic review settings February 9, 2026 20:33
@OCA-git-bot
Copy link
Contributor

Hi @pedrobaeza,
some modules you are maintaining are being modified, check this out!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_lines to inject pack parent lines when component lines are being invoiced/refunded.
  • Override sale.order.line._prepare_invoice_line to 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
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +19
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)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
_inherit = "sale.order.line"

def _compute_qty_delivered(self):
"""Compute pack delivered pack quantites according to its components
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Docstring typo: "quantites" should be "quantities".

Suggested change
"""Compute pack delivered pack quantites according to its components
"""Compute pack delivered pack quantities according to its components

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants