changeset 33c09e388568 in modules/party:default
details: https://hg.tryton.org/modules/party?cmd=changeset;node=33c09e388568
description:
        Set all fields readonly for inactive records

        issue3747
        review295061011
diffstat:

 address.py           |  25 +++++++++----------------
 category.py          |  18 ++++++------------
 contact_mechanism.py |  37 ++++++++++++++-----------------------
 party.py             |  25 ++++++++++---------------
 4 files changed, 39 insertions(+), 66 deletions(-)

diffs (216 lines):

diff -r b911d02f3245 -r 33c09e388568 address.py
--- a/address.py        Sun Mar 01 16:12:39 2020 +0100
+++ b/address.py        Tue Mar 17 20:08:12 2020 +0100
@@ -20,29 +20,23 @@
 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 @@
                 ()
                 ),
             ],
-        states=STATES,
-        depends=['active', 'country', 'subdivision_types'])
+        depends=['country', 'subdivision_types'])
     full_address = fields.Function(fields.Text('Full Address'),
             'get_full_address')
 
diff -r b911d02f3245 -r 33c09e388568 category.py
--- a/category.py       Sun Mar 01 16:12:39 2020 +0100
+++ b/category.py       Tue Mar 17 20:08:12 2020 +0100
@@ -5,25 +5,19 @@
 
 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
diff -r b911d02f3245 -r 33c09e388568 contact_mechanism.py
--- a/contact_mechanism.py      Sun Mar 01 16:12:39 2020 +0100
+++ b/contact_mechanism.py      Tue Mar 17 20:08:12 2020 +0100
@@ -14,11 +14,6 @@
 from trytond.pyson import Eval
 from .exceptions import InvalidPhoneNumber
 
-STATES = {
-    'readonly': ~Eval('active'),
-    }
-DEPENDS = ['active']
-
 _TYPES = [
     ('phone', 'Phone'),
     ('mobile', 'Mobile'),
@@ -44,45 +39,41 @@
     "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'),
diff -r b911d02f3245 -r 33c09e388568 party.py
--- a/party.py  Sun Mar 01 16:12:39 2020 +0100
+++ b/party.py  Tue Mar 17 20:08:12 2020 +0100
@@ -18,17 +18,13 @@
 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 @@
     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={

Reply via email to