Set all fields readonly for inactive records

issue3747
review295061011
This commit is contained in:
Cédric Krier committed 2020-03-17 20:08:12 +01:00
1 parent 3d4156dd49
commit 7925dab37d
4 files changed
+39 -66

No files matched your search

+9 -16
View File
@@ -20,29 +20,23 @@ from trytond.transaction import Transaction
from trytond.cache import Cache
from .exceptions import InvalidFormat
STATES = {
'readonly': ~Eval('active'),
}
DEPENDS = ['active']
class Address(DeactivableMixin, sequence_ordered(), ModelSQL, ModelView):
"Address"
__name__ = 'party.address'
party = fields.Many2One('party.party', 'Party', required=True,
ondelete='CASCADE', select=True, states={
'readonly': If(~Eval('active'), True, Eval('id', 0) > 0),
'readonly': Eval('id', 0) > 0,
},
depends=['active', 'id'])
depends=['id'])
party_name = fields.Char(
"Party Name", states=STATES, depends=DEPENDS,
"Party Name",
help="If filled, replace the name of the party for address formatting")
name = fields.Char("Building Name", states=STATES, depends=DEPENDS)
street = fields.Text("Street", states=STATES, depends=DEPENDS)
zip = fields.Char('Zip', states=STATES, depends=DEPENDS)
city = fields.Char('City', states=STATES, depends=DEPENDS)
country = fields.Many2One('country.country', 'Country',
states=STATES, depends=DEPENDS)
name = fields.Char("Building Name")
street = fields.Text("Street")
zip = fields.Char("Zip")
city = fields.Char("City")
country = fields.Many2One('country.country', "Country")
subdivision_types = fields.Function(
fields.MultiSelection(
'get_subdivision_types', "Subdivision Types"),
@@ -56,8 +50,7 @@ class Address(DeactivableMixin, sequence_ordered(), ModelSQL, ModelView):
()
),
],
states=STATES,
depends=['active', 'country', 'subdivision_types'])
depends=['country', 'subdivision_types'])
full_address = fields.Function(fields.Text('Full Address'),
'get_full_address')
+6 -12
View File
@@ -5,25 +5,19 @@ from sql.operators import Equal
from trytond.model import (
ModelView, ModelSQL, DeactivableMixin, fields, Exclude, tree)
from trytond.pyson import Eval
STATES = {
'readonly': ~Eval('active'),
}
DEPENDS = ['active']
class Category(DeactivableMixin, tree(separator=' / '), ModelSQL, ModelView):
"Category"
__name__ = 'party.category'
name = fields.Char('Name', required=True, states=STATES, translate=True,
depends=DEPENDS,
name = fields.Char(
"Name", required=True, translate=True,
help="The main identifier of the category.")
parent = fields.Many2One('party.category', 'Parent',
select=True, states=STATES, depends=DEPENDS,
parent = fields.Many2One(
'party.category', "Parent", select=True,
help="Add the category below the parent.")
childs = fields.One2Many('party.category', 'parent',
'Children', states=STATES, depends=DEPENDS,
childs = fields.One2Many(
'party.category', 'parent', "Children",
help="Add children below the category.")
@classmethod
+14 -23
View File
@@ -14,11 +14,6 @@ from trytond.model.exceptions import AccessError
from trytond.pyson import Eval
from .exceptions import InvalidPhoneNumber
STATES = {
'readonly': ~Eval('active'),
}
DEPENDS = ['active']
_TYPES = [
('phone', 'Phone'),
('mobile', 'Mobile'),
@@ -44,45 +39,41 @@ class ContactMechanism(
"Contact Mechanism"
__name__ = 'party.contact_mechanism'
type = fields.Selection(_TYPES, 'Type', required=True, states=STATES,
sort=False, depends=DEPENDS)
value = fields.Char('Value', select=True, states=STATES, depends=DEPENDS
type = fields.Selection(_TYPES, "Type", required=True, sort=False)
value = fields.Char("Value", select=True,
# Add all function fields to ensure to always fill them via on_change
+ ['email', 'website', 'skype', 'sip', 'other_value', 'value_compact'])
depends=[
'email', 'website', 'skype', 'sip', 'other_value',
'value_compact'])
value_compact = fields.Char('Value Compact', readonly=True)
name = fields.Char("Name", states=STATES, depends=DEPENDS)
comment = fields.Text('Comment', states=STATES, depends=DEPENDS)
party = fields.Many2One('party.party', 'Party', required=True,
ondelete='CASCADE', states=STATES, select=True, depends=DEPENDS)
name = fields.Char("Name")
comment = fields.Text("Comment")
party = fields.Many2One(
'party.party', "Party", required=True, ondelete='CASCADE', select=True)
email = fields.Function(fields.Char('E-Mail', states={
'invisible': Eval('type') != 'email',
'required': Eval('type') == 'email',
'readonly': ~Eval('active', True),
}, depends=['value', 'type', 'active']),
}, depends=['value', 'type']),
'get_value', setter='set_value')
website = fields.Function(fields.Char('Website', states={
'invisible': Eval('type') != 'website',
'required': Eval('type') == 'website',
'readonly': ~Eval('active', True),
}, depends=['value', 'type', 'active']),
}, depends=['value', 'type']),
'get_value', setter='set_value')
skype = fields.Function(fields.Char('Skype', states={
'invisible': Eval('type') != 'skype',
'required': Eval('type') == 'skype',
'readonly': ~Eval('active', True),
}, depends=['value', 'type', 'active']),
}, depends=['value', 'type']),
'get_value', setter='set_value')
sip = fields.Function(fields.Char('SIP', states={
'invisible': Eval('type') != 'sip',
'required': Eval('type') == 'sip',
'readonly': ~Eval('active', True),
}, depends=['value', 'type', 'active']),
}, depends=['value', 'type']),
'get_value', setter='set_value')
other_value = fields.Function(fields.Char('Value', states={
'invisible': Eval('type').in_(['email', 'website', 'skype', 'sip']),
'required': ~Eval('type').in_(['email', 'website']),
'readonly': ~Eval('active', True),
}, depends=['value', 'type', 'active']),
}, depends=['value', 'type']),
'get_value', setter='set_value')
url = fields.Function(fields.Char('URL', states={
'invisible': ~Eval('url'),
+10 -15
View File
@@ -18,17 +18,13 @@ from trytond.tools import lstrip_wildcard
from .exceptions import (
InvalidIdentifierCode, VIESUnavailable, SimilarityWarning, EraseError)
STATES = {
'readonly': ~Eval('active', True),
}
DEPENDS = ['active']
class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin):
"Party"
__name__ = 'party.party'
name = fields.Char('Name', select=True, states=STATES, depends=DEPENDS,
name = fields.Char(
"Name", select=True,
help="The main identifier of the party.")
code = fields.Char('Code', required=True, select=True,
states={
@@ -39,23 +35,22 @@ class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin):
code_readonly = fields.Function(fields.Boolean('Code Readonly'),
'get_code_readonly')
lang = fields.MultiValue(
fields.Many2One('ir.lang', "Language", states=STATES, depends=DEPENDS,
fields.Many2One('ir.lang', "Language",
help="Used to translate communications with the party."))
langs = fields.One2Many(
'party.party.lang', 'party', "Languages")
identifiers = fields.One2Many('party.identifier', 'party', 'Identifiers',
states=STATES, depends=DEPENDS,
identifiers = fields.One2Many(
'party.identifier', 'party', "Identifiers",
help="Add other identifiers of the party.")
tax_identifier = fields.Function(fields.Many2One(
'party.identifier', 'Tax Identifier',
help="The identifier used for tax report."),
'get_tax_identifier', searcher='search_tax_identifier')
addresses = fields.One2Many('party.address', 'party',
'Addresses', states=STATES, depends=DEPENDS)
contact_mechanisms = fields.One2Many('party.contact_mechanism', 'party',
'Contact Mechanisms', states=STATES, depends=DEPENDS)
categories = fields.Many2Many('party.party-party.category',
'party', 'category', 'Categories', states=STATES, depends=DEPENDS,
addresses = fields.One2Many('party.address', 'party', "Addresses")
contact_mechanisms = fields.One2Many(
'party.contact_mechanism', 'party', "Contact Mechanisms")
categories = fields.Many2Many(
'party.party-party.category', 'party', 'category', "Categories",
help="The categories the party belongs to.")
replaced_by = fields.Many2One('party.party', "Replaced By", readonly=True,
states={