Current behavior:
Creating an SO with negative quantities for a storable product with an
invoicing policy of type "delivered quantities" automatically generates
a return move for the stocks. However, when this delivery is validated,
the delivered quantities are not updated on the SO. This is problematic
as these quantities are therefore not taken into account on the
associated invoice.
Expected behavior:
The delivered quantities should be updated negatively on the SO to
enable the invoicing of these lines.
This is already the behavior in the POS application and when you
create an SO with positive quantities followed by a return
for a larger quantity than the one delivered.
Steps to reproduce:
Create a storable product with an invoicing policy of type "delivered
quantities".
Create an SO with 2 lines:
- a line with positive quantities for any other product.
- a line with negative quantities for the product you created.
Confirm and validate the corresponding deliveries.
Return to the SO. The quantities for the second line are not updated.
Create an invoice. The second line is not taken into account.
Cause of the issue:
The to_refund field of the stock.move model defined in the stock_account
module enables a decrease of the delivered quantities in the associated
Sale Order. This field is set to True for "classic" returns but not for
the stock.move generated from sale.order.line with negative quantities.
Fix:
We rely on the _get_custom_move_fields method to add the to_refund
field in the procurement 'values' arguments in case the stock_account
module is not installed. It is then available to use in the
_get_stock_move_values method where we set its value to True if the
quantity is negative (so that the move should be considered as a refund)
opw-3676045
closesodoo/odoo#154496
X-original-commit: 92917d507a63ee08fc839ed3f7607d5e5060f0a2
Signed-off-by: William Henrotin (whe) <whe@odoo.com>