Use deactivable mixin

issue4341
review38401002
This commit is contained in:
Sergi Almacellas Abellana committed 2018-03-26 14:10:40 +02:00
1 parent 611b5b5fd2
commit c2059a2d60
8 files changed
+18 -47

No files matched your search

+5 -16
View File
@@ -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}
+3 -8
View File
@@ -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)
+4 -8
View File
@@ -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))
+6 -11
View File
@@ -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', [])
-1
View File
@@ -2,5 +2,4 @@
<tree>
<field name="country"/>
<field name="language"/>
<field name="active" tree_invisible="1"/>
</tree>
-1
View File
@@ -3,5 +3,4 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="rec_name" expand="1"/>
<field name="active" tree_invisible="1"/>
</tree>
-1
View File
@@ -5,5 +5,4 @@ this repository contains the full copyright notices and license terms. -->
<field name="name" expand="1"/>
<field name="parent" tree_invisible="1"/>
<field name="childs" tree_invisible="1"/>
<field name="active" tree_invisible="1"/>
</tree>
-1
View File
@@ -6,5 +6,4 @@ this repository contains the full copyright notices and license terms. -->
<field name="name"/>
<field name="lang"/>
<field name="tax_identifier"/>
<field name="active" tree_invisible="1"/>
</tree>