Hello,
I am trying to develop a desktop app with Odoo API, which will allow our staff to input the serial number of work orders via a specialized scanner. However, when I pass the value to Odoo via API, the value does not update on screen unless the user refreshes the screen. I tried using api.onchange() but it only triggers upon form modification, not when the value is written directly.
I was going in circles for days - If anyone can give me some pointers it will be greatly appreciated. Thanks!!
Below is the code on client (API) side:
#Write serial number to Work Order
print('Updating serial number to Work Order...')
models.execute_kw(db, uid, password, 'mrp.workorder', 'write',[[workorder_id],{'x_serial_number_id': serial_number_id}])
Below is the code on server (Odoo) side:
from odoo import models, fields, api
class RFID(models.Model):
_inherit = 'mrp.workorder'
x_serial_number_id= fields.Many2one('stock.production.lot', string='Received Serial Number', store=True)
@api.onchange('x_serial_number_id')
def update_serial_number(self):
for record in self:
if not record.final_lot_id: record.final_lot_id = record.x_serial_number_id
return False