Rational
When doing entering statement it is common to have lines matching receivable or payable lines in the system. Currently on tryton you need to select the party and account and do the reconciliation latter.
When the amount of lines to match is big, this is a long task for the user.
As tryton has all the information, it will be good to automate the creation of such lines, so the user does not need to type all the information.
Proposal
Add a button on the statement lines to match existing payments.
The matching can be done by amount and the line will be keep only if there is a single line matching the same amount.
The matching criteria should be customized and probably it will be good to match the same line using different criteria. For example, if a line for the same amount is found, we may try to find if the matturity date matches the origin date, so the search is redefined and the number of matching lines is increased.
Implementation
We have implement it as custom code using the following code: as extension of the apply rules button.
@classmethod
@ModelView.button
def apply_rules(cls, statements):
pool = Pool()
Line = pool.get('account.statement.line')
MoveLine = pool.get('account.move.line')
Invoice = pool.get('account.invoice')
amount2lines = defaultdict(list)
for line in MoveLine.search([
('reconciliation', '=', None),
('account.party_required', '=', True),
['OR',
('account.type.payable', '=', True),
('account.type.receivable', '=', True),
],
]):
amount2lines[line.amount].append(line)
super().apply_rules(statements)
to_save = []
for statement in statements:
for origin in statement.origins:
if origin.lines:
continue
lines = amount2lines.get(origin.amount)
if lines and len(lines) == 1:
origin_line, = lines
line = Line()
line.statement = origin.statement
line.number = origin.number
line.description = origin.description
line.date = origin.date
line.origin = origin
line.amount = origin.amount
line.party = origin_line.party
line.account = origin_line.account
if isinstance(origin_line.move.origin, Invoice):
line.related_to = origin_line.move.origin
to_save.append(line)
if to_save:
Line.save(to_save)
This misses the implementation of matching multiple criterias, but it should not be hard to implement by using the criteria as key of the dictionary.