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

Hi!

I would like to add a button in contact that will link to crm.lead that the contact sold.

Because of the crm.lead salesman is link by a user_id I created a computed many2one field (stored) crm_user_id to the linked user:

record.crm_user_id = self.env['res.users'].search([('partner_id', '=', record.id)]).id

The id is right but when I want to use it for the domain I get this error:

 

Uncaught Error: NameError: name 'crm_user_id' is not defined
http://localhost:8069/web/content/654-6128a20/web.assets_backend.js:145 Traceback: Error: NameError: name 'crm_user_id' is not defined


When I set a fixe value like 2 (the id of one on my user) instead of the var crm_user_id It works perfectly

The domain in question is set like that:


    <record model="ir.actions.act_window" id="crm_open">
        <field name="domain">[('user_id', '=', crm_user_id)]</field>
        <field name="name">CRM</field>
        <field name="res_model">crm.lead</field>
    </record>


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

Hello Théo Da Silva, 

You are getting this issue because "crm_user_id" is not defined inside the windows action and by default in Odoo you can't pass value in domain inside a XML file for windows action.

And your requirement is to show leads from Partner on button click

So instead of creating a computed field inside the partner you can achieve the same using button method. 

def action_open_crm_lead(self):
        self.ensure_one()
        userObjs = self.env['res.users'].search([('partner_id', '=', self.id)], limit=1)
        user_id = userObjs.id if userObjs else False
        domain = [('user_id', '=', user_id)] if user_id else []
        return {
            'name': 'CRM LEAD',
            'domain': domain,
            'res_model': 'crm.lead',
            'type': 'ir.actions.act_window',
            'view_mode': 'tree,form',
            'view_id': False,
        }

Feel free to ask your queries

Thanks

Anisha Bahukhandi

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

Hello,

Can you please make sure you have store=True on "crm_user_id" field which you have created on contact  (res.partner) form. ?

Regards,

Mustufa Rangwala (Probuse)

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

Hello Mustufa,

Thanks for your answer, yes store=True

    crm_user_id = fields.Many2one(
        comodel_name='res.users',
        compute=_compute_crm_user_id,
        store=True)

I also have a value in the postgres at the field crm_user_id in the table res_patner.

But I still get the same error

Edit:

Thank you very much Anisha Bahukhandi it works perfectly

Ảnh đại diện
Huỷ bỏ

Hello Théo Da Silva,

It's great that your query is resolved and you are satisfied with my assistance.

I would really appreciate if you can take out a few minutes out of your busy schedule and put a google review for me here -

https://www.google.com/search?q=webkul&oq=webkul+&aqs=chrome..69i57j69i60l3j0l2.4182j0j7&sourceid=chrome&ie=UTF-8#lrd=0x390ce561c5555555:0xcfb40ae166ce6c21,1,

A nice review from your side will motivate me and my team to provide exceptional assistance.

I hope you can manage to provide few minutes for this :)

Regards

Anisha Bahukhandi

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 4 18
8038
0
thg 10 23
1763
1
thg 9 21
1821
2
thg 8 25
1094
naked domain set up Đã xử lý
3
thg 7 25
4118