Files
odoo_source/addons/account/tests/test_templates_consistency.py
T
jbw 5ad660877f [IMP] account: Improve reconciliation Models usability
This task aims to both explain supported reconciliation cases and improve the reconciliation model form view.
The form improvement is mainly about label wording and make the options more self speaking.

Also, disable bypass of the matching amount we do in case the statement line's label exactly matches the payment reference.
It can be replaced by just making a final model that is applied whatever the amount and will do the partial reconciliation on everything that wasn't matched by others.
That's cleaner, as users can way more predict what models can do and debug their config.

closes odoo/odoo#73043

Task: 2427089
Related: odoo/upgrade#2729
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
2021-09-01 20:57:00 +00:00

86 lines
5.0 KiB
Python

# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
class AccountingTestTemplConsistency(TransactionCase):
'''Test the templates consistency between some objects like account.account when account.account.template.
'''
def get_model_fields(self, model, extra_domain=None):
# Retrieve fields to compare
domain = [
('model', '=', model),
('state', '=', 'base'),
('related', '=', False),
('compute', '=', False),
('store', '=', True),
]
if extra_domain:
domain += extra_domain
return self.env['ir.model.fields'].search(domain)
def check_fields_consistency(self, model_from, model_to, exceptions=None):
'''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.
'''
extra_domain = [('name', 'not in', exceptions)] if exceptions else []
from_fields = self.get_model_fields(model_from, extra_domain=extra_domain).filtered_domain([('modules', '=', 'account')])
to_fields_set = set([f.name for f in self.get_model_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', 'opening_debit', 'opening_credit', 'allowed_journal_ids', 'group_id', 'root_id', 'is_off_balance'])
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', exceptions=['company_id', 'country_id'])
self.check_fields_consistency('account.tax.repartition.line.template', 'account.tax.repartition.line', exceptions=['plus_report_line_ids', 'minus_report_line_ids'])
self.check_fields_consistency('account.tax.repartition.line', 'account.tax.repartition.line.template', exceptions=['tag_ids', 'country_id', 'company_id', 'sequence'])
def test_fiscal_position_fields(self):
'''Test fields consistency for ('account.fiscal.position', 'account.fiscal.position.template')
'''
#main
self.check_fields_consistency('account.fiscal.position.template', 'account.fiscal.position', exceptions=['chart_template_id'])
self.check_fields_consistency('account.fiscal.position', 'account.fiscal.position.template', exceptions=['active', 'company_id', 'states_count', 'foreign_vat'])
#taxes
self.check_fields_consistency('account.fiscal.position.tax.template', 'account.fiscal.position.tax')
self.check_fields_consistency('account.fiscal.position.tax', 'account.fiscal.position.tax.template')
#accounts
self.check_fields_consistency('account.fiscal.position.account.template', 'account.fiscal.position.account')
self.check_fields_consistency('account.fiscal.position.account', 'account.fiscal.position.account.template')
def test_reconcile_model_fields(self):
'''Test fields consistency for ('account.reconcile.model', 'account.reconcile.model.template')
'''
self.check_fields_consistency('account.reconcile.model.template', 'account.reconcile.model', exceptions=['chart_template_id'])
# exclude fields from inherited 'mail.thread'
mail_thread_fields = [field.name for field in self.get_model_fields('mail.thread')]
self.check_fields_consistency(
'account.reconcile.model',
'account.reconcile.model.template',
exceptions=mail_thread_fields + ['active', 'company_id', 'past_months_limit', 'partner_mapping_line_ids'],
)
# lines
self.check_fields_consistency('account.reconcile.model.line.template', 'account.reconcile.model.line', exceptions=['chart_template_id'])
self.check_fields_consistency('account.reconcile.model.line', 'account.reconcile.model.line.template', exceptions=['company_id', 'journal_id', 'analytic_account_id', 'analytic_tag_ids', 'amount'])
def test_account_group_fields(self):
'''Test fields consistency for ('account.group', 'account.group.template')
'''
self.check_fields_consistency('account.group', 'account.group.template', exceptions=['company_id', 'parent_path'])
self.check_fields_consistency('account.group.template', 'account.group', exceptions=['chart_template_id'])