diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 047ec12980a..f94f45b7f70 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -79,6 +79,7 @@ class procurement_rule(osv.osv): _columns = { 'name': fields.char('Name', required=True, help="This field will fill the packing origin and the name of its moves"), + 'active': fields.boolean('Active', help="If unchecked, it will allow you to hide the rule without removing it."), 'group_propagation_option': fields.selection([('none', 'Leave Empty'), ('propagate', 'Propagate'), ('fixed', 'Fixed')], string="Propagation of Procurement Group"), 'group_id': fields.many2one('procurement.group', 'Fixed Procurement Group'), 'action': fields.selection(selection=lambda s, cr, uid, context=None: s._get_action(cr, uid, context=context), @@ -90,6 +91,7 @@ class procurement_rule(osv.osv): _defaults = { 'group_propagation_option': 'propagate', 'sequence': 20, + 'active': True, } diff --git a/addons/procurement/procurement_view.xml b/addons/procurement/procurement_view.xml index 9b3071a2caa..cfa45087729 100644 --- a/addons/procurement/procurement_view.xml +++ b/addons/procurement/procurement_view.xml @@ -221,6 +221,7 @@ + diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index b9d8a52b4c6..0214eef6da1 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -47,20 +47,6 @@ class procurement_rule(osv.osv): res += [x.id for x in route.pull_ids] return res - def _get_route(self, cr, uid, ids, context=None): - #WARNING TODO route_id is not required, so a field related seems a bad idea >-< - if context is None: - context = {} - result = {} - if context is None: - context = {} - context_with_inactive = context.copy() - context_with_inactive['active_test']=False - for route in self.pool.get('stock.location.route').browse(cr, uid, ids, context=context_with_inactive): - for pull_rule in route.pull_ids: - result[pull_rule.id] = True - return result.keys() - _columns = { 'location_id': fields.many2one('stock.location', 'Procurement Location'), 'location_src_id': fields.many2one('stock.location', 'Source Location', @@ -76,10 +62,6 @@ class procurement_rule(osv.osv): }), 'picking_type_id': fields.many2one('stock.picking.type', 'Picking Type', help="Picking Type determines the way the picking should be shown in the view, reports, ..."), - 'active': fields.related('route_id', 'active', type='boolean', string='Active', store={ - 'stock.location.route': (_get_route, ['active'], 20), - 'procurement.rule': (lambda self, cr, uid, ids, c={}: ids, ['route_id'], 20)}, - help="If the active field is set to False, it will allow you to hide the rule without removing it."), 'delay': fields.integer('Number of Days'), 'partner_address_id': fields.many2one('res.partner', 'Partner Address'), 'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move of the move (which was generated by a next procurement) is cancelled or split, the move generated by this move will too'), @@ -89,7 +71,6 @@ class procurement_rule(osv.osv): _defaults = { 'procure_method': 'make_to_stock', - 'active': True, 'propagate': True, 'delay': 0, } diff --git a/addons/stock/stock.py b/addons/stock/stock.py index ec5983ab359..3cfb10ac05d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -210,6 +210,24 @@ class stock_location_route(osv.osv): 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location.route', context=c), } + def write(self, cr, uid, ids, vals, context=None): + '''when a route is deactivated, deactivate also its pull and push rules''' + if isinstance(ids, (int, long)): + ids = [ids] + res = super(stock_location_route, self).write(cr, uid, ids, vals, context=context) + if 'active' in vals: + push_ids = [] + pull_ids = [] + for route in self.browse(cr, uid, ids, context=context): + if route.push_ids: + push_ids += [r.id for r in route.push_ids if r.active != vals['active']] + if route.pull_ids: + pull_ids += [r.id for r in route.pull_ids if r.active != vals['active']] + if push_ids: + self.pool.get('stock.location.path').write(cr, uid, push_ids, {'active': vals['active']}, context=context) + if pull_ids: + self.pool.get('procurement.rule').write(cr, uid, pull_ids, {'active': vals['active']}, context=context) + return res #---------------------------------------------------------- # Quants @@ -3324,20 +3342,6 @@ class stock_location_path(osv.osv): _description = "Pushed Flows" _order = "name" - def _get_route(self, cr, uid, ids, context=None): - #WARNING TODO route_id is not required, so a field related seems a bad idea >-< - if context is None: - context = {} - result = {} - if context is None: - context = {} - context_with_inactive = context.copy() - context_with_inactive['active_test'] = False - for route in self.pool.get('stock.location.route').browse(cr, uid, ids, context=context_with_inactive): - for push_rule in route.push_ids: - result[push_rule.id] = True - return result.keys() - def _get_rules(self, cr, uid, ids, context=None): res = [] for route in self.browse(cr, uid, ids, context=context): @@ -3362,10 +3366,7 @@ class stock_location_path(osv.osv): "by a worker. With 'Automatic No Step Added', the location is replaced in the original move." ), 'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move is cancelled or split, the move generated by this move will too'), - 'active': fields.related('route_id', 'active', type='boolean', string='Active', store={ - 'stock.location.route': (_get_route, ['active'], 20), - 'stock.location.path': (lambda self, cr, uid, ids, c={}: ids, ['route_id'], 20),}, - help="If the active field is set to False, it will allow you to hide the rule without removing it." ), + 'active': fields.boolean('Active', help="If unchecked, it will allow you to hide the rule without removing it."), 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'), 'route_sequence': fields.related('route_id', 'sequence', string='Route Sequence', store={