跳至內容
選單
此問題已被標幟

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
1787
0
7月 16
3591
0
5月 15
6550
2
6月 24
3279
0
5月 24
1294