Home > database >  Odoo - display partner name on stock.move.line
Odoo - display partner name on stock.move.line

Time:08-13

I'd like to display partner name (partner_id) on stock.move.line

Tried to inherit partner_id like this:

class StockMoveLine(models.Model):
    _inherit = 'stock.move.line'
    partner_name = fields.Many2one(related='partner_id')

This gives me error "KeyError: 'partner_id'"

I'm new in Odoo and have trouble with understanding inheritance of fields or relating, appreciate any help. Thank you.

CodePudding user response:

In many2one field you need to add comodel name not related attribute because it's relation between 2 tables ...

partner_name = fields.Many2one(comodel_name='res.partner')

CodePudding user response:

stock.move.line object has a 'picking_partner_id' field which represents the partner information of the picking document.

Field declared with related data type & readonly means it cannot be accessed via query.

Two things:

  1. If your purpose is to display value in the form view, then you need to extend the view and add a field at appropriate position.

  2. If you want to store value in database & use it in data science, then you need to extend field and add attribute store=True

    For example: picking_partner_id = fields.Many2one(store=True)

  • Related