FIRMAN
FIRMAN

Reputation: 1

ODOO 10 related field not updated

This related field working fine in odoo 9, but not in odoo 10. The field customer_id not updated when I create a new record with nomor_hp_id.

nomor_hp_id = fields.Many2one(
    string='Nomor hp',
    comodel_name='nomor.hp',
    ondelete='cascade',
)
customer_id = fields.Many2one(
    string='Customer',
    related='nomor_hp_id.customer_id',
    ondelete='cascade',
    store=True,
    readonly=True,
)

Try to start new database but the result still not updated.

Upvotes: 0

Views: 1914

Answers (2)

Döme
Döme

Reputation: 833

This way works fine for me.

customer_id = fields.Many2one(
    string='Customer',
    related='nomor_hp_id.customer_id',
    store=True,
)

Upvotes: 0

You have to give comodel name inside Many2one field either it is normal Many2one or related Many2one. Please have a look at below code. You will get your answer.

nomor_hp_id = fields.Many2one(string='Nomor hp', comodel_name='nomor.hp',ondelete='cascade',)

customer_id = fields.Many2one(string='Customer', comodel_name='res.partner', related='nomor_hp_id.customer_id', ondelete='cascade',readonly=True,)

You have to define the reference of which table. Here customer_id is the reference field of the "res_partner" table or "res.partner" model.

Upvotes: 1

Related Questions