[WIP]use related for active field on push/pull rules based on associated route

bzr revid: csn@openerp.com-20130927101552-d5cr2xolmg2mlsi8
This commit is contained in:
Cedric Snauwaert 2013-09-27 12:15:52 +02:00
parent 2684b55ada
commit 1fcc7a937b
2 changed files with 30 additions and 26 deletions

View File

@ -46,6 +46,15 @@ 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):
result = {}
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',
@ -57,13 +66,15 @@ class procurement_rule(osv.osv):
'sequence': fields.integer('Sequence'),
'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.boolean('Active', help="If the active field is set to False, it will allow you to hide the rule without removing it."),
'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." ),
}
_defaults = {
'procure_method': 'make_to_stock',
'sequence': 20,
'active': True,
}
class procurement_order(osv.osv):

View File

@ -214,6 +214,7 @@ class stock_warehouse(osv.osv):
def change_route(self, cr, uid, ids, warehouse, new_reception_step=False, new_delivery_step=False, context=None):
pull_obj = self.pool.get('procurement.rule')
route_obj = self.pool.get('stock.location.route')
new_reception_step = new_reception_step or warehouse.reception_steps
new_delivery_step = new_delivery_step or warehouse.delivery_steps
reception_name = False
@ -271,28 +272,8 @@ class stock_warehouse(osv.osv):
set_active_route_ids.append(warehouse.pick_ship_route_mto.id)
elif new_delivery_step == 'pick_pack_ship':
set_active_route_ids.append(warehouse.pick_pack_ship_route_mto.id)
self.set_route_active_status(cr, uid, ids, set_inactive_route_ids, False, context=context)
self.set_route_active_status(cr, uid, ids, set_active_route_ids, True, context=context)
return True
def set_route_active_status(self, cr, uid, ids, route_ids, status=True, context=None):
route_obj = self.pool.get('stock.location.route')
pull_obj = self.pool.get('procurement.rule')
push_obj = self.pool.get('stock.location.path')
if not route_ids:
return True
route_obj.write(cr, uid, route_ids, {'active': status}, context=context)
pull_rules_ids = []
push_rules_ids = []
for route in route_obj.browse(cr, uid, route_ids, context=context):
for pull_rule in route.pull_ids:
pull_rules_ids.append(pull_rule.id)
for push_rule in route.push_ids:
push_rules_ids.append(push_rule.id)
if pull_rules_ids:
pull_obj.write(cr, uid, pull_rules_ids, {'active': status}, context=context)
if push_rules_ids:
push_obj.write(cr, uid, push_rules_ids, {'active': status}, context=context)
route_obj.write(cr, uid, set_inactive_route_ids, {'active': False}, context=context)
route_obj.write(cr, uid, set_active_route_ids, {'active': True}, context=context)
return True
def create(self, cr, uid, vals, context=None):
@ -514,6 +495,16 @@ class stock_location_path(osv.osv):
_name = "stock.location.path"
_description = "Pushed Flows"
_order = "name"
def _get_route(self, cr, uid, ids, context=None):
result = {}
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()
_columns = {
'name': fields.char('Operation Name', size=64, required=True),
'company_id': fields.many2one('res.company', 'Company'),
@ -537,7 +528,10 @@ 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.boolean('Active', help="If the active field is set to False, it will allow you to hide the rule without removing it."),
'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." ),
}
_defaults = {
'auto': 'auto',
@ -545,7 +539,6 @@ class stock_location_path(osv.osv):
'invoice_state': 'none',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c),
'propagate': True,
'active': True,
}
def _apply(self, cr, uid, rule, move, context=None):
move_obj = self.pool.get('stock.move')