Skip to content

Commit

Permalink
[IMP] sale_unreconciled: reconcile by groups
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Feb 21, 2023
1 parent a5a89b4 commit 4b0d9aa
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions sale_unreconciled/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4b0d9aa

Please sign in to comment.