Goal:
* Simplified modifiers to only have one way to define modifiers;
* Remove states attributes on python field;
* Use python expression in view `required`, `readonly`, `invisible`;
* More accurate validation of xml views.
This commit change the syntax to python expression. The next commit
will update/convert all xml views.
Before this commit:
* the `required`, `readonly` and `invisible` attributes can only have
values of `True`, `False`, 1, 0 or a python expression to use the
context;
* the `attrs` attribute define a dict. The key of this dict was
`required`, `readonly` and `invisible` and the values are the domain or
a string representing a domain to be evaluate as python expression.
This python expressions was evaluate by the javascript with view fields
and other contextual values as: context, uid, parent, active_id,
active_ids, active_model, allowed_company_ids, current_company_id.
* the `states` attribute in the view was a comma separated list of the
state. This list was combined with the `invisible` attribute;
* the `invisible` attribute on python field is used as default value;
* the `states` attribute on python field was dictionnary with state as
key and list of tuple. This structure was combined with `readonly` view
attribute.
* After combining, the resulting domains of the different attributes
`required`, `readonly` and `invisible` are evaluated with the values of
the fields. The `invisible` attributes is splitted into two use:
`invisible` and `column_invisible`.
After this commit:
* The attributes `required`, `readonly`, `invisible` and
`column_invisible` define python expression. This python expressions
are evaluate by the javascript with view fields and other contextual
values as: context, uid, parent, active_id, active_ids, active_model,
allowed_company_ids, current_company_id.
The domains can contains contextual value and will be evaluate by the
javascript.
```xml
<field name="field_a" readonly="not context.get('show_a')" attrs="{'readonly': [('field_b', '!=', False), ('field_c', '=', parent.c)]}"/>
<field name="field_b" states="draft"/>
```
will be replaced by
```xml
<field name="field_a" readonly="not context.get('show_a') or field_b and field_c == parent.c"/>
<field name="field_b" invisible="state != 'draft'"/>
```
Some inherited views will be modified differently in order to maintain
the previous behavior:
```xml
<field name="field_a" readonly="not context.get('show_a')" attrs="{'invisible': [('field_b', '!=', False)]}">
```
```xml
<field name="field_a" position="attributes">
<attribute name="attrs">{'readonly': [('field_c', '=', False)], 'invisible': [('field_d', '!=', '3')]}<attribute>
</field>
```
will be replaced by
```xml
<field name="field_a" readonly="not context.get('show_a')" invisible="field_b">
```
```xml
<field name="field_a" position="attributes">
<attribute name="readonly" add="(not field_c)" separator=" or "/>
<attribute name="invisible">field_d != 3<attribute>
</field>
```
Validation:
A stricter control is made on the level of the attributes (modifiers)
and the fields necessary for these. The use of the previous attributes
'attr' and 'states' triggers an error (these no longer exist after the
application of the migration script)
task-2495504
Part-of: odoo/odoo#104741
76 lines
3.1 KiB
Python
76 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.tests import TransactionCase, tagged, Form
|
|
|
|
|
|
@tagged('-at_install', 'post_install')
|
|
class TestFormCreate(TransactionCase):
|
|
"""
|
|
Test that the basic Odoo models records can be created on
|
|
the interface.
|
|
"""
|
|
|
|
def test_create_res_partner(self):
|
|
# YTI: Clean that brol
|
|
if hasattr(self.env['res.partner'], 'property_account_payable_id'):
|
|
# Required for `property_account_payable_id`, `property_account_receivable_id` to be visible in the view
|
|
# By default, it's the `group` `group_account_readonly` which is required to see it, in the `account` module
|
|
# But once `account_accountant` gets installed, it becomes `account.group_account_manager`
|
|
# https://github.com/odoo/enterprise/blob/bfa643278028da0bfabded2f87ccb7e323d697c1/account_accountant/views/product_views.xml#L9
|
|
self.env.user.groups_id += self.env.ref('account.group_account_readonly')
|
|
self.env.user.groups_id += self.env.ref('account.group_account_manager')
|
|
partner_form = Form(self.env['res.partner'])
|
|
partner_form.name = 'a partner'
|
|
# YTI: Clean that brol
|
|
if hasattr(self.env['res.partner'], 'property_account_payable_id'):
|
|
property_account_payable_id = self.env['account.account'].create({
|
|
'name': 'Test Account',
|
|
'account_type': 'liability_payable',
|
|
'code': 'TestAccountPayable',
|
|
'reconcile': True
|
|
})
|
|
property_account_receivable_id = self.env['account.account'].create({
|
|
'name': 'Test Account',
|
|
'account_type': 'asset_receivable',
|
|
'code': 'TestAccountReceivable',
|
|
'reconcile': True
|
|
})
|
|
partner_form.property_account_payable_id = property_account_payable_id
|
|
partner_form.property_account_receivable_id = property_account_receivable_id
|
|
partner_form.save()
|
|
|
|
def test_create_res_users(self):
|
|
user_form = Form(self.env['res.users'])
|
|
user_form.login = 'a user login'
|
|
user_form.name = 'a user name'
|
|
user_form.save()
|
|
|
|
def test_create_res_company(self):
|
|
company_form = Form(self.env['res.company'])
|
|
company_form.name = 'a company'
|
|
company_form.save()
|
|
|
|
def test_create_res_group(self):
|
|
group_form = Form(self.env['res.groups'])
|
|
group_form.name = 'a group'
|
|
group_form.save()
|
|
|
|
def test_create_res_bank(self):
|
|
bank_form = Form(self.env['res.bank'])
|
|
bank_form.name = 'a bank'
|
|
bank_form.save()
|
|
|
|
def test_create_res_country(self):
|
|
country_form = Form(self.env['res.country'])
|
|
country_form.name = 'a country'
|
|
country_form.code = 'ZX'
|
|
country_form.save()
|
|
|
|
def test_create_res_lang(self):
|
|
lang_form = Form(self.env['res.lang'])
|
|
# lang_form.url_code = 'LANG' # invisible field, tested in http_routing
|
|
lang_form.name = 'a lang name'
|
|
lang_form.code = 'a lang code'
|
|
lang_form.save()
|