changeset b1cb85e1fc7d in modules/account_payment:default
details:
https://hg.tryton.org/modules/account_payment?cmd=changeset;node=b1cb85e1fc7d
description:
Add group lines wizard
issue8213
review275091002
diffstat:
CHANGELOG | 1 +
account.py | 45 ++++++++++++++++++++++++++++++++++++++++++++-
exceptions.py | 4 ++++
message.xml | 3 +++
4 files changed, 52 insertions(+), 1 deletions(-)
diffs (93 lines):
diff -r aa193b4252b3 -r b1cb85e1fc7d CHANGELOG
--- a/CHANGELOG Fri Apr 12 15:59:24 2019 +0200
+++ b/CHANGELOG Fri Apr 12 19:43:53 2019 +0200
@@ -1,3 +1,4 @@
+* Add warning to group lines
* Add date to Pay Lines wizard
Version 5.0.0 - 2018-10-01
diff -r aa193b4252b3 -r b1cb85e1fc7d account.py
--- a/account.py Fri Apr 12 15:59:24 2019 +0200
+++ b/account.py Fri Apr 12 19:43:53 2019 +0200
@@ -18,7 +18,7 @@
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import CompanyValueMixin
-from .exceptions import BlockedWarning
+from .exceptions import BlockedWarning, GroupWarning
from .payment import KINDS
__all__ = ['MoveLine', 'PayLine', 'PayLineAskJournal',
@@ -229,6 +229,49 @@
])
pay = StateAction('account_payment.act_payment_form')
+ def default_start(self, fields):
+ pool = Pool()
+ Line = pool.get('account.move.line')
+ Warning = pool.get('res.user.warning')
+
+ reverse = {'receivable': 'payable', 'payable': 'receivable'}
+ types = {
+ kind: {
+ 'parties': set(),
+ 'lines': list(),
+ }
+ for kind in reverse.keys()}
+ lines = Line.browse(Transaction().context['active_ids'])
+ for line in lines:
+ for kind in types:
+ if getattr(line.account.type, kind):
+ types[kind]['parties'].add(line.party)
+ types[kind]['lines'].append(line)
+
+ for kind in types:
+ parties = types[kind]['parties']
+ others = Line.search([
+ ('account.type.' + kind, '=', reverse[kind]),
+ ('party', 'in', [p.id for p in parties]),
+ ('reconciliation', '=', None),
+ ('payment_amount', '!=', 0),
+ ('move_state', '=', 'posted'),
+ ])
+ for line in others:
+ warning_name = '%s:%s' % (reverse[kind], line.party)
+ if Warning.check(warning_name):
+ lines = [l for l in types[kind]['lines']
+ if l.party == line.party]
+ names = ', '.join(l.rec_name for l in lines[:5])
+ if len(lines) > 5:
+ names += '...'
+ raise GroupWarning(warning_name,
+ gettext('account_payment.msg_pay_line_group',
+ names=names,
+ party=line.party.rec_name,
+ line=line.rec_name))
+ return {}
+
def _get_journals(self):
journals = {}
for journal in getattr(self.ask_journal, 'journals', []):
diff -r aa193b4252b3 -r b1cb85e1fc7d exceptions.py
--- a/exceptions.py Fri Apr 12 15:59:24 2019 +0200
+++ b/exceptions.py Fri Apr 12 19:43:53 2019 +0200
@@ -19,3 +19,7 @@
class BlockedWarning(UserWarning):
pass
+
+
+class GroupWarning(UserWarning):
+ pass
diff -r aa193b4252b3 -r b1cb85e1fc7d message.xml
--- a/message.xml Fri Apr 12 15:59:24 2019 +0200
+++ b/message.xml Fri Apr 12 19:43:53 2019 +0200
@@ -15,5 +15,8 @@
<record model="ir.message" id="msg_pay_line_blocked">
<field name="text">Line "%(line)s" is blocked for payment.</field>
</record>
+ <record model="ir.message" id="msg_pay_line_group">
+ <field name="text">The lines "%(names)s" for %(party)s could be
grouped with the line "%(line)s".</field>
+ </record>
</data>
</tryton>