diff --git a/sale_unreconciled/models/sale_order.py b/sale_unreconciled/models/sale_order.py index 4297640dc2c2..13a3df86d5ee 100644 --- a/sale_unreconciled/models/sale_order.py +++ b/sale_unreconciled/models/sale_order.py @@ -3,6 +3,7 @@ from odoo import _, api, exceptions, fields, models from odoo.osv import expression +from odoo.tools import float_is_zero class SaleOrder(models.Model): @@ -140,19 +141,32 @@ def action_reconcile(self): and l.currency_id.id == currency_id ) ) - if main_product: - # If kit, use the product of the kit - product_id = main_product.id - writeoff_vals = self._get_sale_writeoff_vals( - sale_line_id, currency_id, product_id + currency = ( + self.env["res.currency"].browse(currency_id) + if currency_id + else self.company_id.currency_id ) - if unreconciled_items_group: - writeoff_to_reconcile = unreconciled_items_group._create_writeoff( - [writeoff_vals] + if float_is_zero( + sum(unreconciled_items_group.mapped("amount_residual")), + precision_rounding=currency.rounding, + ): + moves_to_reconcile = unreconciled_items_group + else: + if main_product: + # If kit, use the product of the kit + product_id = main_product.id + writeoff_vals = self._get_sale_writeoff_vals( + sale_line_id, currency_id, product_id ) - all_writeoffs |= writeoff_to_reconcile - # add writeoff line to reconcile algorithm and finish the reconciliation - moves_to_reconcile = unreconciled_items_group | writeoff_to_reconcile + if unreconciled_items_group: + writeoff_to_reconcile = unreconciled_items_group._create_writeoff( + [writeoff_vals] + ) + all_writeoffs |= writeoff_to_reconcile + # add writeoff line to reconcile algorithm and finish the reconciliation + moves_to_reconcile = ( + unreconciled_items_group | writeoff_to_reconcile + ) # Check if reconciliation is total or needs an exchange rate entry to be # created if moves_to_reconcile: