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
66 lines
2.8 KiB
Python
66 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.crm.tests.common import TestCrmCommon
|
|
from odoo.tests.common import Form
|
|
from odoo.tests import tagged, users
|
|
|
|
|
|
@tagged('res_partner')
|
|
class TestPartner(TestCrmCommon):
|
|
|
|
@users('user_sales_leads')
|
|
def test_parent_sync_sales_rep(self):
|
|
""" Test team_id / user_id sync from parent to children if the contact
|
|
is a person. Company children are not updated. """
|
|
contact_company = self.contact_company.with_env(self.env)
|
|
contact_company_1 = self.contact_company_1.with_env(self.env)
|
|
self.assertFalse(contact_company.team_id)
|
|
self.assertFalse(contact_company.user_id)
|
|
self.assertFalse(contact_company_1.team_id)
|
|
self.assertFalse(contact_company_1.user_id)
|
|
|
|
child = self.contact_1.with_env(self.env)
|
|
self.assertEqual(child.parent_id, self.contact_company_1)
|
|
self.assertFalse(child.team_id)
|
|
self.assertFalse(child.user_id)
|
|
|
|
# update comppany sales rep info
|
|
contact_company.user_id = self.env.uid
|
|
contact_company.team_id = self.sales_team_1.id
|
|
|
|
# change child parent: shold update sales rep info
|
|
child.parent_id = contact_company.id
|
|
self.assertEqual(child.user_id, self.env.user)
|
|
|
|
# test form tool
|
|
# <field name="team_id" groups="base.group_no_one"/>
|
|
with self.debug_mode():
|
|
partner_form = Form(self.env['res.partner'], 'base.view_partner_form')
|
|
partner_form.parent_id = contact_company
|
|
partner_form.company_type = 'person'
|
|
partner_form.name = 'Hermes Conrad'
|
|
self.assertEqual(partner_form.team_id, self.sales_team_1)
|
|
self.assertEqual(partner_form.user_id, self.env.user)
|
|
partner_form.parent_id = contact_company_1
|
|
self.assertEqual(partner_form.team_id, self.sales_team_1)
|
|
self.assertEqual(partner_form.user_id, self.env.user)
|
|
|
|
# test form tool
|
|
# <field name="team_id" groups="base.group_no_one"/>
|
|
with self.debug_mode():
|
|
partner_form = Form(self.env['res.partner'], 'base.view_partner_form')
|
|
# `parent_id` is invisible when `is_company` is True (`company_type == 'company'`)
|
|
# and parent_id is not set
|
|
# So, set a temporary `parent_id` before setting the contact as company
|
|
# to make `parent_id` visible in the interface while being a company
|
|
# <field name="parent_id"
|
|
# invisible="(is_company and not parent_id or company_name) and company_name != ''"
|
|
# />
|
|
partner_form.parent_id = contact_company_1
|
|
partner_form.company_type = 'company'
|
|
partner_form.parent_id = contact_company
|
|
partner_form.name = 'Mom Corp'
|
|
self.assertFalse(partner_form.team_id)
|
|
self.assertFalse(partner_form.user_id)
|