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

I have added a domain of filtering customer_category = "main customer" in res partner many2one field in Sales App 

partner_id = fields.Many2one('res.partner', domain="[('category_id', '=', 'Main Customer')]",string='Customer')

Therefore i would like it to be passed too when someone creates a new customer from Sales Application it should add that domain too as default value, how can l archive this?

Regards.

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

Do you mean that the newly created customer should have the 'category_id' field value = 'Main Customer'?
Firstly if category_id is a many2one field domain="[('category_id', '=', 'Main Customer')] this domain should not work. There should be a record ID instead of 'Main Customer' for example domain="[('category_id', '=', 1)] or you have to add another field in the model for category_id which has "Main Customer" records id as a default value.

assuming that this field is a selection field:
`field name="partner_id"  context="{'default_category_id': 'main_customer'} `

adding context like this to the field in the view should be enough for your purpose. you might also want to see some example in the "crm.lead.form" "partner_id" field.


assuming that this field is a many2one field:

field name="partner_id"  context="{'default_category_id': record_id}
​ (here record_id is the record id of Main customer. Or if you included the default category_id in the model and view you can replace record_id with the field name of default category id that is set to "Main Customer" record)
adding context like this to the field in the view should be enough for your purpose. you might also want to see some example in the "crm.lead.form" "partner_id" field.

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

Hi
Can you try this code,

record = self.env['Model_Name'].create({ 'partner_id': (0, 0, {'domain_field': 'domain_value'}) })

Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 22
3815
3
thg 10 18
40840
8
thg 2 17
8355
0
thg 1 17
5871
2
thg 2 24
12574