Skip to content

[16.0][sale_advance_payment] Incorrect amount_residual in sales orders with refund invoices #3975

@kikopeiro

Description

@kikopeiro

Module

sale_advance_payment

Describe the bug

The amount_residual field in sales orders shows an incorrect value when there are refund invoices (credit notes) associated with the order. This happens because the current calculation doesn't properly handle the sign of refund invoices.

To Reproduce

Affected versions: 16.0

Steps to reproduce the behavior:

  1. Create a sales order
  2. Confirm the order and create the customer invoice
  3. Post the invoice
  4. Ceate a refund invoice (credit note)
  5. Post the refund invoice
  6. Check the amount_residual field in the sales order

Expected behavior

The amount_residual should correctly reflect the actual pending amount, properly accounting for both the original invoice and the refund invoice with their corresponding signs.

Additional context

The issue appears to be in the computation logic at: https://github.com/OCA/sale-workflow/blob/16.0/sale_advance_payment/models/sale.py#L57

The calculation should use amount_residual_signed instead of amount_residual to properly handle the sign of refund invoices.

Example runboat scenario:

Image Image

Related PR: #3863

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions