跳至内容
菜单
此问题已终结

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
形象
丢弃
最佳答案

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,)

:)

形象
丢弃
编写者

You are exactly right!! Thanks!!

最佳答案

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
    )
形象
丢弃
编写者

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.

最佳答案

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

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

形象
丢弃
编写者

Thank You I adopted this too. Nice weekend.

相关帖文 回复 查看 活动
1
2月 24
1775
0
7月 16
3571
0
5月 15
6528
2
6月 24
3232
0
5月 24
1287