This question has been flagged
4 Replies
6911 Views

Hi

i have a custom module for the sale.order.form , what i need is to add the child.ids of the selected partner.id as drop down list.

at below what i write, so please check and feed me back if that right or not?

in the .py

partner_id.child_ids = fields.Many2one('res.partner', string='Contact Person', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
domain=[('partner_id.child_ids', '=', False)])


in the view.xml

<data>
    <xpath expr="//field[@name='partner_id']" position="after">
<field name="partner_id.child_ids" domain="[('customer','=',True)]" context="{'search_default_customer':1}" options='{"always_reload": True}'/>
    </xpath>
</data>


report_templates.xml

<span t-field="doc.partner_id.child_ids"/>



Avatar
Discard

Try this domain : domain=lambda self: [('model_id', '=', self.parent_id.id)]

Author Best Answer

Dear All,

i tried your solutions, but it gives me an error related to another field in the view.xml file , actually i don't know why because I'm not a developer.

now, i will trying another solution as following and i will feed you back.


in report_templates.xml

<t t-if="doc.partner_id.child_ids">
    <t t-if="doc.partner_id.child_ids.type == 'Contact'">
        <span t-field="doc.partner_id.child_ids.name"/>
    </t>
</t>

this solution required to set only one child_ids as contact in the types


appreciate your cooperation


Avatar
Discard
Best Answer

Remove domain from .py file,

and modify domain in .xml file as,

domain="[('customer', '=', True),('parent_id', '=', partner_id)]"

Avatar
Discard
Best Answer
Hi Ayman Gabr,
 
Change this code.
 
Python:
 partner_id_child_ids = fields.Many2one('res.partner', string='Contact Person', domain=[('parent_id', '=', self.partner_id)])
Xml:
 
 <xpath expr="//field[@name='partner_id']" position="after">
<field name="partner_id_child_ids" domain="[('customer','=',True)]" context="{'search_default_customer':1}" options='{"always_reload": True}'/>
 </xpath>
 
Thank you.
Avatar
Discard

Where are there such files?
I'm using Odoo (Studio) online and have seen no buttons for editing code.