changeset f41b373f8418 in modules/sale_payment:default
details:
https://hg.tryton.org/modules/sale_payment?cmd=changeset;node=f41b373f8418
description:
Fill payment with sale data
issue9244
review293551002
diffstat:
CHANGELOG | 2 ++
account.py | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diffs (49 lines):
diff -r 7bb39d5d805c -r f41b373f8418 CHANGELOG
--- a/CHANGELOG Mon May 04 12:27:19 2020 +0200
+++ b/CHANGELOG Fri May 22 11:54:05 2020 +0200
@@ -1,3 +1,5 @@
+* Fill payment with sale data
+
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
diff -r 7bb39d5d805c -r f41b373f8418 account.py
--- a/account.py Mon May 04 12:27:19 2020 +0200
+++ b/account.py Fri May 22 11:54:05 2020 +0200
@@ -1,8 +1,10 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import functools
+from decimal import Decimal
from trytond.i18n import gettext
+from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.modules.account_payment.exceptions import PaymentValidationError
@@ -32,6 +34,25 @@
def _get_origin(cls):
return super(Payment, cls)._get_origin() + ['sale.sale']
+ @fields.depends('origin')
+ def on_change_origin(self):
+ pool = Pool()
+ Sale = pool.get('sale.sale')
+ try:
+ super().on_change_origin()
+ except AttributeError:
+ pass
+ if self.origin and isinstance(self.origin, Sale):
+ sale = self.origin
+ self.party = sale.invoice_party or sale.party
+ sale_amount = sale.total_amount
+ self.kind = 'receivable' if sale_amount > 0 else 'payable'
+ payment_amount = sum(
+ (p.amount for p in sale.payments if p.state != 'failed'),
+ Decimal(0))
+ self.amount = abs(sale_amount) - payment_amount
+ self.currency = self.origin.currency
+
@classmethod
def validate(cls, payments):
pool = Pool()