Replace _constraints with validate in ModelStorage and improve user messages.
issue2616 review371002
This commit is contained in:
1 parent
3a60d8f8f2
commit
04732ae2b0
5 files changed
+42
-25
No files matched your search
+3
-3
@@ -45,8 +45,8 @@ class Address(ModelSQL, ModelView):
|
||||
cls._order.insert(0, ('party', 'ASC'))
|
||||
cls._order.insert(1, ('sequence', 'ASC'))
|
||||
cls._error_messages.update({
|
||||
'write_party': 'You can not modify the party of an address!',
|
||||
})
|
||||
'write_party': 'You can not modify the party of address "%s".',
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
@@ -114,7 +114,7 @@ class Address(ModelSQL, ModelView):
|
||||
if 'party' in vals:
|
||||
for address in addresses:
|
||||
if address.party.id != vals['party']:
|
||||
cls.raise_user_error('write_party')
|
||||
cls.raise_user_error('write_party', (address.rec_name,))
|
||||
super(Address, cls).write(addresses, vals)
|
||||
|
||||
def on_change_country(self):
|
||||
|
||||
+13
-11
@@ -29,26 +29,28 @@ class Category(ModelSQL, ModelView):
|
||||
super(Category, cls).__setup__()
|
||||
cls._sql_constraints = [
|
||||
('name_parent_uniq', 'UNIQUE(name, parent)',
|
||||
'The name of a party category must be unique by parent!'),
|
||||
]
|
||||
cls._constraints += [
|
||||
('check_recursion', 'recursive_categories'),
|
||||
('check_name', 'wrong_name'),
|
||||
]
|
||||
'The name of a party category must be unique by parent.'),
|
||||
]
|
||||
cls._error_messages.update({
|
||||
'recursive_categories': 'You can not create recursive categories!',
|
||||
'wrong_name': 'You can not use "%s" in name field!' % SEPARATOR,
|
||||
})
|
||||
'wrong_name': ('Invalid category name "%%s": You can not use '
|
||||
'"%s" in name field.' % SEPARATOR),
|
||||
})
|
||||
cls._order.insert(1, ('name', 'ASC'))
|
||||
|
||||
@staticmethod
|
||||
def default_active():
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def validate(cls, categories):
|
||||
super(Category, cls).validate(categories)
|
||||
cls.check_recursion(categories, rec_name='name')
|
||||
for category in categories:
|
||||
category.check_name()
|
||||
|
||||
def check_name(self):
|
||||
if SEPARATOR in self.name:
|
||||
return False
|
||||
return True
|
||||
self.raise_user_error('wrong_name', (category.name,))
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.parent:
|
||||
|
||||
@@ -97,5 +97,14 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.translation" id="party_category_recursion_error">
|
||||
<field name="name">party.category</field>
|
||||
<field name="lang">en_US</field>
|
||||
<field name="type">error</field>
|
||||
<field name="src">recursion_error</field>
|
||||
<field name="value">Recursion error: Party Category "%(rec_name)s" with parent "%(parent_rec_name)s" was configured as ancestor of itself.</field>
|
||||
<field name="module">party</field>
|
||||
<field name="fuzzy" eval="False"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -86,8 +86,8 @@ class ContactMechanism(ModelSQL, ModelView):
|
||||
cls._order.insert(0, ('party', 'ASC'))
|
||||
cls._order.insert(1, ('sequence', 'ASC'))
|
||||
cls._error_messages.update({
|
||||
'write_party': ('You can not modify the party of '
|
||||
'a contact mechanism!'),
|
||||
'write_party': ('You can not modify the party of contact '
|
||||
'mechanism "%s".'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@@ -171,5 +171,5 @@ class ContactMechanism(ModelSQL, ModelView):
|
||||
if 'party' in vals:
|
||||
for mechanism in mechanisms:
|
||||
if mechanism.party.id != vals['party']:
|
||||
cls.raise_user_error('write_party')
|
||||
cls.raise_user_error('write_party', (mechanism.rec_name,))
|
||||
super(ContactMechanism, cls).write(mechanisms, vals)
|
||||
@@ -77,14 +77,12 @@ class Party(ModelSQL, ModelView):
|
||||
super(Party, cls).__setup__()
|
||||
cls._sql_constraints = [
|
||||
('code_uniq', 'UNIQUE(code)',
|
||||
'The code of the party must be unique!')
|
||||
]
|
||||
cls._constraints += [
|
||||
('check_vat', 'invalid_vat'),
|
||||
'The code of the party must be unique.')
|
||||
]
|
||||
cls._error_messages.update({
|
||||
'invalid_vat': 'Invalid VAT number!',
|
||||
})
|
||||
'invalid_vat': ('Invalid VAT number "%(vat)s" on party '
|
||||
'"%(party)s".'),
|
||||
})
|
||||
cls._order.insert(0, ('name', 'ASC'))
|
||||
|
||||
@staticmethod
|
||||
@@ -219,6 +217,12 @@ class Party(ModelSQL, ModelView):
|
||||
return address
|
||||
return default_address
|
||||
|
||||
@classmethod
|
||||
def validate(cls, parties):
|
||||
super(Party, cls).validate(parties)
|
||||
for party in parties:
|
||||
party.check_vat()
|
||||
|
||||
def check_vat(self):
|
||||
'''
|
||||
Check the VAT number depending of the country.
|
||||
@@ -241,8 +245,10 @@ class Party(ModelSQL, ModelView):
|
||||
'vat_number': vat_number,
|
||||
})
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
self.raise_user_error('invalid_vat', {
|
||||
'vat': vat_number,
|
||||
'party': party.rec_name,
|
||||
})
|
||||
|
||||
|
||||
class PartyCategory(ModelSQL):
|
||||
|
||||
Reference in new issue
Block a user