Skip to Content
Menu
This question has been flagged

Hi! 


I'm trying to show sale order payment term in picking form as a read-only field.

My code:


class stock_picking(models.Model):
    _inherit = 'stock.picking'

    payment_term_id = fields.Many2one(
        'sale.order','Payment Terms',
        related='sale_id.payment_term_id',
        readonly=True
    )

Compilation & Installation OK. BUT when trying to open delivery form I get an error:

Odoo Server Error
Traceback (most recent call last):
  File "C:\Odoo 13.0\server\odoo\api.py", line 753, in get
    value = self._data[field][record._ids[0]]
KeyError: 25


What is wrong? Any help will be greatly appreciated!!
Happy weekend for everyone.
Regards,

Antti
Avatar
Discard
Best Answer

Hi Antti Kukko ,

    Error is because you are given model name 'sale.order' , Change Model name to 'account.payment.term'

 payment_term_id = fields.Many2one('account.payment.term',

 string='Payment Terms',related='sale_id.payment_term_id',readonly=True,)

:)

Avatar
Discard
Author

You are exactly right!! Thanks!!

Best Answer

Hello,

I think you have not defined field correctly.

try this:


payment_term_id = fields.Many2one(
        'payment.term', string='Payment Terms',
        related='sale_id.payment_term_id',
        readonly=True
    )
Avatar
Discard
Author

This was a crucial advice!! Thank You very much!! I wrote the following and now it works!! Thank You!!

payment_term_id = fields.Many2one(

comodel_name='account.payment.term',

string='Payment Terms',

related='sale_id.payment_term_id',

readonly=True

)

in odoo 13, payment.term is the model name.

Alright your problem solved.

Best Answer

class stock_picking(models.Model):  Class name will be like

class StockPicking(models.Model) and run I am sure it will work.

Avatar
Discard
Author

Thank You I adopted this too. Nice weekend.

Related Posts Replies Views Activity
1
Feb 24
445
0
Jul 16
2400
0
May 15
5241
2
Jun 24
934
0
May 24
214