def test_base(self): demo_user = self.env.ref("base.user_demo") group_erp_manager = self.env.ref("base.group_erp_manager") group_system = self.env.ref("base.group_system") demo_user.write({"groups_id": [(3, group_system.id)]}) group_system.write({"users": [(3, demo_user.id)]}) demo_user.write({"groups_id": [(4, group_erp_manager.id)]}) view_users_form = self.env.ref("base.view_users_form") res = (self.env["res.users"].with_user(demo_user).with_context({ "uid": demo_user.id }).load_views([[view_users_form.id, "form"]])) sel_groups = name_selection_groups([group_erp_manager.id]) res = self.env["res.users"].with_user(demo_user).fields_get() self.assertTrue(res.get(sel_groups)) demo_user.write({"groups_id": [(4, group_system.id)]}) sel_groups = name_selection_groups( [group_erp_manager.id, group_system.id]) res = self.env["res.users"].with_user(demo_user).fields_get() self.assertTrue(res.get(sel_groups))
def test_base(self): demo_user = self.env.ref('base.user_demo') group_erp_manager = self.env.ref('base.group_erp_manager') group_system = self.env.ref('base.group_system') demo_user.write({'groups_id': [(3, group_system.id)]}) group_system.write({'users': [(3, demo_user.id)]}) demo_user.write({'groups_id': [(4, group_erp_manager.id)]}) view_users_form = self.env.ref('base.view_users_form') res = self.env['res.users'].with_user(demo_user).with_context({ 'uid': demo_user.id }).load_views([[view_users_form.id, "form"]]) sel_groups = name_selection_groups([group_erp_manager.id]) res = self.env['res.users'].with_user(demo_user).fields_get() self.assertTrue(res.get(sel_groups)) demo_user.write({'groups_id': [(4, group_system.id)]}) sel_groups = name_selection_groups( [group_erp_manager.id, group_system.id]) res = self.env['res.users'].with_user(demo_user).fields_get() self.assertTrue(res.get(sel_groups))
def write(self, vals): check_allow_credit_note = True group_credit_note = self.env.ref( 'pos_orders_history_return.group_generate_credit_note', False) if group_credit_note: group_credit_note_name_boolean = name_boolean_group( group_credit_note.id) group_credit_note_name_selection = name_selection_groups( group_credit_note.ids) if group_credit_note_name_boolean in vals: vals['allow_credit_note'] = vals[ group_credit_note_name_boolean] check_allow_credit_note = False elif group_credit_note_name_selection in vals: vals['allow_credit_note'] = vals[ group_credit_note_name_selection] check_allow_credit_note = False res = super(ResUsers, self).write(vals) if check_allow_credit_note and 'allow_credit_note' in vals: group_credit_note = self.env.ref( 'pos_orders_history_return.group_generate_credit_note', False) if group_credit_note: for user in self: if user.share: continue if vals['allow_credit_note']: if user not in group_credit_note.users: user.sudo().write( {'groups_id': [(4, group_credit_note.id)]}) else: if user in group_credit_note.users: user.sudo().write( {'groups_id': [(3, group_credit_note.id)]}) return res
def _prepare_user_group_ids_from_default_get(self): ResGroups = self.env['res.groups'] ResUsers = self.env['res.users'] res1 = ResGroups.get_groups_by_application() fields = [] for item in res1: if item[1] == 'boolean': for group in item[2]: fields.append(name_boolean_group(group.id)) elif item[1] == 'selection': fields.append(name_selection_groups(item[2].ids)) res2 = ResUsers.default_get(fields) return res2['groups_id'][0][2]