From 515ac8e2ae293e4cb21ca3f237dd136793d0caff Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Tue, 11 Apr 2017 15:21:34 +0200 Subject: [PATCH] [ADD] account: add test to check objects consistency when created from templates For example, we had in the past fields added on account.account but not on account.account.template. The purpose of the new test is to detect such oversight (force developpers to explicitly name exceptions in the test). Was PR #16012 task ID: 31488 --- addons/account/tests/__init__.py | 1 + .../tests/test_templates_consistency.py | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 addons/account/tests/test_templates_consistency.py diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py index d51139e91c7..e8758501547 100644 --- a/addons/account/tests/__init__.py +++ b/addons/account/tests/__init__.py @@ -15,3 +15,4 @@ from . import test_product_id_change from . import test_reconciliation from . import test_search from . import test_tax +from . import test_templates_consistency diff --git a/addons/account/tests/test_templates_consistency.py b/addons/account/tests/test_templates_consistency.py new file mode 100644 index 00000000000..0def722e2d7 --- /dev/null +++ b/addons/account/tests/test_templates_consistency.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from odoo.tests.common import HttpCase + + +class AccountingTestTemplConsistency(HttpCase): + '''Test the templates consistency between some objects like account.account when account.account.template. + ''' + + def check_fields_consistency(self, model_from, model_to, exceptions=[]): + '''Check the consistency of fields from one model to another by comparing if all fields + in the model_from are present in the model_to. + :param model_from: The model to compare. + :param model_to: The compared model. + :param exceptions: Not copied model's fields. + ''' + + def get_fields(model, extra_domain=None): + # Retrieve fields to compare + domain = [('model', '=', model), ('state', '=', 'base'), ('related', '=', False), + ('compute', '=', False)] + if extra_domain: + domain += extra_domain + return self.env['ir.model.fields'].search(domain) + + from_fields = get_fields(model_from, extra_domain=[('name', 'not in', exceptions)]) + to_fields_set = set([f.name for f in get_fields(model_to)]) + for field in from_fields: + assert field.name in to_fields_set,\ + 'Missing field "%s" from "%s" in model "%s".' % (field.name, model_from, model_to) + + def test_account_account_fields(self): + '''Test fields consistency for ('account.account', 'account.account.template') + ''' + self.check_fields_consistency( + 'account.account.template', 'account.account', exceptions=['chart_template_id', 'nocreate']) + self.check_fields_consistency( + 'account.account', 'account.account.template', exceptions=['company_id', 'deprecated', 'last_time_entries_checked']) + + def test_account_tax_fields(self): + '''Test fields consistency for ('account.tax', 'account.tax.template') + ''' + self.check_fields_consistency('account.tax.template', 'account.tax', exceptions=['chart_template_id']) + self.check_fields_consistency('account.tax', 'account.tax.template')