Replace _constraints with validate in ModelStorage and improve user messages.

issue2616
review371002
This commit is contained in:
Albert Cervera i Areny committed 2013-03-07 16:55:48 +01:00
1 parent 26e00b9f83
commit bf33f2309d
2 files changed
+31 -23

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ class Invoice:
super(Invoice, cls).__setup__()
cls._error_messages.update({
'delete_purchase_invoice': ('You can not delete invoices '
'that come from a purchase!'),
'that come from a purchase.'),
'reset_invoice_purchase': ('You cannot reset to draft '
'an invoice generated by a purchase.'),
})
+30 -22
View File
@@ -141,14 +141,14 @@ class Purchase(Workflow, ModelSQL, ModelView):
cls._order.insert(0, ('purchase_date', 'DESC'))
cls._order.insert(1, ('id', 'DESC'))
cls._error_messages.update({
'invoice_addresse_required': 'Invoice addresses must be '
'defined for the quotation.',
'warehouse_required': ('A warehouse must be defined for the '
'quotation.'),
'missing_account_payable': ('It misses '
'an "Account Payable" on the party "%s"!'),
'invoice_address_required': ('Invoice address must be '
'defined for quotation of sale "%s".'),
'warehouse_required': ('A warehouse must be defined for '
'quotation of sale "%s".'),
'missing_account_payable': ('Missing "Account Payable" on '
'party "%s".'),
'delete_cancel': ('Purchase "%s" must be cancelled before '
'deletion!'),
'deletion.'),
})
cls._transitions |= set((
('draft', 'quotation'),
@@ -531,12 +531,14 @@ class Purchase(Workflow, ModelSQL, ModelView):
def check_for_quotation(self):
if not self.invoice_address:
self.raise_user_error('invoice_addresse_required')
self.raise_user_error('invoice_address_required',
(purchase.rec_name,))
for line in self.lines:
if (not line.to_location
and line.product
and line.product.type in ('goods', 'assets')):
self.raise_user_error('warehouse_required')
self.raise_user_error('warehouse_required',
(purchase.rec_name,))
@classmethod
def set_reference(cls, purchases):
@@ -896,12 +898,12 @@ class PurchaseLine(ModelSQL, ModelView):
super(PurchaseLine, cls).__setup__()
cls._order.insert(0, ('sequence', 'ASC'))
cls._error_messages.update({
'supplier_location_required': (
'The supplier location is required!'),
'missing_account_expense': ('It misses '
'an "Account Expense" on product "%s"!'),
'missing_account_expense_property': ('It misses '
'an "account expense" default property!'),
'supplier_location_required': ('Purchase "%(purchase)s" misses '
'the supplier location for line "%(line)s".'),
'missing_account_expense': ('Product "%(product)s" of purchase '
'%(purchase)s misses an expense account.'),
'missing_account_expense_property': ('Purchase "%(purchase)s" '
'misses an "account expense" default property.'),
})
@classmethod
@@ -1158,15 +1160,18 @@ class PurchaseLine(ModelSQL, ModelView):
if self.product:
invoice_line.account = self.product.account_expense_used
if not invoice_line.account:
self.raise_user_error('missing_account_expense',
error_args=(self.product.rec_name,))
self.raise_user_error('missing_account_expense', {
'product': line.product.rec_name,
'purchase': line.purchase.rec_name,
})
else:
for model in ('product.template', 'product.category'):
invoice_line.account = Property.get('account_expense', model)
if invoice_line.account:
break
if not invoice_line.account:
self.raise_user_error('missing_account_expense_property')
self.raise_user_error('missing_account_expense_property',
(line.purchase.rec_name,))
invoice_line.purchase_lines = [self]
return [invoice_line]
@@ -1204,7 +1209,10 @@ class PurchaseLine(ModelSQL, ModelView):
if quantity <= 0.0:
return
if not self.purchase.party.supplier_location:
self.raise_user_error('supplier_location_required')
self.raise_user_error('supplier_location_required', {
'purchase': self.purchase.rec_name,
'line': self.rec_name,
})
with Transaction().set_user(0, set_context=True):
move = Move()
move.quantity = quantity
@@ -1556,8 +1564,8 @@ class ShipmentIn:
cls.incoming_moves.depends.append('supplier')
cls._error_messages.update({
'reset_move': ('You cannot reset to draft a move generated '
'by a purchase.'),
'reset_move': ('You cannot reset to draft move "%s" because '
'it was generated by a purchase.'),
})
@classmethod
@@ -1593,7 +1601,7 @@ class ShipmentIn:
for shipment in shipments:
for move in shipment.incoming_moves:
if move.state == 'cancel' and move.purchase_line:
cls.raise_user_error('reset_move')
cls.raise_user_error('reset_move', (move.rec_name,))
return super(ShipmentIn, cls).draft(shipments)