1

我正在尝试在 Inventory 模块顶部添加条形码扫描仪(更具体地说,在拣货顶部)。任何时候在拣货视图内扫描条形码时,如果可以找到其条形码,则必须添加一个完成的产品。我已经为“web.AbstractAction”编写了扩展(我以出勤模块为例),但无法从选择视图内部访问它。我显然错过了需要指定一些设置的地方,但我不知道在哪里,官方文档不能问我的问题。

这是我在这个任务上的所有代码:

static/js/barcode_scanner.js

odoo.define('stock.barcode_scanner', function(require) {
    'use sctrict';

    var AbstractAction = require('web.AbstractAction');
    var core = require('web.core');

    var BarcodeAction = AbstractAction.extend({

        start: function() {
            var self = this;
            core.bus.on('barcode_scanned', this, this._onBarcodeScanned);
            return this._super();
            // .then(function() {
            //     if (self.message_demo_barcodes) {
            //         self.setup_message_demo_barcodes();
            //     }
            // });
        },

        destroy: function () {
            core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
            this._super();
        },

        _onBarcodeScanned: function(barcode) {
            var self = this;
            core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
            this._rpc({
                    model: 'stock.picking',
                    method: 'product_scan',
                    args: [barcode, ],
                })
                .then(function (result) {
                    if (result.action) {
                        self.do_action(result.action);
                    } else if (result.warning) {
                        self.do_warn(result.warning);
                        core.bus.on('barcode_scanned', self, self._onBarcodeScanned);
                    }
                }, function () {
                    core.bus.on('barcode_scanned', self, self._onBarcodeScanned);
                });
        },

    });

    core.action_registry.add('stock_barcode_scanner', BarcodeAction);

    return {
        BarcodeAction: BarcodeAction,
    };
});

models/stock_picking.py

import logging
from odoo import models, api, _


_logger = logging.getLogger(__name__)


class Picking(models.Model):
    _inherit = "stock.picking"
    _description = "Extended Picking"

    @api.model
    def product_scan(self, barcode):
        _logger.info("i'm trying {}".format(barcode))
        return {'warning': _('%(barcode)s scanned') % {'barcode': barcode}}

views/stock_picking_views.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="stock_barcode_scanner_action" model="ir.actions.client">
            <field name="name">Pickings</field>
            <field name="tag">stock_barcode_scanner</field>
            <field name="target">fullscreen</field>
        </record>
    </data>
</odoo>

views/web_asset_backend_template.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="assets_backend" name="nickel_inventory assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/nickel_inventory/static/js/barcode_scanner.js"></script>
        </xpath>
    </template>

</odoo>

__manifest__.py

# -*- coding: utf-8 -*-
{
    'name': "nickel_inventory",

    'summary': """
    """,

    'description': """
    """,

    'author': "",
    'website': "",

    # Categories can be used to filter modules in modules listing
    # Check https://github.com/odoo/odoo/blob/13.0/odoo/addons/base/data/ir_module_category_data.xml
    # for the full list
    'category': 'Sales/Sales',
    'version': '0.1',

    # any module necessary for this one to work correctly
    'depends': ['base', 'product', 'stock'],

    # always loaded
    'data': [
        # 'security/ir.model.access.csv',
        'views/product_views.xml',
        'views/stock_picking_views.xml',
        'views/web_asset_backend_template.xml',
    ],
    # only loaded in demonstration mode
    'demo': [],
    'installable': True,
}

我错过了什么?它真的可以在 odoo 视图之上工作,还是我只能在 js 框架视图中使用它?

4

1 回答 1

1

如果有人好奇我是如何解决这个问题的——我已经为菜单项添加了绑定。就我而言,odoo 打开清晰的白页并听取键盘输入。

views/stock_picking_views.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="stock_barcode_scanner_action" model="ir.actions.client">
            <field name="name">Pickings</field>
            <field name="tag">stock_barcode_scanner</field>
            <field name="target">fullscreen</field>
        </record>

        <menuitem id="menu_stock_barcode_scanner" name="Barcode scanner" sequence="20" action="stock_barcode_scanner_action"/>
    </data>
</odoo>

下一步是用有用的表格和逻辑填充这个空白页面。

于 2019-11-22T15:20:26.820 回答