diff --git a/address.py b/address.py
index 3017b89fb8..a1b6c0b6c6 100644
--- a/address.py
+++ b/address.py
@@ -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):
diff --git a/category.py b/category.py
index 8ec6fe5170..267c12e29c 100644
--- a/category.py
+++ b/category.py
@@ -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:
diff --git a/category.xml b/category.xml
index 71e9f471bf..b1706de7eb 100644
--- a/category.xml
+++ b/category.xml
@@ -97,5 +97,14 @@ this repository contains the full copyright notices and license terms. -->
+
+ party.category
+ en_US
+ error
+ recursion_error
+ Recursion error: Party Category "%(rec_name)s" with parent "%(parent_rec_name)s" was configured as ancestor of itself.
+ party
+
+
diff --git a/contact_mechanism.py b/contact_mechanism.py
index aa1c4f5da4..ed2f981c94 100644
--- a/contact_mechanism.py
+++ b/contact_mechanism.py
@@ -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)
diff --git a/party.py b/party.py
index f5379f2be5..4444183166 100644
--- a/party.py
+++ b/party.py
@@ -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):