From 2137eecd2cef0b804e58606117fdc4bc5460913e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 1 Feb 2017 21:43:20 +0100 Subject: [PATCH] Improve accounting move descriptions - Add statement line number as move description - Set description on statement account line if unique issue6205 review26051002 --- CHANGELOG | 3 +++ statement.py | 12 ++++++++++-- tests/scenario_account_statement.rst | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index df2ba1cb03..ff9d838b32 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Add statement line number as move description +* Set description on statement account line if unique + Version 4.2.0 - 2016-11-28 * Bug fixes (see mercurial logs for details) * Manage readonly state on Statement Line diff --git a/statement.py b/statement.py index 35e3b5e05a..0b0b066bc4 100644 --- a/statement.py +++ b/statement.py @@ -450,7 +450,7 @@ class Statement(Workflow, ModelSQL, ModelView): move_lines.append((move_line, line)) move_line = statement._get_move_line( - amount, amount_second_currency) + amount, amount_second_currency, lines) move_line.move = move move_lines.append((move_line, None)) @@ -474,9 +474,10 @@ class Statement(Workflow, ModelSQL, ModelView): date=key['date'], origin=self, company=self.company, + description=unicode(key['number']), ) - def _get_move_line(self, amount, amount_second_currency): + def _get_move_line(self, amount, amount_second_currency, lines): 'Return counterpart Move Line for the amount' pool = Pool() MoveLine = pool.get('account.move.line') @@ -497,12 +498,19 @@ class Statement(Workflow, ModelSQL, ModelView): second_currency = None amount_second_currency = None + descriptions = {l.description for l in lines} + if len(descriptions) == 1: + description, = descriptions + else: + description = '' + return MoveLine( debit=abs(amount) if amount < 0 else 0, credit=abs(amount) if amount > 0 else 0, account=account, second_currency=second_currency, amount_second_currency=amount_second_currency, + description=description, ) @classmethod diff --git a/tests/scenario_account_statement.rst b/tests/scenario_account_statement.rst index 9ccc733b60..f26e2a523d 100644 --- a/tests/scenario_account_statement.rst +++ b/tests/scenario_account_statement.rst @@ -148,6 +148,8 @@ Received 180 from customer:: >>> statement_line = StatementLine() >>> statement.lines.append(statement_line) + >>> statement_line.number = '0001' + >>> statement_line.description = 'description' >>> statement_line.date = today >>> statement_line.amount = Decimal('180') >>> statement_line.party = customer @@ -159,10 +161,15 @@ Received 180 from customer:: >>> statement_line = statement.lines[-1] >>> statement_line.amount Decimal('80.00') + >>> statement_line.number + '0001' + >>> statement_line.description + 'description' >>> statement_line.party == customer True >>> statement_line.account == receivable True + >>> statement_line.description = 'other description' >>> statement_line.invoice = customer_invoice2 >>> statement_line.amount Decimal('80.00') @@ -171,6 +178,8 @@ Paid 50 to customer:: >>> statement_line = StatementLine() >>> statement.lines.append(statement_line) + >>> statement_line.number = '0002' + >>> statement_line.description = 'description' >>> statement_line.date = today >>> statement_line.amount = Decimal('-50') >>> statement_line.party = customer @@ -201,6 +210,22 @@ Validate statement:: >>> statement.state u'validated' +Test posted moves:: + + >>> statement_line = statement.lines[0] + >>> move = statement_line.move + >>> move.description + u'0001' + >>> sorted((l.description for l in move.lines)) + [u'', u'description', u'other description'] + + >>> statement_line = statement.lines[2] + >>> move = statement_line.move + >>> move.description + u'0002' + >>> sorted((l.description for l in move.lines)) + [u'description', u'description'] + Test invoice state:: >>> customer_invoice1.reload()