From 987f5fcbd220682410fc46777c0405b9a580779f Mon Sep 17 00:00:00 2001 From: Wolfgang Pichler Date: Wed, 16 Jan 2019 19:38:26 +0100 Subject: [PATCH] [MIG] account_financial_report: Migration to 12.0 [IMP] Reformated one query to avoid one sql injection warning message - but no sql injection was possible here --- account_financial_report/__manifest__.py | 3 +- account_financial_report/menuitems.xml | 3 +- .../report/abstract_report.py | 4 +- .../report/abstract_report_xlsx.py | 4 ++ .../report/aged_partner_balance.py | 2 +- .../report/general_ledger.py | 2 +- .../report/journal_ledger.py | 2 +- account_financial_report/report/open_items.py | 2 +- .../report/trial_balance.py | 4 +- account_financial_report/report/vat_report.py | 2 +- .../js/account_financial_report_backend.js | 40 ++++++++++++++++--- .../tests/abstract_test.py | 13 +----- .../tests/test_aged_partner_balance.py | 4 +- .../tests/test_general_ledger.py | 17 ++++---- .../tests/test_journal_ledger.py | 6 +-- .../tests/test_open_items.py | 4 +- .../tests/test_trial_balance.py | 8 ++-- .../tests/test_vat_report.py | 16 ++++---- .../wizard/general_ledger_wizard.py | 5 ++- .../wizard/trial_balance_wizard.py | 6 +-- 20 files changed, 86 insertions(+), 61 deletions(-) diff --git a/account_financial_report/__manifest__.py b/account_financial_report/__manifest__.py index 59d023e7..e0bddf19 100644 --- a/account_financial_report/__manifest__.py +++ b/account_financial_report/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Account Financial Reports', - 'version': '11.0.2.5.0', + 'version': '12.0.1.0.0', 'category': 'Reporting', 'summary': 'OCA Financial Reports', 'author': 'Camptocamp SA,' @@ -15,7 +15,6 @@ "website": "https://odoo-community.org/", 'depends': [ 'account', - 'account_invoicing', 'date_range', 'report_xlsx', ], diff --git a/account_financial_report/menuitems.xml b/account_financial_report/menuitems.xml index 080f3029..ee2cae49 100644 --- a/account_financial_report/menuitems.xml +++ b/account_financial_report/menuitems.xml @@ -58,6 +58,7 @@ groups="base.group_erp_manager" /> + diff --git a/account_financial_report/report/abstract_report.py b/account_financial_report/report/abstract_report.py index 7fe0c54e..8fbec5af 100644 --- a/account_financial_report/report/abstract_report.py +++ b/account_financial_report/report/abstract_report.py @@ -14,9 +14,9 @@ class AbstractReport(models.AbstractModel): # Never delete rows used in last 5 minutes seconds = max(seconds, 300) query = """ -DELETE FROM """ + self._table + """ +DELETE FROM %s WHERE COALESCE( write_date, create_date, (now() at time zone 'UTC'))::timestamp < ((now() at time zone 'UTC') - interval %s) """ - self.env.cr.execute(query, ("%s seconds" % seconds,)) + self.env.cr.execute(query, (self._table, "%s seconds" % seconds,)) diff --git a/account_financial_report/report/abstract_report_xlsx.py b/account_financial_report/report/abstract_report_xlsx.py index 8634823f..9d26800e 100644 --- a/account_financial_report/report/abstract_report_xlsx.py +++ b/account_financial_report/report/abstract_report_xlsx.py @@ -3,6 +3,8 @@ # Copyright 2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import models +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT +import datetime class AbstractReportXslx(models.AbstractModel): @@ -188,6 +190,8 @@ class AbstractReportXslx(models.AbstractModel): """ for col_pos, column in self.columns.items(): value = getattr(line_object, column['field']) + if isinstance(value, datetime.date): + value = datetime.datetime.strftime(value, DEFAULT_SERVER_DATE_FORMAT) cell_type = column.get('type', 'string') if cell_type == 'many2one': self.sheet.write_string( diff --git a/account_financial_report/report/aged_partner_balance.py b/account_financial_report/report/aged_partner_balance.py index a00d32ee..3a0b25f4 100644 --- a/account_financial_report/report/aged_partner_balance.py +++ b/account_financial_report/report/aged_partner_balance.py @@ -195,7 +195,7 @@ class AgedPartnerBalanceReportCompute(models.TransientModel): report = self.env['ir.actions.report'].search( [('report_name', '=', report_name), ('report_type', '=', report_type)], limit=1) - return report.report_action(self) + return report.report_action(self, config=False) def _get_html(self): result = {} diff --git a/account_financial_report/report/general_ledger.py b/account_financial_report/report/general_ledger.py index db6512f3..12cbc280 100644 --- a/account_financial_report/report/general_ledger.py +++ b/account_financial_report/report/general_ledger.py @@ -224,7 +224,7 @@ class GeneralLedgerReportCompute(models.TransientModel): 'report_general_ledger_qweb' return self.env['ir.actions.report'].search( [('report_name', '=', report_name), - ('report_type', '=', report_type)], limit=1).report_action(self) + ('report_type', '=', report_type)], limit=1).report_action(self, config=False) def _get_html(self): result = {} diff --git a/account_financial_report/report/journal_ledger.py b/account_financial_report/report/journal_ledger.py index 8688375b..b8e46219 100644 --- a/account_financial_report/report/journal_ledger.py +++ b/account_financial_report/report/journal_ledger.py @@ -594,7 +594,7 @@ class ReportJournalLedger(models.TransientModel): 'report_journal_ledger_qweb' return self.env['ir.actions.report'].search( [('report_name', '=', report_name), - ('report_type', '=', report_type)], limit=1).report_action(self) + ('report_type', '=', report_type)], limit=1).report_action(self, config=False) def _get_html(self): result = {} diff --git a/account_financial_report/report/open_items.py b/account_financial_report/report/open_items.py index f1039151..959809bc 100644 --- a/account_financial_report/report/open_items.py +++ b/account_financial_report/report/open_items.py @@ -160,7 +160,7 @@ class OpenItemsReportCompute(models.TransientModel): 'report_open_items_qweb' return self.env['ir.actions.report'].search( [('report_name', '=', report_name), - ('report_type', '=', report_type)], limit=1).report_action(self) + ('report_type', '=', report_type)], limit=1).report_action(self, config=False) def _get_html(self): result = {} diff --git a/account_financial_report/report/trial_balance.py b/account_financial_report/report/trial_balance.py index 5f5c8418..057372ca 100644 --- a/account_financial_report/report/trial_balance.py +++ b/account_financial_report/report/trial_balance.py @@ -209,7 +209,7 @@ class TrialBalanceReportCompute(models.TransientModel): 'report_trial_balance_qweb' return self.env['ir.actions.report'].search( [('report_name', '=', report_name), - ('report_type', '=', report_type)], limit=1).report_action(self) + ('report_type', '=', report_type)], limit=1).report_action(self, config=False) def _get_html(self): result = {} @@ -410,7 +410,7 @@ SELECT accgroup.parent_id, coalesce(accgroup.code_prefix, accgroup.name), accgroup.name, - accgroup.parent_left * 100000, + accgroup.id * 100000, accgroup.level FROM account_group accgroup""" diff --git a/account_financial_report/report/vat_report.py b/account_financial_report/report/vat_report.py index 795dd1bf..fff310c9 100644 --- a/account_financial_report/report/vat_report.py +++ b/account_financial_report/report/vat_report.py @@ -112,7 +112,7 @@ class VATReportCompute(models.TransientModel): action = self.env['ir.actions.report'].search( [('report_name', '=', report_name), ('report_type', '=', report_type)], limit=1) - return action.with_context(context).report_action(self) + return action.with_context(context).report_action(self, config=False) def _get_html(self): result = {} diff --git a/account_financial_report/static/src/js/account_financial_report_backend.js b/account_financial_report/static/src/js/account_financial_report_backend.js index dd23b5ad..0d93674f 100644 --- a/account_financial_report/static/src/js/account_financial_report_backend.js +++ b/account_financial_report/static/src/js/account_financial_report_backend.js @@ -23,7 +23,7 @@ odoo.define('account_financial_report.account_financial_report_backend', functio if (action.context.context) { this.given_context = action.context.context; } - this.given_context.active_id = action.context.active_id || + this.given_context.active_id = action.context.active_id || action.params.active_id; this.given_context.model = action.context.active_model || false; this.given_context.ttype = action.context.ttype || false; @@ -57,13 +57,38 @@ odoo.define('account_financial_report.account_financial_report_backend', functio args: [self.given_context], context: self.odoo_context, }) - .then(function (result) { - self.html = result.html; - defs.push(self.update_cp()); - return $.when.apply($, defs); + .then(function (result) { + self.html = result.html; + defs.push(self.update_cp()); + return $.when.apply($, defs); + }); + }, + // Updates the control panel and render the elements that have yet to be rendered + update_cp: function() { + if (this.$buttons) { + var status = { + breadcrumbs: this.actionManager.get_breadcrumbs(), + cp_content: {$buttons: this.$buttons}, + }; + return this.update_control_panel(status); + } + }, + do_show: function() { + this._super(); + this.update_cp(); + }, + print: function() { + var self = this; + this._rpc({ + model: this.given_context.model, + method: 'print_report', + args: [this.given_context.active_id, 'qweb-pdf'], + context: self.odoo_context, + }).then(function(result){ + self.do_action(result); }); }, - // Updates the control panel and render the elements that have yet + // Updates the control panel and render the elements that have yet // to be rendered update_cp: function () { if (this.$buttons) { @@ -101,6 +126,9 @@ odoo.define('account_financial_report.account_financial_report_backend', functio self.do_action(result); }); }, + canBeRemoved: function () { + return $.when(); + }, }); core.action_registry.add( diff --git a/account_financial_report/tests/abstract_test.py b/account_financial_report/tests/abstract_test.py index 5935a59f..0d2792dc 100644 --- a/account_financial_report/tests/abstract_test.py +++ b/account_financial_report/tests/abstract_test.py @@ -36,7 +36,7 @@ class AbstractTest(common.TransactionCase): 'bank_account_code_prefix': 1014, 'cash_account_code_prefix': 1014, 'currency_id': self.ref('base.USD'), - 'transfer_account_id': transfer_account_id.id, + 'transfer_account_code_prefix': '000', }) transfer_account_id.update({ 'chart_template_id': self.chart.id, @@ -98,7 +98,6 @@ class AbstractTest(common.TransactionCase): def _add_chart_of_accounts(self): self.company = self.env['res.company'].create({ 'name': 'Spanish test company', - 'external_report_layout': 'standard', }) self.env.ref('base.group_multi_company').write({ 'users': [(4, self.env.uid)], @@ -109,15 +108,7 @@ class AbstractTest(common.TransactionCase): }) self.with_context( company_id=self.company.id, force_company=self.company.id) - wizard = self.env['wizard.multi.charts.accounts'].create({ - 'company_id': self.company.id, - 'chart_template_id': self.chart.id, - 'code_digits': 4, - 'currency_id': self.ref('base.USD'), - 'transfer_account_id': self.chart.transfer_account_id.id, - }) - wizard.onchange_chart_template_id() - wizard.execute() + self.chart.try_loading_for_current_company() self.revenue = self.env['account.account'].search( [('user_type_id', '=', self.ref( "account.data_account_type_revenue"))], limit=1) diff --git a/account_financial_report/tests/test_aged_partner_balance.py b/account_financial_report/tests/test_aged_partner_balance.py index 54bb7407..3060583e 100644 --- a/account_financial_report/tests/test_aged_partner_balance.py +++ b/account_financial_report/tests/test_aged_partner_balance.py @@ -2,7 +2,7 @@ # Copyright 2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import time +from datetime import date from . import abstract_test @@ -29,7 +29,7 @@ class TestAgedPartnerBalance(abstract_test.AbstractTest): def _getBaseFilters(self): return { - 'date_at': time.strftime('%Y-12-31'), + 'date_at': date(date.today().year, 12, 31), 'company_id': self.company.id, } diff --git a/account_financial_report/tests/test_general_ledger.py b/account_financial_report/tests/test_general_ledger.py index ca218b91..6e735e43 100644 --- a/account_financial_report/tests/test_general_ledger.py +++ b/account_financial_report/tests/test_general_ledger.py @@ -5,6 +5,7 @@ import time from odoo.tests import common +from datetime import date, datetime from . import abstract_test_foreign_currency as a_t_f_c @@ -31,10 +32,10 @@ class TestGeneralLedger(a_t_f_c.AbstractTestForeignCurrency): def _getBaseFilters(self): return { - 'date_from': time.strftime('%Y-01-01'), - 'date_to': time.strftime('%Y-12-31'), + 'date_from': date(date.today().year, 1, 1), + 'date_to': date(date.today().year, 12, 31), 'company_id': self.company.id, - 'fy_start_date': time.strftime('%Y-01-01'), + 'fy_start_date': date(date.today().year, 1, 1), 'foreign_currency': True, } @@ -87,11 +88,11 @@ class TestGeneralLedgerReport(common.TransactionCase): def setUp(self): super(TestGeneralLedgerReport, self).setUp() - self.before_previous_fy_year = '2014-05-05' - self.previous_fy_date_start = '2015-01-01' - self.previous_fy_date_end = '2015-12-31' - self.fy_date_start = '2016-01-01' - self.fy_date_end = '2016-12-31' + self.before_previous_fy_year = datetime.strptime('2014-05-05', '%Y-%m-%d') + self.previous_fy_date_start = datetime.strptime('2015-01-01', '%Y-%m-%d') + self.previous_fy_date_end = datetime.strptime('2015-12-31', '%Y-%m-%d') + self.fy_date_start = datetime.strptime('2016-01-01', '%Y-%m-%d') + self.fy_date_end = datetime.strptime('2016-12-31', '%Y-%m-%d') self.receivable_account = self.env['account.account'].search([ ('user_type_id.name', '=', 'Receivable') ], limit=1) diff --git a/account_financial_report/tests/test_journal_ledger.py b/account_financial_report/tests/test_journal_ledger.py index 2a293013..62c867ef 100644 --- a/account_financial_report/tests/test_journal_ledger.py +++ b/account_financial_report/tests/test_journal_ledger.py @@ -3,7 +3,7 @@ import time -from datetime import datetime +from datetime import datetime, date from dateutil.relativedelta import relativedelta from odoo.fields import Date @@ -34,8 +34,8 @@ class TestJournalLedger(a_t_f_c.AbstractTestForeignCurrency): def _getBaseFilters(self): return { - 'date_from': time.strftime('%Y-01-01'), - 'date_to': time.strftime('%Y-12-31'), + 'date_from': date(date.today().year, 1, 1), + 'date_to': date(date.today().year, 12, 31), 'company_id': self.company.id, 'journal_ids': [(6, 0, self.journal_sale.ids)] } diff --git a/account_financial_report/tests/test_open_items.py b/account_financial_report/tests/test_open_items.py index 5456c135..2b686771 100644 --- a/account_financial_report/tests/test_open_items.py +++ b/account_financial_report/tests/test_open_items.py @@ -2,7 +2,7 @@ # Copyright 2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import time +from datetime import date from . import abstract_test_foreign_currency as a_t_f_c @@ -28,7 +28,7 @@ class TestOpenItems(a_t_f_c.AbstractTestForeignCurrency): def _getBaseFilters(self): return { - 'date_at': time.strftime('%Y-12-31'), + 'date_at': date(date.today().year, 12, 31), 'company_id': self.company.id, 'foreign_currency': True, } diff --git a/account_financial_report/tests/test_trial_balance.py b/account_financial_report/tests/test_trial_balance.py index 90b66422..47c432cf 100644 --- a/account_financial_report/tests/test_trial_balance.py +++ b/account_financial_report/tests/test_trial_balance.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import time - +from datetime import date from odoo.tests import common from . import abstract_test_foreign_currency as a_t_f_c @@ -30,10 +30,10 @@ class TestTrialBalance(a_t_f_c.AbstractTestForeignCurrency): def _getBaseFilters(self): return { - 'date_from': time.strftime('%Y-01-01'), - 'date_to': time.strftime('%Y-12-31'), + 'date_from': date(date.today().year, 1, 1), + 'date_to': date(date.today().year, 12, 31), 'company_id': self.company.id, - 'fy_start_date': time.strftime('%Y-01-01'), + 'fy_start_date': date(date.today().year, 1, 1), 'foreign_currency': True, 'show_partner_details': True, } diff --git a/account_financial_report/tests/test_vat_report.py b/account_financial_report/tests/test_vat_report.py index a2b6e570..f0cdef99 100644 --- a/account_financial_report/tests/test_vat_report.py +++ b/account_financial_report/tests/test_vat_report.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import time - +from datetime import date from odoo.tests import common from . import abstract_test_tax_report @@ -29,8 +29,8 @@ class TestVAT(abstract_test_tax_report.AbstractTest): def _getBaseFilters(self): return { - 'date_from': time.strftime('%Y-01-01'), - 'date_to': time.strftime('%Y-12-31'), + 'date_from': date(date.today().year, 1, 1), + 'date_to': date(date.today().year, 12, 31), 'company_id': self.env.user.company_id.id, } @@ -157,7 +157,7 @@ class TestVATReport(common.TransactionCase): def _get_report_lines(self): self.cbinvoice.pay_and_reconcile( - self.bank_journal.id, 300, time.strftime('%Y-%m-10')) + self.bank_journal.id, 300, date(date.today().year, date.today().month, 10)) vat_report = self.env['report_vat_report'].create({ 'date_from': self.date_from, 'date_to': self.date_to, @@ -274,8 +274,8 @@ class TestVATReport(common.TransactionCase): 'date_to': time.strftime('%Y-%m-01'), 'tax_detail': True}) wizard.onchange_date_range_id() - self.assertEqual(wizard.date_from, time.strftime('%Y-%m-01')) - self.assertEqual(wizard.date_to, time.strftime('%Y-%m-28')) + self.assertEqual(wizard.date_from, date(date.today().year, 1, 1)) + self.assertEqual(wizard.date_to, date(date.today().year, date.today().month, 28)) wizard._export('qweb-pdf') wizard.button_export_html() wizard.button_export_pdf() @@ -287,8 +287,8 @@ class TestVATReport(common.TransactionCase): 'based_on': 'taxgroups', 'tax_detail': True}) wizard.onchange_date_range_id() - self.assertEqual(wizard.date_from, time.strftime('%Y-%m-01')) - self.assertEqual(wizard.date_to, time.strftime('%Y-%m-28')) + self.assertEqual(wizard.date_from, date(date.today().year, 1, 1)) + self.assertEqual(wizard.date_to, date(date.today().year, date.today().month, 28)) wizard._export('qweb-pdf') wizard.button_export_html() wizard.button_export_pdf() diff --git a/account_financial_report/wizard/general_ledger_wizard.py b/account_financial_report/wizard/general_ledger_wizard.py index de119dac..35b6acac 100644 --- a/account_financial_report/wizard/general_ledger_wizard.py +++ b/account_financial_report/wizard/general_ledger_wizard.py @@ -9,9 +9,10 @@ from odoo import api, fields, models, _ from odoo.tools.safe_eval import safe_eval -from odoo.tools import pycompat +from odoo.tools import pycompat, DEFAULT_SERVER_DATE_FORMAT from odoo.exceptions import ValidationError import time +from datetime import datetime class GeneralLedgerReportWizard(models.TransientModel): @@ -121,7 +122,7 @@ class GeneralLedgerReportWizard(models.TransientModel): for wiz in self.filtered('date_from'): date = fields.Datetime.from_string(wiz.date_from) res = self.company_id.compute_fiscalyear_dates(date) - wiz.fy_start_date = res['date_from'] + wiz.fy_start_date = datetime.strftime(res['date_from'], DEFAULT_SERVER_DATE_FORMAT) @api.onchange('company_id') def onchange_company_id(self): diff --git a/account_financial_report/wizard/trial_balance_wizard.py b/account_financial_report/wizard/trial_balance_wizard.py index f9eac02f..d5873297 100644 --- a/account_financial_report/wizard/trial_balance_wizard.py +++ b/account_financial_report/wizard/trial_balance_wizard.py @@ -6,9 +6,9 @@ from odoo import api, fields, models, _ from odoo.tools.safe_eval import safe_eval -from odoo.tools import pycompat +from odoo.tools import pycompat, DEFAULT_SERVER_DATE_FORMAT from odoo.exceptions import UserError, ValidationError - +from datetime import datetime class TrialBalanceReportWizard(models.TransientModel): """Trial balance report wizard.""" @@ -98,7 +98,7 @@ class TrialBalanceReportWizard(models.TransientModel): for wiz in self.filtered('date_from'): date = fields.Datetime.from_string(wiz.date_from) res = self.company_id.compute_fiscalyear_dates(date) - wiz.fy_start_date = res['date_from'] + wiz.fy_start_date = datetime.strftime(res['date_from'], DEFAULT_SERVER_DATE_FORMAT) @api.onchange('company_id') def onchange_company_id(self):