summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2020-01-23 07:33:43 +0000
committerLaurent Smet <las@odoo.com>2020-04-15 17:25:39 +0000
commit5a99ddf88bfd36bb6004c2dccf2a46c6bfbb5141 (patch)
tree6c0e070a2214f952705bf0b0912161f914f2a0b0
parent65b798b46160e74ed87829583b7a9bb46233081f (diff)
[IMP] account: Improve testing class for account_reports
closes odoo/odoo#44493 Related: odoo/enterprise#8114 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
-rw-r--r--addons/account/models/account_tax.py2
-rw-r--r--addons/account/tests/common.py38
2 files changed, 30 insertions, 10 deletions
diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py
index 6834bc43f49..2939bbdbe6f 100644
--- a/addons/account/models/account_tax.py
+++ b/addons/account/models/account_tax.py
@@ -67,7 +67,7 @@ class AccountTax(models.Model):
string='Children Taxes')
sequence = fields.Integer(required=True, default=1,
help="The sequence field is used to define order in which the tax lines are applied.")
- amount = fields.Float(required=True, digits=(16, 4))
+ amount = fields.Float(required=True, digits=(16, 4), default=0.0)
description = fields.Char(string='Label on Invoices')
price_include = fields.Boolean(string='Included in Price', default=False,
help="Check this if the price you use on the product and invoices includes this tax.")
diff --git a/addons/account/tests/common.py b/addons/account/tests/common.py
index a0c3d87fee2..a05a1c468e0 100644
--- a/addons/account/tests/common.py
+++ b/addons/account/tests/common.py
@@ -637,6 +637,12 @@ class AccountTestInvoicingCommon(SavepointCase):
cls.cr = cls.env.cr
cls.company_data = cls.setup_company_data('company_1_data')
+
+ user.write({
+ 'company_ids': [(6, 0, cls.company_data['company'].ids)],
+ 'company_id': cls.company_data['company'].id,
+ })
+
cls.currency_data = cls.setup_multi_currency_data()
# ==== Taxes ====
@@ -760,20 +766,31 @@ class AccountTestInvoicingCommon(SavepointCase):
:param company_name: The name of the company.
:return: A dictionary will be returned containing all relevant accounting data for testing.
'''
+ def search_account(company, chart_template, field_name, domain):
+ template_code = chart_template[field_name].code
+ domain = [('company_id', '=', company.id)] + domain
+
+ account = None
+ if template_code:
+ account = cls.env['account.account'].search(domain + [('code', '=like', template_code + '%')], limit=1)
+
+ if not account:
+ account = cls.env['account.account'].search(domain, limit=1)
+ return account
+
chart_template = cls.env.user.company_id.chart_template_id
+ currency = cls.env.user.company_id.currency_id
company = cls.env['res.company'].create({
'name': company_name,
- 'currency_id': cls.env.user.company_id.currency_id.id,
+ 'currency_id': currency.id,
**kwargs,
})
cls.env.user.company_ids |= company
- cls.env.user.company_id = company
- chart_template = cls.env['account.chart.template'].browse(chart_template.id)
- chart_template.try_loading()
+ chart_template.with_company(company).try_loading()
# The currency could be different after the installation of the chart template.
- company.write({'currency_id': kwargs.get('currency_id', cls.env.user.company_id.currency_id.id)})
+ company.write({'currency_id': kwargs.get('currency_id', currency.id)})
return {
'company': company,
@@ -786,14 +803,17 @@ class AccountTestInvoicingCommon(SavepointCase):
('company_id', '=', company.id),
('user_type_id', '=', cls.env.ref('account.data_account_type_expenses').id)
], limit=1),
- 'default_account_receivable': cls.env['account.account'].search([
- ('company_id', '=', company.id),
- ('user_type_id.type', '=', 'receivable')
- ], limit=1),
+ 'default_account_receivable': search_account(company, chart_template, 'property_account_receivable_id', [
+ ('user_type_id.type', '=', 'receivable')
+ ]),
'default_account_payable': cls.env['account.account'].search([
('company_id', '=', company.id),
('user_type_id.type', '=', 'payable')
], limit=1),
+ 'default_account_assets': cls.env['account.account'].search([
+ ('company_id', '=', company.id),
+ ('user_type_id', '=', cls.env.ref('account.data_account_type_current_assets').id)
+ ], limit=1),
'default_account_tax_sale': company.account_sale_tax_id.mapped('invoice_repartition_line_ids.account_id'),
'default_account_tax_purchase': company.account_purchase_tax_id.mapped('invoice_repartition_line_ids.account_id'),
'default_journal_misc': cls.env['account.journal'].search([