我的模块中有一个 barcode 字段(类型:字符),它包含使用 barcode scanner 扫描的产品的 scanned barcode value . 此扫描的产品将添加到 POS order 中的 line 字段(类型:一个2多个)中 . 在此之后,应该为下一个产品的条形码清除 barcode 字段 . This work in Odoo10 但是,它不适用于Odoo11 . 在Odoo11中,对于onchange的工作,我们必须更改该条形码字段中的值,然后按Enter键或单击“保存”按钮并进行编辑 . 然后它会工作 . 但是,我需要在扫描后,该字段应该被清除 . 我在下面给出了一段代码 . 等待正确的解决方案 . 提前致谢 . :)

class PosOrder(models.Model):
    _inherit = "pos.order"

    barcode = fields.Char('Product')

    @api.multi
    @api.onchange('barcode')
    def _onchange_barcode(self):
        for record in self:
            #my codes
            record.barcode = ""
            print ("Value in Barcode field is ",record.barcode,". Have nice time")

上面的代码将在终端中打印以下行:条形码字段中的值为 . 玩得开心它将条形码字段设置为空白,但不会影响前端 . 我附上了截图 .
enter image description here