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
3
  • can u explain ur issue ????
    – Prashant
    Commented Nov 23, 2015 at 11:00
  • Option 1 written by you is proper answer for your question. Commented Nov 23, 2015 at 11:08
  • No I tried its not working i am getting error as keyerror:res_partner
    – Kiran
    Commented Nov 23, 2015 at 12:37

4 Answers 4

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
1
  • 1
    cool. Just remember to use the first solution when you don't need anymore to print it... Commented Nov 23, 2015 at 13:19
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.

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

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.