Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
7531 Представления

I have created a Customer and that customers has 3 contact person names. Now while creating the Sales Order, I want to select 1 contact person name from a list. How can I get only the names of the contact person into a field?

I have created a related field in my custom module and in the form view I have displayed it :

custom.py

customer_contact = fields.Char(related="partner_id.child_ids.name", string="Contact Person", )

custom_saleorder_views.xml

<xpath expr="//field[@name='partner_shipping_id']" position="after">
<!-- Add your fields or attributes here -->
<field name="customer_contact" />
</xpath>

I have displayed the field below the Delivery address.

Now when I select the customer in Sales Order form view, it gives only the first contact person name. The rest of the contact names are not displayed.

How to get a list of contact names in the field "customer_contact". As the default field type of 'name' field is 'Char', using many2one field in our custom module gives a error.

Аватар
Отменить
Лучший ответ

Hi,

you can not used related="partner_id.child_ids.name" because  child_ids is One2many field

One2many fields does not work in related. 

Please try below Example:

customer_contact = fields.Char(string="Contact Person" )

@api.onchange('partner_id')

def get_customer_contact_person(self):

    if self.partner_id and self.partner_id.child_ids:

        for person in self.partner_id.child_ids:

            self.customer_contact =  ' '.join(person.name)

Make sure it will helpful.

Thank You.


Аватар
Отменить
Автор

Hi Dhaval,

I tried you code, but it game me the following error. Can you please help me in solving this error.

line 66, in get_customer_contact_person

self.customer_contact = ''.join(person.name)

TypeError: can only join an iterable

Hello Arpit,

you can try below:

def get_customer_contact_person(self):

if self.partner_id and self.partner_id.child_ids:

self.customer_contact = ' '.join(str(person.name) for person in self.partner_id.child_ids)

Автор

Hi Dhaval,

Your updated solution is working well without any problem. Thank you for your prompt answer.

With your code I am getting contact person names, but not as a drop down list. I want to select only one contact person from 3 or 4 persons.

So can you help me in getting a drop down menu for contact persons.

Thanks for your previous answers.

Related Posts Ответы Просмотры Активность
3
сент. 18
2341
2
мар. 15
9161
2
июл. 24
7943
1
окт. 22
3859
2
июн. 20
6368