From febc431586f0d0dd242472aa992bbf3896c5a1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 17 Jan 2019 17:34:50 +0100 Subject: [PATCH] Add support for payment and payment_group on Statement Rule issue7925 review45851002 --- CHANGELOG | 2 ++ __init__.py | 4 ++++ setup.py | 1 + statement.py | 33 ++++++++++++++++++++++++++ tests/test_account_payment_clearing.py | 2 +- tryton.cfg | 1 + 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 1c4b006331..e1534cd77d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add support for payment and payment_group on Statement Rule + Version 5.0.0 - 2018-10-01 * Bug fixes (see mercurial logs for details) * Remove support for Python 2.7 diff --git a/__init__.py b/__init__.py index 8a5f8ba66a..d9b70df15a 100644 --- a/__init__.py +++ b/__init__.py @@ -18,6 +18,10 @@ def register(): statement.StatementLine, module='account_payment_clearing', type_='model', depends=['account_statement']) + Pool.register( + statement.StatementRuleLine, + module='account_payment_clearing', type_='model', + depends=['account_statement_rule']) Pool.register( payment.Succeed, module='account_payment_clearing', type_='wizard') diff --git a/setup.py b/setup.py index 826f9b130b..3a264ca26c 100755 --- a/setup.py +++ b/setup.py @@ -53,6 +53,7 @@ requires.append(get_require_version('trytond')) tests_require = [get_require_version('proteus'), get_require_version('trytond_account_statement'), + get_require_version('trytond_account_statement_rule'), 'python-dateutil'] dependency_links = [] if minor_version % 2: diff --git a/statement.py b/statement.py index 18e6e4aded..bb1331e9f2 100644 --- a/statement.py +++ b/statement.py @@ -160,3 +160,36 @@ class StatementLine(metaclass=PoolMeta): if l.payment and l.payment.clearing_move and l.payment.clearing_move.state == 'draft']) + + +class StatementRuleLine(metaclass=PoolMeta): + __name__ = 'account.statement.rule.line' + + def get_line(self, origin, keywords, **context): + line = super().get_line(origin, keywords, **context) + if line: + line.payment = self._get_payment(origin, keywords) + if (line.payment and line.party + and line.payment.party != line.party): + return + line.payment_group = self._get_payment_group(origin, keywords) + return line + + def _get_payment(self, origin, keywords): + pool = Pool() + Payment = pool.get('account.payment') + if keywords.get('payment'): + payments = Payment.search([('rec_name', '=', keywords['payment'])]) + if len(payments) == 1: + payment, = payments + return payment + + def _get_payment_group(self, origin, keywords): + pool = Pool() + Payment = pool.get('account.payment.group') + if keywords.get('payment_group'): + groups, = Payment.search( + [('rec_name', '=', keywords['payment_group'])]) + if len(groups) == 1: + group, = groups + return group diff --git a/tests/test_account_payment_clearing.py b/tests/test_account_payment_clearing.py index 88c3a22f97..f972878470 100644 --- a/tests/test_account_payment_clearing.py +++ b/tests/test_account_payment_clearing.py @@ -11,7 +11,7 @@ from trytond.tests.test_tryton import doctest_checker class AccountPaymentTestCase(ModuleTestCase): 'Test Account Payment module' module = 'account_payment_clearing' - extras = ['account_statement'] + extras = ['account_statement', 'account_statement_rule'] def suite(): diff --git a/tryton.cfg b/tryton.cfg index 36efd5acdd..ebf391a300 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,6 +5,7 @@ depends: ir extras_depend: account_statement + account_statement_rule xml: payment.xml statement.xml