Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4037 Lượt xem

I got some issues on getting id from rest.partner in Odoo. I added compute field in stock.move.line called irLot. below is code sample.

class StockMoveLine(models.Model):
_inherit = 'stock.move.line'

irLot = fields.Char(string="Internal Reference", compute='_compute_ir')


def _compute_ir(self):
partner_id = self.picking_id.partner_id.id partner_obj = self.env['res.partner'] obj = partner_obj.search([('id','=',partner_id)]) for rec in obj: internal_ref = rec.ref self.irLot = internal_ref



so my problem is when I assign to partner_id variable. there is no value is coming out even though i assigned self.picking_id.partner_id.id. there is always showing False. so I assigned id directly and it works as below.

partner_obj = self.env['res.partner'] 
obj = partner_obj.search([('id','=','112')])


How can i get id value from self.picking_id.partner_id.id?
What did I do wrong? quite noob on odoo please suggest me.
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

It seems Partner field does not have any value. Make sure you have selected the partner in Partner field in picking.

In the code, you don't have to search the partner again. To have the partner recordset, just use this:

self.picking_id.partner_id # This will give you the recordset of the partner
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Arya answer is worked !

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 23
4438
2
thg 7 19
3080
1
thg 9 22
3459
1
thg 9 22
3625
1
thg 12 19
3136