Я пытаюсь добавить сканер штрих-кода поверх модуля Inventory (точнее, поверх набора). Каждый раз, когда штрих-код сканируется, когда в окне выбора, он должен добавить один продукт, если он может найти его штрих-код. Я написал расширение для web.AbstractAction (в качестве примера я взял модуль Attendance), но до него нельзя добраться изнутри окна выбора. Мне явно не хватает какой-то точки, где мне нужно указать некоторые настройки, но я не знаю, где, и официальная документация не может задать мой вопрос.
Вот весь мой код для этой задачи:
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 framework?