Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4924 มุมมอง

Im trying to create several users for customers by executing a wizard from a transient Model, im creating about seven hundred users but my methods are taking too much time to complete only with one hundred. Can anyone help me to improve my methods, actually are this:

@api.multi
def create_student_user_selected(self):
    customers_ready = 0
    active_ids = self.env.context.get('active_ids', []) or []
    records = self.env['my.customers_model'].browse(active_ids)

    for customer in records:
        customers_ready += 1
        print('customer number '+ str(customers_ready))
        if customer.email and not customer.usuario_id:
            self.create_customer_user(customer)
        else:
        print('The customer has no email')

@api.multi
def create_customer_user(self, customer_id):
    customers_group = self.env.ref('stock_sales.customers_group')
    user_data = {
        'name': partner_id.name,
        'login': partner_id.email,
        'partner_id': partner_id.partner_id.id
    }
    user_customer_obj = self.env['res.users'].sudo().create(user_data)
    partner_id.sudo().write(
        {
            'user_id': user_customer_obj.id,
        }
    )
    customer_id.partner_id.email = customer_id.email 
    customers_group.users += user_customer_obj

อวตาร
ละทิ้ง

Hi,

By using sql query you can save your precious time otherwsie it will take some extra time. Because ORM will check all constrains while creating. If you don't  need to check any constrains you can follow sql query otherwsie it will take some time.

Query

create_user = """insert into res_users(name,login,partner_id) values ('%s', '%s', %d)""" % (partner_id.name, partner_id.email, partner_id.partner_id.id)

self.env.cr.execute(create_user)

Thanks.

ผู้เขียน

ok, thanks, i will try that.

ผู้เขียน คำตอบที่ดีที่สุด

But the users cannot be imported.

อวตาร
ละทิ้ง

Sure they can. If you have admin privileges, you can go to Settings > Users & Companies > Users, there is an import button that allows you to import Users from a csv file.

คำตอบที่ดีที่สุด

Hi Oscar, since this will be a one-time setup, the simplest way would be to just import the users using a csv file.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ก.ย. 20
29445
Eliminar licencia de usuario แก้ไขแล้ว
1
เม.ย. 24
1692
0
พ.ย. 22
1931
1
ก.ย. 20
5426
1
พ.ย. 21
2723