diff --git a/address.py b/address.py index 9d0d050eb5..e68117807a 100644 --- a/address.py +++ b/address.py @@ -4,6 +4,8 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval, If from trytond.pool import Pool +from trytond.transaction import Transaction +from trytond.backend import TableHandler STATES = { 'readonly': ~Eval('active'), @@ -31,7 +33,9 @@ class Address(ModelSQL, ModelView): 'Subdivision', domain=[('country', '=', Eval('country'))], states=STATES, depends=['active', 'country']) active = fields.Boolean('Active') - sequence = fields.Integer("Sequence", required=True) + sequence = fields.Integer("Sequence", + order_field='(%(table)s.sequence IS NULL) %(order)s, ' + '%(table)s.sequence %(order)s') full_address = fields.Function(fields.Text('Full Address'), 'get_full_address') @@ -43,6 +47,15 @@ class Address(ModelSQL, ModelView): 'write_party': 'You can not modify the party of an address!', }) + def init(self, module_name): + cursor = Transaction().cursor + table = TableHandler(cursor, self, module_name) + + super(Address, self).init(module_name) + + # Migration from 2.4: drop required on sequence + table.not_null_action('sequence', action='remove') + def default_active(self): return True diff --git a/contact_mechanism.py b/contact_mechanism.py index cadee5645e..772a688877 100644 --- a/contact_mechanism.py +++ b/contact_mechanism.py @@ -2,6 +2,8 @@ #this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval +from trytond.transaction import Transaction +from trytond.backend import TableHandler STATES = { 'readonly': ~Eval('active'), @@ -36,7 +38,9 @@ class ContactMechanism(ModelSQL, ModelView): party = fields.Many2One('party.party', 'Party', required=True, ondelete='CASCADE', states=STATES, select=True, depends=DEPENDS) active = fields.Boolean('Active', select=True) - sequence = fields.Integer('Sequence', required=True) + sequence = fields.Integer('Sequence', + order_field='(%(table)s.sequence IS NULL) %(order)s, ' + '%(table)s.sequence %(order)s') email = fields.Function(fields.Char('E-Mail', states={ 'invisible': Eval('type') != 'email', 'required': Eval('type') == 'email', @@ -77,6 +81,15 @@ class ContactMechanism(ModelSQL, ModelView): 'a contact mechanism!', }) + def init(self, module_name): + cursor = Transaction().cursor + table = TableHandler(cursor, self, module_name) + + super(ContactMechanism, self).init(module_name) + + # Migration from 2.4: drop required on sequence + table.not_null_action('sequence', action='remove') + def default_type(self): return 'phone'