From ca438bddb6c1a25ca0e9cf44df8e8468ae6cba17 Mon Sep 17 00:00:00 2001 From: jcoux Date: Mon, 25 Jul 2016 10:46:45 +0200 Subject: [PATCH] Review of OCA Open Items Report PDF --- account_financial_report_qweb/__openerp__.py | 5 +- account_financial_report_qweb/menuitems.xml | 4 +- .../report/__init__.py | 2 +- .../report/aged_partner_balance.py | 34 ++-- .../report/{open_invoice.py => open_items.py} | 182 +++++++++++------- ...voice_report.xml => open_items_report.xml} | 76 +++++--- account_financial_report_qweb/reports.xml | 12 +- .../wizard/__init__.py | 3 +- ...invoice_wizard.py => open_items_wizard.py} | 15 +- ...rd_view.xml => open_items_wizard_view.xml} | 16 +- 10 files changed, 213 insertions(+), 136 deletions(-) rename account_financial_report_qweb/report/{open_invoice.py => open_items.py} (77%) rename account_financial_report_qweb/report/templates/{open_invoice_report.xml => open_items_report.xml} (77%) rename account_financial_report_qweb/wizard/{open_invoice_wizard.py => open_items_wizard.py} (90%) rename account_financial_report_qweb/wizard/{open_invoice_wizard_view.xml => open_items_wizard_view.xml} (78%) diff --git a/account_financial_report_qweb/__openerp__.py b/account_financial_report_qweb/__openerp__.py index 72c6a16b..cf6ff977 100644 --- a/account_financial_report_qweb/__openerp__.py +++ b/account_financial_report_qweb/__openerp__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Author: Damien Crier +# Author: Julien Coux # Copyright 2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { @@ -22,7 +23,7 @@ 'data': [ 'wizard/aged_partner_balance_wizard_view.xml', 'wizard/general_ledger_wizard_view.xml', - 'wizard/open_invoice_wizard_view.xml', + 'wizard/open_items_wizard_view.xml', 'wizard/balance_common_wizard_view.xml', 'wizard/partner_balance_wizard_view.xml', 'wizard/trial_balance_wizard_view.xml', @@ -32,7 +33,7 @@ 'report/templates/aged_partner_balance.xml', 'report/templates/general_ledger.xml', 'report/templates/layouts.xml', - 'report/templates/open_invoice_report.xml', + 'report/templates/open_items_report.xml', 'view/account_view.xml' ], 'test': [ diff --git a/account_financial_report_qweb/menuitems.xml b/account_financial_report_qweb/menuitems.xml index 23564bc9..a7e0c87f 100644 --- a/account_financial_report_qweb/menuitems.xml +++ b/account_financial_report_qweb/menuitems.xml @@ -36,8 +36,8 @@ diff --git a/account_financial_report_qweb/report/__init__.py b/account_financial_report_qweb/report/__init__.py index eaa9c1ca..4aef330d 100644 --- a/account_financial_report_qweb/report/__init__.py +++ b/account_financial_report_qweb/report/__init__.py @@ -7,4 +7,4 @@ from . import aged_partner_balance from . import general_ledger from . import general_ledger_xlsx -from . import open_invoice +from . import open_items diff --git a/account_financial_report_qweb/report/aged_partner_balance.py b/account_financial_report_qweb/report/aged_partner_balance.py index e0e4d582..374c85ff 100644 --- a/account_financial_report_qweb/report/aged_partner_balance.py +++ b/account_financial_report_qweb/report/aged_partner_balance.py @@ -19,7 +19,7 @@ class AgedPartnerBalanceReport(models.TransientModel): filter_partner_ids = fields.Many2many(comodel_name='res.partner') show_move_line_details = fields.Boolean() - open_invoice_id = fields.Many2one(comodel_name='report_open_invoice_qweb') + open_items_id = fields.Many2one(comodel_name='report_open_items_qweb') account_ids = fields.One2many( comodel_name='report_aged_partner_balance_qweb_account', @@ -168,15 +168,15 @@ class AgedPartnerBalanceReportCompute(models.TransientModel): @api.model def compute_data_for_report(self): self.ensure_one() - model = self.env['report_open_invoice_qweb'] - self.open_invoice_id = model.create({ + model = self.env['report_open_items_qweb'] + self.open_items_id = model.create({ 'date_at': self.date_at, 'only_posted_moves': self.only_posted_moves, 'company_id': self.company_id.id, 'filter_account_ids': [(6, 0, self.filter_account_ids.ids)], 'filter_partner_ids': [(6, 0, self.filter_partner_ids.ids)], }) - self.open_invoice_id.compute_data_for_report() + self.open_items_id.compute_data_for_report() self.inject_account_values() self.inject_partner_values() @@ -207,14 +207,14 @@ SELECT rao.code, rao.name FROM - report_open_invoice_qweb_account rao + report_open_items_qweb_account rao WHERE rao.report_id = %s """ query_inject_account_params = ( self.id, self.env.uid, - self.open_invoice_id.id, + self.open_items_id.id, ) self.env.cr.execute(query_inject_account, query_inject_account_params) @@ -236,9 +236,9 @@ SELECT rpo.partner_id, rpo.name FROM - report_open_invoice_qweb_partner rpo + report_open_items_qweb_partner rpo INNER JOIN - report_open_invoice_qweb_account rao ON rpo.report_account_id = rao.id + report_open_items_qweb_account rao ON rpo.report_account_id = rao.id INNER JOIN report_aged_partner_balance_qweb_account ra ON rao.code = ra.code WHERE @@ -247,7 +247,7 @@ AND ra.report_id = %s """ query_inject_partner_params = ( self.env.uid, - self.open_invoice_id.id, + self.open_items_id.id, self.id, ) self.env.cr.execute(query_inject_partner, query_inject_partner_params) @@ -328,11 +328,11 @@ SELECT ) AS older FROM date_range, - report_open_invoice_qweb_move_line rlo + report_open_items_qweb_move_line rlo INNER JOIN - report_open_invoice_qweb_partner rpo ON rlo.report_partner_id = rpo.id + report_open_items_qweb_partner rpo ON rlo.report_partner_id = rpo.id INNER JOIN - report_open_invoice_qweb_account rao ON rpo.report_account_id = rao.id + report_open_items_qweb_account rao ON rpo.report_account_id = rao.id INNER JOIN report_aged_partner_balance_qweb_account ra ON rao.code = ra.code INNER JOIN @@ -358,7 +358,7 @@ GROUP BY """ query_inject_line_params = (self.date_at,) * 6 query_inject_line_params += ( - self.open_invoice_id.id, + self.open_items_id.id, self.id, ) self.env.cr.execute(query_inject_line, query_inject_line_params) @@ -439,11 +439,11 @@ SELECT END AS older FROM date_range, - report_open_invoice_qweb_move_line rlo + report_open_items_qweb_move_line rlo INNER JOIN - report_open_invoice_qweb_partner rpo ON rlo.report_partner_id = rpo.id + report_open_items_qweb_partner rpo ON rlo.report_partner_id = rpo.id INNER JOIN - report_open_invoice_qweb_account rao ON rpo.report_account_id = rao.id + report_open_items_qweb_account rao ON rpo.report_account_id = rao.id INNER JOIN report_aged_partner_balance_qweb_account ra ON rao.code = ra.code INNER JOIN @@ -467,7 +467,7 @@ AND ra.report_id = %s """ query_inject_move_line_params = (self.date_at,) * 6 query_inject_move_line_params += ( - self.open_invoice_id.id, + self.open_items_id.id, self.id, ) self.env.cr.execute(query_inject_move_line, diff --git a/account_financial_report_qweb/report/open_invoice.py b/account_financial_report_qweb/report/open_items.py similarity index 77% rename from account_financial_report_qweb/report/open_invoice.py rename to account_financial_report_qweb/report/open_items.py index c3dfc2f4..9c05ff3a 100644 --- a/account_financial_report_qweb/report/open_invoice.py +++ b/account_financial_report_qweb/report/open_items.py @@ -5,95 +5,120 @@ from openerp import models, fields, api -class OpenInvoiceReport(models.TransientModel): +class OpenItemsReport(models.TransientModel): """ Here, we just define class fields. For methods, go more bottom at this file. + + The class hierarchy is : + * OpenItemsReport + ** OpenItemsReportAccount + *** OpenItemsReportPartner + **** OpenItemsReportMoveLine """ - _name = 'report_open_invoice_qweb' + _name = 'report_open_items_qweb' + # Filters fields, used for data computation date_at = fields.Date() only_posted_moves = fields.Boolean() hide_account_balance_at_0 = fields.Boolean() company_id = fields.Many2one(comodel_name='res.company') filter_account_ids = fields.Many2many(comodel_name='account.account') filter_partner_ids = fields.Many2many(comodel_name='res.partner') + + # Flag fields, used for report display has_second_currency = fields.Boolean() + # Data fields, used to browse report data account_ids = fields.One2many( - comodel_name='report_open_invoice_qweb_account', + comodel_name='report_open_items_qweb_account', inverse_name='report_id' ) -class OpenInvoiceReportAccount(models.TransientModel): +class OpenItemsReportAccount(models.TransientModel): - _name = 'report_open_invoice_qweb_account' + _name = 'report_open_items_qweb_account' _order = 'code ASC' report_id = fields.Many2one( - comodel_name='report_open_invoice_qweb', + comodel_name='report_open_items_qweb', ondelete='cascade', index=True ) + + # Data fields, used to keep link with real object account_id = fields.Many2one( 'account.account', index=True ) + + # Data fields, used for report display code = fields.Char() name = fields.Char() final_amount_residual = fields.Float(digits=(16, 2)) + # Data fields, used to browse report data partner_ids = fields.One2many( - comodel_name='report_open_invoice_qweb_partner', + comodel_name='report_open_items_qweb_partner', inverse_name='report_account_id' ) -class OpenInvoiceReportPartner(models.TransientModel): +class OpenItemsReportPartner(models.TransientModel): - _name = 'report_open_invoice_qweb_partner' + _name = 'report_open_items_qweb_partner' report_account_id = fields.Many2one( - comodel_name='report_open_invoice_qweb_account', + comodel_name='report_open_items_qweb_account', ondelete='cascade', index=True ) + + # Data fields, used to keep link with real object partner_id = fields.Many2one( 'res.partner', index=True ) + + # Data fields, used for report display name = fields.Char() final_amount_residual = fields.Float(digits=(16, 2)) + # Data fields, used to browse report data move_line_ids = fields.One2many( - comodel_name='report_open_invoice_qweb_move_line', + comodel_name='report_open_items_qweb_move_line', inverse_name='report_partner_id' ) @api.model def _generate_order_by(self, order_spec, query): + """Custom order to display "No partner allocated" at last position.""" return """ ORDER BY -CASE - WHEN "report_open_invoice_qweb_partner"."partner_id" IS NOT NULL - THEN 0 - ELSE 1 + CASE + WHEN "report_open_items_qweb_partner"."partner_id" IS NOT NULL + THEN 0 + ELSE 1 END, -"report_open_invoice_qweb_partner"."name" + "report_open_items_qweb_partner"."name" """ -class OpenInvoiceReportMoveLine(models.TransientModel): +class OpenItemsReportMoveLine(models.TransientModel): - _name = 'report_open_invoice_qweb_move_line' + _name = 'report_open_items_qweb_move_line' report_partner_id = fields.Many2one( - comodel_name='report_open_invoice_qweb_partner', + comodel_name='report_open_items_qweb_partner', ondelete='cascade', index=True ) + + # Data fields, used to keep link with real object move_line_id = fields.Many2one('account.move.line') + + # Data fields, used for report display date = fields.Date() date_due = fields.Date() entry = fields.Char() @@ -108,38 +133,43 @@ class OpenInvoiceReportMoveLine(models.TransientModel): amount_residual_currency = fields.Float(digits=(16, 2)) -class OpenInvoiceReportCompute(models.TransientModel): +class OpenItemsReportCompute(models.TransientModel): + """ Here, we just define methods. + For class fields, go more top at this file. + """ - _inherit = 'report_open_invoice_qweb' + _inherit = 'report_open_items_qweb' - @api.model + @api.multi def print_report(self): self.ensure_one() self.compute_data_for_report() + report_name = 'account_financial_report_qweb.report_open_items_qweb' return { 'type': 'ir.actions.report.xml', - 'report_name': - 'account_financial_report_qweb.report_open_invoice_qweb', + 'report_name': report_name, 'datas': {'ids': [self.id]}, } - @api.model + @api.multi def compute_data_for_report(self): self.ensure_one() - - self.inject_account_values() - self.inject_partner_values() - self.inject_line_values() - self.inject_line_values(only_empty_partner_line=True) - self.clean_partners_and_accounts() - self.compute_partners_and_accounts_cumul() + # Compute report data + self._inject_account_values() + self._inject_partner_values() + self._inject_line_values() + self._inject_line_values(only_empty_partner_line=True) + self._clean_partners_and_accounts() + self._compute_partners_and_accounts_cumul() if self.hide_account_balance_at_0: - self.clean_partners_and_accounts( + self._clean_partners_and_accounts( only_delete_account_balance_at_0=True ) - self.compute_has_second_currency() + # Compute display flag + self._compute_has_second_currency() - def inject_account_values(self): + def _inject_account_values(self): + """Inject report values for report_open_items_qweb_account.""" query_inject_account = """ WITH accounts AS @@ -184,7 +214,7 @@ WITH a.id ) INSERT INTO - report_open_invoice_qweb_account + report_open_items_qweb_account ( report_id, create_uid, @@ -221,7 +251,8 @@ FROM ) self.env.cr.execute(query_inject_account, query_inject_account_params) - def inject_partner_values(self): + def _inject_partner_values(self): + """ Inject report values for report_open_items_qweb_partner. """ query_inject_partner = """ WITH accounts_partners AS @@ -242,7 +273,7 @@ WITH 'No partner allocated' ) AS partner_name FROM - report_open_invoice_qweb_account ra + report_open_items_qweb_account ra INNER JOIN account_account a ON ra.account_id = a.id INNER JOIN @@ -274,7 +305,7 @@ WITH at.include_initial_balance ) INSERT INTO - report_open_invoice_qweb_partner + report_open_items_qweb_partner ( report_account_id, create_uid, @@ -304,7 +335,12 @@ FROM ) self.env.cr.execute(query_inject_partner, query_inject_partner_params) - def inject_line_values(self, only_empty_partner_line=False): + def _inject_line_values(self, only_empty_partner_line=False): + """ Inject report values for report_open_items_qweb_move_line. + + The "only_empty_partner_line" value is used + to compute data without partner. + """ query_inject_move_line = """ WITH move_lines_amount AS @@ -328,9 +364,9 @@ WITH END ) AS partial_amount_currency FROM - report_open_invoice_qweb_partner rp + report_open_items_qweb_partner rp INNER JOIN - report_open_invoice_qweb_account ra + report_open_items_qweb_account ra ON rp.report_account_id = ra.id INNER JOIN account_move_line ml @@ -408,7 +444,7 @@ WITH amount_currency ) INSERT INTO - report_open_invoice_qweb_move_line + report_open_items_qweb_move_line ( report_partner_id, create_uid, @@ -460,9 +496,9 @@ SELECT ml.amount_currency, ml2.amount_residual_currency FROM - report_open_invoice_qweb_partner rp + report_open_items_qweb_partner rp INNER JOIN - report_open_invoice_qweb_account ra ON rp.report_account_id = ra.id + report_open_items_qweb_account ra ON rp.report_account_id = ra.id INNER JOIN account_move_line ml ON ra.account_id = ml.account_id INNER JOIN @@ -525,19 +561,22 @@ ORDER BY self.date_at,) ) - def compute_partners_and_accounts_cumul(self): + def _compute_partners_and_accounts_cumul(self): + """ Compute cumulative amount for + report_open_items_qweb_partner and report_open_items_qweb_account. + """ query_compute_partners_cumul = """ UPDATE - report_open_invoice_qweb_partner + report_open_items_qweb_partner SET final_amount_residual = ( SELECT SUM(rml.amount_residual) AS final_amount_residual FROM - report_open_invoice_qweb_move_line rml + report_open_items_qweb_move_line rml WHERE - rml.report_partner_id = report_open_invoice_qweb_partner.id + rml.report_partner_id = report_open_items_qweb_partner.id ) WHERE id IN @@ -545,9 +584,9 @@ WHERE SELECT rp.id FROM - report_open_invoice_qweb_account ra + report_open_items_qweb_account ra INNER JOIN - report_open_invoice_qweb_partner rp + report_open_items_qweb_partner rp ON ra.id = rp.report_account_id WHERE ra.report_id = %s @@ -558,16 +597,16 @@ WHERE params_compute_partners_cumul) query_compute_accounts_cumul = """ UPDATE - report_open_invoice_qweb_account + report_open_items_qweb_account SET final_amount_residual = ( SELECT SUM(rp.final_amount_residual) AS final_amount_residual FROM - report_open_invoice_qweb_partner rp + report_open_items_qweb_partner rp WHERE - rp.report_account_id = report_open_invoice_qweb_account.id + rp.report_account_id = report_open_items_qweb_account.id ) WHERE report_id = %s @@ -576,23 +615,29 @@ WHERE self.env.cr.execute(query_compute_accounts_cumul, params_compute_accounts_cumul) - def clean_partners_and_accounts(self, - only_delete_account_balance_at_0=False): + def _clean_partners_and_accounts(self, + only_delete_account_balance_at_0=False): + """ Delete empty data for + report_open_items_qweb_partner and report_open_items_qweb_account. + + The "only_delete_account_balance_at_0" value is used + to delete also the data with cumulative amounts at 0. + """ query_clean_partners = """ DELETE FROM - report_open_invoice_qweb_partner + report_open_items_qweb_partner WHERE id IN ( SELECT DISTINCT rp.id FROM - report_open_invoice_qweb_account ra + report_open_items_qweb_account ra INNER JOIN - report_open_invoice_qweb_partner rp + report_open_items_qweb_partner rp ON ra.id = rp.report_account_id LEFT JOIN - report_open_invoice_qweb_move_line rml + report_open_items_qweb_move_line rml ON rp.id = rml.report_partner_id WHERE ra.report_id = %s @@ -615,16 +660,16 @@ WHERE self.env.cr.execute(query_clean_partners, params_clean_partners) query_clean_accounts = """ DELETE FROM - report_open_invoice_qweb_account + report_open_items_qweb_account WHERE id IN ( SELECT DISTINCT ra.id FROM - report_open_invoice_qweb_account ra + report_open_items_qweb_account ra LEFT JOIN - report_open_invoice_qweb_partner rp + report_open_items_qweb_partner rp ON ra.id = rp.report_account_id WHERE ra.report_id = %s @@ -646,22 +691,23 @@ WHERE params_clean_accounts = (self.id,) self.env.cr.execute(query_clean_accounts, params_clean_accounts) - def compute_has_second_currency(self): + def _compute_has_second_currency(self): + """ Compute "has_second_currency" flag which will used for display.""" query_update_has_second_currency = """ UPDATE - report_open_invoice_qweb + report_open_items_qweb SET has_second_currency = ( SELECT TRUE FROM - report_open_invoice_qweb_move_line l + report_open_items_qweb_move_line l INNER JOIN - report_open_invoice_qweb_partner p + report_open_items_qweb_partner p ON l.report_partner_id = p.id INNER JOIN - report_open_invoice_qweb_account a + report_open_items_qweb_account a ON p.report_account_id = a.id WHERE a.report_id = %s diff --git a/account_financial_report_qweb/report/templates/open_invoice_report.xml b/account_financial_report_qweb/report/templates/open_items_report.xml similarity index 77% rename from account_financial_report_qweb/report/templates/open_invoice_report.xml rename to account_financial_report_qweb/report/templates/open_items_report.xml index ac6a6d24..b4b7be18 100644 --- a/account_financial_report_qweb/report/templates/open_invoice_report.xml +++ b/account_financial_report_qweb/report/templates/open_items_report.xml @@ -1,54 +1,50 @@ -