From 10fe7ffc6610c6f7323733cb6c7923ee05b4e78b Mon Sep 17 00:00:00 2001 From: mreficent Date: Fri, 23 Mar 2018 15:42:04 +0100 Subject: [PATCH] [IMP] account_financial_report: adapt the wizards to multicompany --- account_financial_report/README.rst | 1 + account_financial_report/__manifest__.py | 2 +- .../readme/CONTRIBUTORS.rst | 1 + .../tests/test_vat_report.py | 27 ++++++++++------- .../wizard/aged_partner_balance_wizard.py | 14 ++++++++- .../aged_partner_balance_wizard_view.xml | 12 ++++++-- .../wizard/general_ledger_wizard.py | 29 +++++++++++++++++-- .../wizard/general_ledger_wizard_view.xml | 19 +++++++++--- .../wizard/open_items_wizard.py | 14 ++++++++- .../wizard/open_items_wizard_view.xml | 14 +++++++-- .../wizard/trial_balance_wizard.py | 25 ++++++++++++++-- .../wizard/trial_balance_wizard_view.xml | 20 +++++++++++-- .../wizard/vat_report_wizard.py | 20 ++++++++++++- 13 files changed, 167 insertions(+), 31 deletions(-) diff --git a/account_financial_report/README.rst b/account_financial_report/README.rst index cf1a8f08..9f04d5e8 100644 --- a/account_financial_report/README.rst +++ b/account_financial_report/README.rst @@ -97,6 +97,7 @@ Contributors * Akim Juillerat * Alexis de Lattre * Mihai Fekete +* Miquel Raïch Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report/__manifest__.py b/account_financial_report/__manifest__.py index cf1dfe4b..5ddf2a5c 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.3.1', + 'version': '11.0.2.4.0', 'category': 'Reporting', 'summary': 'OCA Financial Reports', 'author': 'Camptocamp SA,' diff --git a/account_financial_report/readme/CONTRIBUTORS.rst b/account_financial_report/readme/CONTRIBUTORS.rst index 4604fe42..10431f9e 100644 --- a/account_financial_report/readme/CONTRIBUTORS.rst +++ b/account_financial_report/readme/CONTRIBUTORS.rst @@ -14,6 +14,7 @@ * Akim Juillerat * Alexis de Lattre * Mihai Fekete +* Miquel Raïch Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report/tests/test_vat_report.py b/account_financial_report/tests/test_vat_report.py index 08648cdb..a2b6e570 100644 --- a/account_financial_report/tests/test_vat_report.py +++ b/account_financial_report/tests/test_vat_report.py @@ -48,22 +48,27 @@ class TestVATReport(common.TransactionCase): def setUp(self): super(TestVATReport, self).setUp() - self.date_from = time.strftime('%Y-%m-01'), - self.date_to = time.strftime('%Y-%m-28'), + self.date_from = time.strftime('%Y-%m-01') + self.date_to = time.strftime('%Y-%m-28') + self.company = self.env.ref('base.main_company') self.receivable_account = self.env['account.account'].search([ + ('company_id', '=', self.company.id), ('user_type_id.name', '=', 'Receivable') ], limit=1) self.income_account = self.env['account.account'].search([ + ('company_id', '=', self.company.id), ('user_type_id.name', '=', 'Income') ], limit=1) self.tax_account = self.env['account.account'].search([ + ('company_id', '=', self.company.id), ('user_type_id', '=', self.env.ref( - 'account.data_account_type_non_current_liabilities').id - )], limit=1) - self.bank_journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1) + 'account.data_account_type_non_current_liabilities').id) + ], limit=1) + self.bank_journal = self.env['account.journal'].search([ + ('type', '=', 'bank'), ('company_id', '=', self.company.id) + ], limit=1) self.tax_tag_01 = self.env['account.account.tag'].create({ 'name': 'Tag 01', 'applicability': 'taxes' @@ -90,6 +95,7 @@ class TestVATReport(common.TransactionCase): 'amount_type': 'percent', 'type_tax_use': 'sale', 'account_id': self.tax_account.id, + 'company_id': self.company.id, 'refund_account_id': self.tax_account.id, 'tax_group_id': self.tax_group_10.id, 'tag_ids': [(6, 0, [self.tax_tag_01.id, self.tax_tag_02.id])] @@ -102,6 +108,7 @@ class TestVATReport(common.TransactionCase): 'type_tax_use': 'sale', 'tax_exigibility': 'on_payment', 'account_id': self.tax_account.id, + 'company_id': self.company.id, 'refund_account_id': self.tax_account.id, 'cash_basis_account': self.tax_account.id, 'tax_group_id': self.tax_group_20.id, @@ -111,6 +118,7 @@ class TestVATReport(common.TransactionCase): invoice = self.env['account.invoice'].create({ 'partner_id': self.env.ref('base.res_partner_2').id, 'account_id': self.receivable_account.id, + 'company_id': self.company.id, 'date_invoice': time.strftime('%Y-%m-03'), 'type': 'out_invoice', }) @@ -130,6 +138,7 @@ class TestVATReport(common.TransactionCase): self.cbinvoice = self.env['account.invoice'].create({ 'partner_id': self.env.ref('base.res_partner_2').id, 'account_id': self.receivable_account.id, + 'company_id': self.company.id, 'date_invoice': time.strftime('%Y-%m-05'), 'type': 'out_invoice', }) @@ -147,13 +156,12 @@ class TestVATReport(common.TransactionCase): self.cbinvoice.action_invoice_open() def _get_report_lines(self): - company = self.env.ref('base.main_company') self.cbinvoice.pay_and_reconcile( self.bank_journal.id, 300, time.strftime('%Y-%m-10')) vat_report = self.env['report_vat_report'].create({ 'date_from': self.date_from, 'date_to': self.date_to, - 'company_id': company.id, + 'company_id': self.company.id, 'based_on': 'taxtags', 'tax_detail': True, }) @@ -238,11 +246,10 @@ class TestVATReport(common.TransactionCase): self.assertEqual(lines['tax_group_20'].tax, 50) def test_get_report_html(self): - company = self.env.ref('base.main_company') vat_report = self.env['report_vat_report'].create({ 'date_from': self.date_from, 'date_to': self.date_to, - 'company_id': company.id, + 'company_id': self.company.id, 'tax_detail': True, }) vat_report.compute_data_for_report() diff --git a/account_financial_report/wizard/aged_partner_balance_wizard.py b/account_financial_report/wizard/aged_partner_balance_wizard.py index 97d68691..c192c24b 100644 --- a/account_financial_report/wizard/aged_partner_balance_wizard.py +++ b/account_financial_report/wizard/aged_partner_balance_wizard.py @@ -17,6 +17,7 @@ class AgedPartnerBalanceWizard(models.TransientModel): company_id = fields.Many2one( comodel_name='res.company', default=lambda self: self.env.user.company_id, + required=True, string='Company' ) date_at = fields.Date(required=True, @@ -38,11 +39,22 @@ class AgedPartnerBalanceWizard(models.TransientModel): ) show_move_line_details = fields.Boolean() + @api.onchange('company_id') + def onchange_company_id(self): + """Handle company change.""" + if self.company_id and self.partner_ids: + self.partner_ids = self.partner_ids.filtered( + lambda p: p.company_id == self.company_id or + not p.company_id) + if self.company_id and self.account_ids: + self.account_ids = self.account_ids.filtered( + lambda a: a.company_id == self.company_id) + @api.onchange('receivable_accounts_only', 'payable_accounts_only') def onchange_type_accounts_only(self): """Handle receivable/payable accounts only change.""" if self.receivable_accounts_only or self.payable_accounts_only: - domain = [] + domain = [('company_id', '=', self.company_id.id)] if self.receivable_accounts_only and self.payable_accounts_only: domain += [('internal_type', 'in', ('receivable', 'payable'))] elif self.receivable_accounts_only: diff --git a/account_financial_report/wizard/aged_partner_balance_wizard_view.xml b/account_financial_report/wizard/aged_partner_balance_wizard_view.xml index a2e3196c..0b8c5863 100644 --- a/account_financial_report/wizard/aged_partner_balance_wizard_view.xml +++ b/account_financial_report/wizard/aged_partner_balance_wizard_view.xml @@ -21,15 +21,21 @@ -