How to use related fields (fields.related) in odoo-8?
Solution 1
You should use a related field instead:
comment = fields.Char(related='partner_id.comment')
If you need to store it in your account_invoice record you also need to add the parameter store=True Problem is, this way you can't just print it but if you need to show it you need to put it into your view.
If you really need to print it temporarly you need to do this other way:
comment = fields.Char(compute='_compute_comment')
def _compute_comment(self):
for record in self:
record.comment = partner_id.comment
print record.comment
Solution 2
Related Field
There is not anymore fields.related fields.
Instead you just set the name argument related to your model:
participant_nick = fields.Char(string='Nick name',
related='partner_id.name')
The type kwarg is not needed anymore.
Setting the store kwarg will automatically store the value in database. With new API the value of the related field will be automatically updated, sweet.
participant_nick = fields.Char(string='Nick name',
store=True,
related='partner_id.name')
Note
When updating any related field not all translations of related field are translated if field is stored!!
Chained related fields modification will trigger invalidation of the cache for all elements of the chain.
Solution 3
in odoo8
if need same object fields to related then you can use related="related field name " use store=True
comment2 = fields.Char(string='comment',related='comment', store=True)
Comments
-
Kiran almost 2 years
I am trying to retrieve comment field(customer internal notes) from res_partner to account invoice module.Right now I just want to print it later I will include it in xml code. I tried in three ways like this,
1)comment2 = fields.Char(string='Comment',related='res_partner.comment',compute='_compute_com') @api.multi def _compute_com(self): print self.comment2 2)comment = fields.Many2one('res.partner','Comment',compute='_compute_com') @api.multi def _compute_com(self): print self.comment 3)partner_comment = fields.Char(compute='_compute_com') @api.multi def _compute_com(self): Comment = self.env['res.partner'].browse(partner_id).comment print Comment
-
Alessandro Ruffolo over 8 yearscool. Just remember to use the first solution when you don't need anymore to print it...