Skip to Content
Menu
This question has been flagged
2 Replies
1760 Views

Hi,

I have a custom model which does NOT inherit res.partner or any other model.

It has a lot of fields, to which I have added two (2) many2one fields at the bottom:

class my_custom_model(models.Model):
    _name = 'my_custom_model'
    _description = 'Custom Model'      
   field1 = fields.Char('field1')
   field2 = fields.Char('field2')
   (field.......... many custom fields!!!)
   field99 = fields.Char('field99')
   m2o_name1 = fields.Many2one('res.partner', 'partner name 1')
   m2o_name2 = fields.Many2one('res.partner', partner name 2')


It works as expected, I can choose 2 partners for any record and save it.

My question is, how do I access other fields in the res.partner model from here?

For example: If I want to access partner 1 and partner 2 phone numbers and use in my custom code - something like:

Python:

partner1_phone = m20_name1.phone_number

partner2_phone = m20_name2.phone_number

Then use in XML in the standard way:

<field name="partner1_phone" "string"partner 1 phone number: " />
<field name="partner2_phone" "string"partner  2 phone number: "/>


Can this be done without inheriting res.partner in my custom model?

The my_custom_model has lots of custom fields that don't belong and are not required in the partner model.
I don't want to add all these fields to the res.partner model.

Is there an easy way for me to access the res.partner data based on the stored ids?


Avatar
Discard
Best Answer

Dear Ed,


Please try related field type

partner1_phone = fields.Char(string='Phone', related='partner_id.phone')

Regards,

Silvestar





Avatar
Discard
Best Answer

Hello ED,

For this, you can use . notation for accessing other fields values in many2one . Using . you can access other fields values from that particular model.

Avatar
Discard