odoo js 抓取键盘输入

15 篇文章 4 订阅
1 篇文章 0 订阅

贴代码

odoo.define('Product.barcode', function (require) {
   "use strict";


var FormController = require('web.FormController');


    FormController.include({

        _barcodeScanned: async function (barcode, target) {
                this._super.apply(this, arguments);
                if (this.modelName === "stock.picking" && this.initialState.data.state === '新建'){
                    var date = await this._rpc({
                    "model": "stock.picking",
                    "method": "on_barcode_scanned",
                    "args": [this.initialState.res_id, barcode],
                });}
                this.reload();
        },
    });

});


#调用 models 模型函数方法
def _add_product(self, product, qty=1.0):
    order_line = self.move_lines.filtered(lambda r: r.product_id.id == product.id)
    if order_line:
        order_line.product_uom_qty += qty
        self.env.user.notify_success(message='添加物资:%s 成功' % product.name)
    else:
        product_lang = product.with_context({
            'lang': self.partner_id.lang,
            'partner_id': self.partner_id.id,
        })
        name = product_lang.display_name
        vals = {
            'product_id': product.id,
            'name': name,
            'product_uom': product.uom_id.id,
            'product_uom_qty': 1,
            'price_subtotal': product.purchase_price,
            'warehouse_id': product.warehouse_id.id,
        }
        self.move_lines = [(0, 0, vals)]
        self.env.user.notify_success(message='添加物资:%s 成功' % product.name)

def on_barcode_scanned(self, barcode):
    product = self.env['product.product'].search([('default_code', '=', barcode)])
    if product:
        self._add_product(product)
    else:
        self.env.user.notify_success(message='没有编码为:%s 的物资 ' % barcode)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值