changeset b759822ca43c in modules/sale_payment:default
details:
https://hg.tryton.org/modules/sale_payment?cmd=changeset&node=b759822ca43c
description:
Check against credit limit unpaid amount of the sale
issue11229
review395461002
diffstat:
sale.py | 19 ++++++++++++++++---
tryton.cfg | 1 +
2 files changed, 17 insertions(+), 3 deletions(-)
diffs (46 lines):
diff -r 4d5907ef3457 -r b759822ca43c sale.py
--- a/sale.py Thu Jan 20 19:07:43 2022 +0100
+++ b/sale.py Sun Mar 06 18:20:38 2022 +0100
@@ -64,15 +64,28 @@
default.setdefault('payments', None)
return super(Sale, cls).copy(sales, default=default)
+ @property
+ def payment_amount_authorized(self):
+ "Total amount of the authorized payments"
+ return sum(p.amount for p in self.payments if p.is_authorized)
+
+ @property
+ def amount_to_pay(self):
+ "Amount to pay to confirm the sale"
+ return self.total_amount
+
@classmethod
def payment_confirm(cls, sales):
"Confirm the sale based on payment authorization"
to_confirm = []
for sale in sales:
- payment_amount = sum(
- p.amount for p in sale.payments if p.is_authorized)
- if payment_amount >= sale.total_amount:
+ if sale.payment_amount_authorized >= sale.amount_to_pay:
to_confirm.append(sale)
if to_confirm:
to_confirm = cls.browse(to_confirm) # optimize cache
cls.confirm(to_confirm)
+
+ @property
+ def credit_limit_amount(self):
+ amount = super().credit_limit_amount
+ return max(0, amount - self.payment_amount_authorized)
diff -r 4d5907ef3457 -r b759822ca43c tryton.cfg
--- a/tryton.cfg Thu Jan 20 19:07:43 2022 +0100
+++ b/tryton.cfg Sun Mar 06 18:20:38 2022 +0100
@@ -8,6 +8,7 @@
sale
extras_depend:
account_payment_clearing
+ sale_credit_limit
xml:
sale.xml
message.xml