This question has been flagged
2 Replies
7042 Views

I have a model called loan.application:

from openerp import models, fields, api, exceptions, _

class loan_application(models.Model):
    _name = 'loan.application'
    _description = 'Loan Application'

    partner_id = fields.Many2one(string="Partner", comodel_name="res.partner")
    partner_title = fields.Many2one(related="partner_id.title")
    partner_name = fields.Char(related="partner_id.name")
    partner_street = fields.Char(related="partner_id.street")
    partner_street2 = fields.Char(related="partner_id.street2")
    partner_city = fields.Char(related="partner_id.city")
    partner_zip = fields.Char(related="partner_id.zip")
    partner_phone = fields.Char(related="partner_id.phone")
    partner_mobile = fields.Char(related="partner_id.mobile")
    partner_email = fields.Char(related="partner_id.email")

I have a form view that displays all these fields.

Now, the weird part:

If I fill out all of these fields and press the [Save] button, all the related fields are saved, except for: partner_street, partner_street2, partner_zip and partner_mobile. What makes these four fields so special that they do NOT save?

Avatar
Discard

Try:

artner_zip = fields.Char(related="partner_id.zip", use_parent_address=False)
OR
artner_zip = fields.Char(related="partner_id.zip", store=True)
or combine them...

Same thing in 2022, some of my related fields are sometimes saved sometimes not ... seems a bit random.

Best Answer

Hello Andre de Kock,

Related fields are by default read-only and not stored in database..
If you want to store it's value then you have to put store= True attribute on field.


Please find below link of Odoo documentation it may be useful to you,

https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#related-fields

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Best Answer

Hi,

In order to store a related field in our database, we can add an argument store within the field definition.
Please check this video for more information.

https://www.youtube.com/watch?v=PKE5IpxnsSs

Hope it helps

Avatar
Discard