5

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
forvas
  • 9,801
  • 7
  • 62
  • 158
Kiran
  • 1,481
  • 6
  • 36
  • 66

4 Answers4

14

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
Alessandro Ruffolo
  • 1,575
  • 1
  • 16
  • 34
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.

Jainik Patel
  • 2,284
  • 1
  • 15
  • 35
1

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)

LINK

Community
  • 1
  • 1
Prashant
  • 704
  • 10
  • 23
0

Be careful, you have to use the same kind of field !!

(I had the problem with Selection and Char ... so I have to use Selection with Selection)

jteks
  • 603
  • 7
  • 15