From bd03b66a4e65eff46f13d87510c1f85dc656fcc5 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Tue, 17 Nov 2020 17:22:48 +0100 Subject: [PATCH] [13.0][IMP] partner_statement: * show partner name at the top. * simplify view logic for `name` and `ref` printing. * fallback to journal entry `ref` when the journal item has no `ref` set. * little query formatting changes to enhance readability. --- partner_statement/readme/CONTRIBUTORS.rst | 1 + .../report/activity_statement.py | 60 ++++++++++--------- .../report/outstanding_statement.py | 13 +++- .../views/activity_statement.xml | 19 +++--- .../views/outstanding_statement.xml | 12 ++-- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/partner_statement/readme/CONTRIBUTORS.rst b/partner_statement/readme/CONTRIBUTORS.rst index 286b2c12..22ac2498 100644 --- a/partner_statement/readme/CONTRIBUTORS.rst +++ b/partner_statement/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Miquel Raïch * Graeme Gellatly +* Lois Rilo diff --git a/partner_statement/report/activity_statement.py b/partner_statement/report/activity_statement.py index f1de2b6c..adddb6f6 100644 --- a/partner_statement/report/activity_statement.py +++ b/partner_statement/report/activity_statement.py @@ -79,29 +79,32 @@ class ActivityStatement(models.AbstractModel): self._cr.mogrify( """ SELECT m.name AS move_id, l.partner_id, l.date, - CASE WHEN (aj.type IN ('sale', 'purchase')) - THEN l.name - ELSE '/' - END as name, - CASE WHEN (aj.type IN ('sale', 'purchase')) - THEN l.ref - WHEN (aj.type in ('bank', 'cash')) - THEN 'Payment' - ELSE '' - END as ref, - l.blocked, l.currency_id, l.company_id, - CASE WHEN (l.currency_id is not null AND l.amount_currency > 0.0) - THEN sum(l.amount_currency) - ELSE sum(l.debit) - END as debit, - CASE WHEN (l.currency_id is not null AND l.amount_currency < 0.0) - THEN sum(l.amount_currency * (-1)) - ELSE sum(l.credit) - END as credit, - CASE WHEN l.date_maturity is null - THEN l.date - ELSE l.date_maturity - END as date_maturity + CASE WHEN (aj.type IN ('sale', 'purchase')) + THEN l.name + ELSE '/' + END as name, + CASE + WHEN (aj.type IN ('sale', 'purchase')) AND l.name IS NOT NULL + THEN l.ref + WHEN aj.type IN ('sale', 'purchase') AND l.name IS NULL + THEN m.ref + WHEN (aj.type in ('bank', 'cash')) + THEN 'Payment' + ELSE '' + END as ref, + l.blocked, l.currency_id, l.company_id, + CASE WHEN (l.currency_id is not null AND l.amount_currency > 0.0) + THEN sum(l.amount_currency) + ELSE sum(l.debit) + END as debit, + CASE WHEN (l.currency_id is not null AND l.amount_currency < 0.0) + THEN sum(l.amount_currency * (-1)) + ELSE sum(l.credit) + END as credit, + CASE WHEN l.date_maturity is null + THEN l.date + ELSE l.date_maturity + END as date_maturity FROM account_move_line l JOIN account_move m ON (l.move_id = m.id) JOIN account_journal aj ON (l.journal_id = aj.id) @@ -115,10 +118,13 @@ class ActivityStatement(models.AbstractModel): THEN l.name ELSE '/' END, - CASE WHEN (aj.type IN ('sale', 'purchase')) - THEN l.ref - WHEN (aj.type in ('bank', 'cash')) - THEN 'Payment' + CASE + WHEN (aj.type IN ('sale', 'purchase')) AND l.name IS NOT NULL + THEN l.ref + WHEN aj.type IN ('sale', 'purchase') AND l.name IS NULL + THEN m.ref + WHEN (aj.type in ('bank', 'cash')) + THEN 'Payment' ELSE '' END, l.blocked, l.currency_id, l.amount_currency, l.company_id diff --git a/partner_statement/report/outstanding_statement.py b/partner_statement/report/outstanding_statement.py index ce1af302..f1ae61e8 100644 --- a/partner_statement/report/outstanding_statement.py +++ b/partner_statement/report/outstanding_statement.py @@ -17,7 +17,11 @@ class OutstandingStatement(models.AbstractModel): self._cr.mogrify( """ SELECT m.name AS move_id, l.partner_id, l.date, l.name, - l.ref, l.blocked, l.currency_id, l.company_id, + l.blocked, l.currency_id, l.company_id, + CASE WHEN l.ref IS NOT NULL + THEN l.ref + ELSE m.ref + END as ref, CASE WHEN (l.currency_id is not null AND l.amount_currency > 0.0) THEN avg(l.amount_currency) ELSE avg(l.debit) @@ -62,8 +66,11 @@ class OutstandingStatement(models.AbstractModel): (pd.id IS NULL AND pc.id IS NULL) ) AND l.date <= %(date_end)s AND m.state IN ('posted') GROUP BY l.partner_id, m.name, l.date, l.date_maturity, l.name, - l.ref, l.blocked, l.currency_id, - l.balance, l.amount_currency, l.company_id + CASE WHEN l.ref IS NOT NULL + THEN l.ref + ELSE m.ref + END, + l.blocked, l.currency_id, l.balance, l.amount_currency, l.company_id """, locals(), ), diff --git a/partner_statement/views/activity_statement.xml b/partner_statement/views/activity_statement.xml index 5118afe6..36563bf5 100644 --- a/partner_statement/views/activity_statement.xml +++ b/partner_statement/views/activity_statement.xml @@ -21,6 +21,10 @@ Date:

+

+ Partner Name: +

+

Partner Code:

@@ -80,12 +84,15 @@ - + + + + @@ -94,16 +101,10 @@ > - - - - Payment - + diff --git a/partner_statement/views/outstanding_statement.xml b/partner_statement/views/outstanding_statement.xml index a6228db0..9752406f 100644 --- a/partner_statement/views/outstanding_statement.xml +++ b/partner_statement/views/outstanding_statement.xml @@ -22,6 +22,10 @@ Date:

+
+ Partner Name: +

+

Partner Code:

@@ -71,9 +75,12 @@ + + + @@ -82,9 +89,6 @@ > - - -