Search code examples
inheritanceodooodoo-14

Odoo - display partner name on stock.move.line


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.


Solution

  • From the official documentation:

    Related fields
    A special case of computed fields are related (proxy) fields, which provide the value of a sub-field on the current record.

    The value of a related field is given by following a sequence of relational fields and reading a field on the reached model. The complete sequence of fields to traverse is specified by the related attribute.

    You can use the move_id field to access the partner_id field on stock move

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