How to use related fields (fields.related) in odoo-8?

I am trying to get the comment field (internal client notes) from res_partner to the invoice module. Now I just want to print it later. I will include it in the xml code. I tried in three ways:

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 
+5
source share
4 answers

Instead, you should use the appropriate field:

 comment = fields.Char(related='partner_id.comment') 

If you need to save it in an account_invoice entry, you also need to add the store = True parameter . The problem is that you cannot just print it, but if you need to show it, you need to put it in your view.

If you really need to print it temporarily, you need to do it differently:

 comment = fields.Char(compute='_compute_comment') def _compute_comment(self): for record in self: record.comment = partner_id.comment print record.comment 
+13
source

Linked Field

No more fields.related fields.

Instead, you simply specify the name argument for your model:

 participant_nick = fields.Char(string='Nick name', related='partner_id.name') 

The kwarg type is no longer needed.

Configuring the kwarg repository will automatically save the value to the database. With the new API, the value of the associated field will be automatically updated, sweet.

 participant_nick = fields.Char(string='Nick name', store=True, related='partner_id.name') 

Note

When updating any related area, not all translations of the related area are translated if the field is saved!

Changing related linked fields will invalidate the cache for all items in the chain.

+2
source

in odoo8

if you need the same object fields for this, then you can use related = "sibling field name" use store = True

 comment2 = fields.Char(string='comment',related='comment', store=True) 

LINK

+1
source

there is a problem with my sister field, I have two classes: nomenclature and projet_ligne. I want to get the value "sous" to "eta", so my code is there

 class nomenclature(models.Model): _name = 'nomenclature' name = fields.Char('Nom de la nomenclature',required=True) quantite = fields.Integer('Quantité',required=True) produit=fields.Many2one('product.product') sous= fields.Boolean('sous') class projet_ligne(models.Model): _name = 'projet.ligne' #name = fields.Char('nom du sous essaie',required=True) nomenclature=fields.Many2one('nomenclature',required=True) responsable=fields.Many2one('res.users',) projet = fields.Many2one('projet',required=True) date= fields.Date() etat=fields.Boolean('Achevé?') reference= fields.Char('Réference') nature= fields.Char('Nature') dateprelevement= fields.Date() lieuprelevement= fields.Char('lieu') etatvalider= fields.Boolean('Validé') eta= fields.Boolean(related='nomenclature.sous') 

Does not work:/

0
source

Source: https://habr.com/ru/post/1236599/


All Articles