跳至内容
菜单
此问题已终结
1 回复
2239 查看

My model: Tenant.


In model Tenant I have field phone, I want when I create a new tenant (In case of creating a new account first (EX: login = "0123 456 789") , then create tenant), field "phone" in this model will link with field "login" in model res_users


On the contrary, in case of creating a new tenant first (Ex: 0123 456 789), when I create account in res_users, "login" in this model auto link with "phone" in tenant.


Model Tenant:


	
class Tenant(models.Model):    
_name = "pma.tenant"   
​_inherit = ["mail.thread", "mail.activity.mixin"]   
​_description = "Manager Tenant"   
​_order = "create_date desc"
name = fields.Char(string="Tenant Name", required=True)   
owner = fields.Many2one("res.users", string="Owner", required=True, default=lambda self: self.env.user)
    phone = fields.Char(string="Phone Number", required=True)   

user = fields.Many2one("res.users")   
email = fields.Char(string="Email Address", required=True)   

    @api.onchange("phone")   

def _compute_check_phone_number(self):       
for record in self:           
convert_phone = utils.convert_phone_to_global(self.phone)     
if convert_phone:
record.user = self.env["res.users"].search(                    [("login", "=", convert_phone)])

Model Res_users:
class Users(models.Model):   
_inherit = "res.users"
   

@api.model_create_multi   
def create(self, vals_list):       
users = super(Users, self).create(vals_list)       
for user in users:           
convert_login = utils.convert_phone_to_vn(user.login)            if convert_login: 
              tenant = (self.env["pma.tenant"].sudo().search([("phone", "=", convert_login)]))
                tenant.write({"user": users.id})       
return users

I have linked, but it only works in 1 case: creating a new Previous Tenant, creating an account will automatically link.


I want it works for bolh case.

Please help me ....



形象
丢弃
编写者 最佳答案

Please help me 


形象
丢弃
相关帖文 回复 查看 活动
2
2月 20
4167
0
1月 25
725
3
12月 24
20160
0
3月 24
1151
3
11月 24
29974