diff --git a/CHANGELOG b/CHANGELOG
index 49d3dfd70e..30c3023772 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add warning to group lines
* Add date to Pay Lines wizard
Version 5.0.0 - 2018-10-01
diff --git a/account.py b/account.py
index 78087bd141..122a2a32bf 100644
--- a/account.py
+++ b/account.py
@@ -18,7 +18,7 @@ from trytond.transaction import Transaction
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 @@ class PayLine(Wizard):
])
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 --git a/exceptions.py b/exceptions.py
index bd9bb8758b..3403af63cd 100644
--- a/exceptions.py
+++ b/exceptions.py
@@ -19,3 +19,7 @@ class PaymentValidationError(ValidationError):
class BlockedWarning(UserWarning):
pass
+
+
+class GroupWarning(UserWarning):
+ pass
diff --git a/message.xml b/message.xml
index dc4aa73573..494debd670 100644
--- a/message.xml
+++ b/message.xml
@@ -15,5 +15,8 @@ this repository contains the full copyright notices and license terms. -->
Line "%(line)s" is blocked for payment.
+
+ The lines "%(names)s" for %(party)s could be grouped with the line "%(line)s".
+