我有一个应用程序,用户可以预订交付并为每次交付选择交付合作伙伴。我想阻止用户在同一时间内为两个不同的交付选择相同的合作伙伴。
我想应用与更改事件相同的方法,但是在视图加载时执行此操作。
以下是选择正确域名的方法:
def delivery_partners_change(self,cr,uid,ids):
domain=[]
print("RECALCULATING DOMAIN")
# the domain of the delivery partners should be all partners with can_install set that are not present in any conflicting deliveries done during the same time period.
for picking in self.browse(cr, uid, ids):
print("Picking partners: "+str([x.id for x in picking.delivery_partner_ids]))
# select partners that are in use by one of the overlapping events
cr.execute('select id from res_partner where id not in (SELECT r.partner_id FROM stock_picking p, stock_picking_delivery_partner_rel r WHERE ((%s >= p.delivery_date_min and %s < p.delivery_date_max) or (%s <= p.delivery_date_max and %s > p.delivery_date_min)) and r.picking_id = p.id)', (picking.delivery_date_min, picking.delivery_date_min, picking.delivery_date_max, picking.delivery_date_max))
in_use = cr.fetchall();
domain = [("id", "in", in_use)];
print("DOMAIN RETURNED = "+str(domain));
return {'domain':{'delivery_partner_ids': domain}}
问题是,当用户打开视图时,他可以看到整个不受限制的域。在此onchange事件触发后,他只能获取正确的记录子集以供选择。
当用户在Web客户端中打开记录时,如何将此域应用于视图init处的字段?
答案 0 :(得分:0)
试试这个,
在py文件中,
_columns = {
'init_onchange_call': fields.function(delivery_partners_change, string='Nothing Display', help='field at view init', multi="delivery_partners_change"),
}
在xml文件中,
<field name="init_onchange_call" invisible="1" />