Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2205 Lượt xem

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 ....



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Please help me 


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 20
4159
0
thg 1 25
712
3
thg 12 24
20133
0
thg 3 24
1129
3
thg 11 24
29958