Reputation: 33
please I would like to know how I can get the value of a field from another model in Odoo 12. I have a contact class and another class where I want to get the phone number of the contact class and when I use the many2one relationship it brings me the email addresses and not the phone number. I specify any time that I inherited the contact class from Odoo and I added the telephone field in this class
Upvotes: 0
Views: 2603
Reputation: 1
Get value from another field in xml file in odoo :
<page string="Properties">
<field name="property_ids" context="{'id':active_id}">
<!-- key can be any, property type active id -->
<tree>
<field name="name" />
<field name="price" />
<field name="property_status" />
</tree>
</field>
</page>
For ex : if current model is property type, i want fields of real_Estate properties (which is another model), add this type of code to current model (here, property_type)
Here from code, property_ids field is available in property_type model, only then it works
Upvotes: -1
Reputation: 26678
You got emails
because _rec_name
is set to the email
field. note that emails are just displayed names, the recipient
field is a reference to a mail.mass_mailing.contact
record.
To get a phone number instead of an email you can:
Override name_get
to display phone_number
:
def name_get(self):
res_list = []
for contact in self:
res_list.append((contact.id, contact.phone_number))
return res_list
You can check if phone_number
is empty and display another value instead.
Add a related field phone_number
next to recipient
field:
recipient= fields.Many2one(comodel_name= "mail.mass_mailing.contact", required = True)
phone_number = fields.Char(related='recipient.phone_number')
Upvotes: 1