From 5ef5a5c8f314b46aee7163b86050eece6344cb24 Mon Sep 17 00:00:00 2001 From: Bertrand Chenal Date: Tue, 27 May 2008 00:55:13 +0200 Subject: [PATCH] Add constraint on move: forbid service product. --- move.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/move.py b/move.py index fcaae74dbe..dc35b79500 100644 --- a/move.py +++ b/move.py @@ -17,7 +17,8 @@ class Move(OSV): _rec_name = "product" product = fields.Many2One("product.product", "Product", required=True, select=1, states=STATES, - on_change=['product', 'type', 'currency', 'uom', 'company']) + on_change=['product', 'type', 'currency', 'uom', 'company'], + domain=[('type', '!=', 'service')],) uom = fields.Many2One("product.uom", "Uom", required=True, states=STATES) quantity = fields.Float("Quantity", digits=(12, 6), required=True, states=STATES) @@ -84,6 +85,10 @@ class Move(OSV): 'AND packing_out IS NOT NULL))', 'Move can not be in both Supplier and Customer Packing'), ] + self._constraints += [ + ('check_product_type', + 'Error! You can not use service product for a move.', ['product']) + ] self._order[0] = ('id', 'DESC') def default_to_location(self, cursor, user, context=None): @@ -204,6 +209,12 @@ class Move(OSV): res['type'] = 'output' return res + def check_product_type(self, cursor, user, ids): + for move in self.browse(cursor, user, ids): + if move.type == 'service': + return False + return True + def on_change_from_location(self, cursor, user, ids, vals, context=None): return self._on_change_location(cursor, user, ids, vals, context=context)