Add Followers when confirm PO in Odoo9
@api.multi
def action_confirm(self):
group_id = self.env['ir.model.data'].xmlid_to_res_id('branch_stock.branch_head_stock')
#branch_stock.branch_head_stock (nama_modul_tempat_group.group_id)
self._cr.execute("select rp.id from res_groups_users_rel rel inner join res_users ru on rel.uid=ru.id "\
"inner join res_partner rp on rp.id=ru.partner_id "\
"where rel.gid=%s and rp.branch_id=%s " % (group_id, self.src_warehouse_id.branch_id.id))
ress = self._cr.fetchall()
new_follower_ids = []
for res in ress:
p_id = res[0]
new_follower_ids.append(p_id)
res_model = 'stock.branch.request'
ir_model = self.env['ir.model']
#digunakan untuk menambah followers (berdasakan ini self.src_warehouse_id.branch_id.id)
for obj in self :
model_obj = self.env[res_model]
model_ids = ir_model.search([('model','=',model_obj.name)])
model_name = model_ids.name
obj.message_subscribe(new_follower_ids)
#
self.write({'state': 'confirm', 'name': self.env['ir.sequence'].next_by_code('stock.branch.request')})
Komentar
Posting Komentar