diff --git a/address.py b/address.py index 8714bcfa45..edce573fe4 100644 --- a/address.py +++ b/address.py @@ -7,8 +7,9 @@ from sql import Null from sql.conditionals import Case, Coalesce from sql.operators import Concat -from trytond.model import ModelView, ModelSQL, MatchMixin, fields, \ - sequence_ordered +from trytond.model import ( + ModelView, ModelSQL, MatchMixin, DeactivableMixin, fields, + sequence_ordered) from trytond.pyson import Eval, If from trytond import backend from trytond.pool import Pool @@ -23,7 +24,7 @@ STATES = { DEPENDS = ['active'] -class Address(sequence_ordered(), ModelSQL, ModelView): +class Address(DeactivableMixin, sequence_ordered(), ModelSQL, ModelView): "Address" __name__ = 'party.address' party = fields.Many2One('party.party', 'Party', required=True, @@ -43,8 +44,6 @@ class Address(sequence_ordered(), ModelSQL, ModelView): ('parent', '=', None), ], states=STATES, depends=['active', 'country']) - active = fields.Boolean('Active', - help="Uncheck to exclude the address from future use.") full_address = fields.Function(fields.Text('Full Address'), 'get_full_address') @@ -78,10 +77,6 @@ class Address(sequence_ordered(), ModelSQL, ModelView): [value])) table.drop_column('streetbis') - @staticmethod - def default_active(): - return True - _autocomplete_limit = 100 def _autocomplete_domain(self): @@ -209,13 +204,11 @@ class Address(sequence_ordered(), ModelSQL, ModelView): self.subdivision = None -class AddressFormat(MatchMixin, ModelSQL, ModelView): +class AddressFormat(DeactivableMixin, MatchMixin, ModelSQL, ModelView): "Address Format" __name__ = 'party.address.format' country = fields.Many2One('country.country', "Country") language = fields.Many2One('ir.lang', "Language") - active = fields.Boolean("Active", - help="Uncheck to exclude the format from future use.") format_ = fields.Text("Format", required=True, help="Available variables (also in upper case):\n" "- ${party_name}\n" @@ -240,10 +233,6 @@ class AddressFormat(MatchMixin, ModelSQL, ModelView): 'with exception "%(exception)s".'), }) - @classmethod - def default_active(cls): - return True - @classmethod def default_format_(cls): return """${party_name} diff --git a/category.py b/category.py index 0f6acc1836..b31db88f4d 100644 --- a/category.py +++ b/category.py @@ -4,7 +4,8 @@ from sql.conditionals import Coalesce from sql.operators import Equal from trytond import backend -from trytond.model import ModelView, ModelSQL, fields, Exclude +from trytond.model import ( + ModelView, ModelSQL, DeactivableMixin, fields, Exclude) from trytond.pyson import Eval __all__ = ['Category'] @@ -17,7 +18,7 @@ DEPENDS = ['active'] SEPARATOR = ' / ' -class Category(ModelSQL, ModelView): +class Category(DeactivableMixin, ModelSQL, ModelView): "Category" __name__ = 'party.category' name = fields.Char('Name', required=True, states=STATES, translate=True, @@ -29,8 +30,6 @@ class Category(ModelSQL, ModelView): childs = fields.One2Many('party.category', 'parent', 'Children', states=STATES, depends=DEPENDS, help="Add children below the category.") - active = fields.Boolean('Active', - help="Uncheck to exclude the category from future use.") @classmethod def __setup__(cls): @@ -57,10 +56,6 @@ class Category(ModelSQL, ModelView): # Migration from 4.6: replace unique by exclude table_h.drop_constraint('name_parent_uniq') - @staticmethod - def default_active(): - return True - @classmethod def validate(cls, categories): super(Category, cls).validate(categories) diff --git a/contact_mechanism.py b/contact_mechanism.py index 3d62bb4f5b..32b7efe72e 100644 --- a/contact_mechanism.py +++ b/contact_mechanism.py @@ -6,7 +6,8 @@ try: except ImportError: phonenumbers = None -from trytond.model import ModelView, ModelSQL, fields, sequence_ordered +from trytond.model import ( + ModelView, ModelSQL, DeactivableMixin, fields, sequence_ordered) from trytond.pyson import Eval from trytond import backend @@ -37,7 +38,8 @@ _PHONE_TYPES = { } -class ContactMechanism(sequence_ordered(), ModelSQL, ModelView): +class ContactMechanism( + DeactivableMixin, sequence_ordered(), ModelSQL, ModelView): "Contact Mechanism" __name__ = 'party.contact_mechanism' _rec_name = 'value' @@ -52,8 +54,6 @@ class ContactMechanism(sequence_ordered(), ModelSQL, ModelView): comment = fields.Text('Comment', states=STATES, depends=DEPENDS) party = fields.Many2One('party.party', 'Party', required=True, ondelete='CASCADE', states=STATES, select=True, depends=DEPENDS) - active = fields.Boolean('Active', select=True, - help="Uncheck to exclude the contact mechanism from future use.") email = fields.Function(fields.Char('E-Mail', states={ 'invisible': Eval('type') != 'email', 'required': Eval('type') == 'email', @@ -116,10 +116,6 @@ class ContactMechanism(sequence_ordered(), ModelSQL, ModelView): def default_type(): return 'phone' - @staticmethod - def default_active(): - return True - @classmethod def get_value(cls, mechanisms, names): return dict((name, dict((m.id, m.value) for m in mechanisms)) diff --git a/party.py b/party.py index c667e49bb5..490ce79b7e 100644 --- a/party.py +++ b/party.py @@ -6,7 +6,7 @@ from sql import Null, Column, Cast, Literal from sql.functions import CharLength, Substring, Position from trytond.model import (ModelView, ModelSQL, MultiValueMixin, ValueMixin, - fields, Unique, sequence_ordered) + DeactivableMixin, fields, Unique, sequence_ordered) from trytond.wizard import Wizard, StateTransition, StateView, Button from trytond.pyson import Eval, Bool from trytond.transaction import Transaction @@ -26,7 +26,7 @@ STATES = { DEPENDS = ['active'] -class Party(ModelSQL, ModelView, MultiValueMixin): +class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin): "Party" __name__ = 'party.party' @@ -59,11 +59,6 @@ class Party(ModelSQL, ModelView, MultiValueMixin): categories = fields.Many2Many('party.party-party.category', 'party', 'category', 'Categories', states=STATES, depends=DEPENDS, help="The categories the party belongs to.") - active = fields.Boolean('Active', select=True, states={ - 'readonly': Bool(Eval('replaced_by')), - }, - depends=['replaced_by'], - help="Uncheck to exclude the party from future use.") replaced_by = fields.Many2One('party.party', "Replaced By", readonly=True, states={ 'invisible': ~Eval('replaced_by'), @@ -85,6 +80,10 @@ class Party(ModelSQL, ModelView, MultiValueMixin): 'The code of the party must be unique.') ] cls._order.insert(0, ('name', 'ASC')) + cls.active.states.update({ + 'readonly': Bool(Eval('replaced_by')), + }) + cls.active.depends.append('replaced_by') @classmethod def __register__(cls, module_name): @@ -102,10 +101,6 @@ class Party(ModelSQL, ModelView, MultiValueMixin): table, _ = tables[None] return [CharLength(table.code), table.code] - @staticmethod - def default_active(): - return True - @staticmethod def default_categories(): return Transaction().context.get('categories', []) diff --git a/view/address_format_list.xml b/view/address_format_list.xml index 101a6c5880..2919fd3715 100644 --- a/view/address_format_list.xml +++ b/view/address_format_list.xml @@ -2,5 +2,4 @@ - diff --git a/view/category_list.xml b/view/category_list.xml index a7e643066b..8470f20573 100644 --- a/view/category_list.xml +++ b/view/category_list.xml @@ -3,5 +3,4 @@ this repository contains the full copyright notices and license terms. --> - diff --git a/view/category_tree.xml b/view/category_tree.xml index 6215ea3a27..e963d4392e 100644 --- a/view/category_tree.xml +++ b/view/category_tree.xml @@ -5,5 +5,4 @@ this repository contains the full copyright notices and license terms. --> - diff --git a/view/party_tree.xml b/view/party_tree.xml index 2e40d7003a..f7a3ff6b4b 100644 --- a/view/party_tree.xml +++ b/view/party_tree.xml @@ -6,5 +6,4 @@ this repository contains the full copyright notices and license terms. --> -