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

Hi,


I was trying to update record by onchange function. It is not working.

Could you please anyone help me?!

If you have any other solution for it. Pls do suggest

odoo version : 13.0


class AssetMain(models.Model):

    _name = 'asset.asset'


    allocation_lines = fields.One2many('asset.allocation', 'asset_id', string='Allocation')

    current_employee = fields.Many2one('hr.employee', string="Allocated Employee")



class AssetAllocation(models.Model):

    _name = 'asset.allocation'

name = fields.Many2one('hr.employee', string="Employee")

asset_id = fields.Many2one('asset.asset', string="Asset")

@api.onchange('name')

    def _update_asset(self):

        for rec in self.asset_id:

if self.state == 'active'

rec.current_employee = self.name

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you Sudhir..

i have been resolved by below code.


def write(self, vals):
res = super(AssetAllocation, self).write(vals)
for rec in self.asset_id:
if self.state == 'active':
rec.current_employee = self.name
rec.current_branch = self.branch
return res
Câu trả lời hay nhất

It will not work with the onchange but you should do it in the create/write method because onchange is being executed at clientside and not serverside.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 21
2149
0
thg 1 21
2482
3
thg 3 24
7094
1
thg 8 24
14706
2
thg 3 24
7785