Skip to content

Commit

Permalink
[IMP] Enhanced get agent lines filter by payment
Browse files Browse the repository at this point in the history
  • Loading branch information
stenext committed Sep 19, 2023
1 parent a83f29b commit 1a6f3a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
13 changes: 13 additions & 0 deletions sale_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,16 @@ def _skip_settlement(self):
self.commission_id.invoice_state == "paid"
and self.invoice_id.payment_state not in ["in_payment", "paid"]
) or self.invoice_id.state != "posted"

def _skip_future_payments(self, date_payment_to):
if self.commission_id.invoice_state == "paid":
payments_dates = []
for (
_partial,
_amount,
counterpart_line,
) in self.invoice_id._get_reconciled_invoices_partials():
payments_dates.append(counterpart_line.date)
if any(date_payment_to < date for date in payments_dates):
return True
return False
26 changes: 5 additions & 21 deletions sale_commission/wizard/wizard_settle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2014-2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json
from datetime import date, datetime
from datetime import date

from dateutil.relativedelta import relativedelta

Expand Down Expand Up @@ -102,6 +101,10 @@ def action_settle(self):
pos += 1
if line._skip_settlement():
continue
if self.date_payment_to and line._skip_future_payments(
self.date_payment_to
):
continue
if line.invoice_date > sett_to:
sett_from = self._get_period_start(agent, line.invoice_date)
sett_to = self._get_next_period_date(
Expand Down Expand Up @@ -143,23 +146,4 @@ def _get_agent_lines(self, agent, date_to_agent):
],
order="invoice_date",
)
if self.date_payment_to:
aila = aila.filtered(
lambda line: not (
line.commission_id.invoice_state == "paid"
and line.invoice_id.invoice_payments_widget != "false"
and not self.check_payment_date(line)
)
)
return aila

def check_payment_date(self, agent_line):
move_dict_content = json.loads(agent_line.invoice_id.invoice_payments_widget)[
"content"
]
return all(
[
self.date_payment_to > datetime.strptime(x["date"], "%Y-%m-%d").date()
for x in move_dict_content
]
)

0 comments on commit 1a6f3a4

Please sign in to comment.