ODOO13:继承的javascript方法只执行一次有问题

2024-06-02 10:20:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我继承了模块stock_barcode(enterprise\stock_barcode\static\src\js\client_action\abstract_client_action.js)中的javascript方法

使用条形码扫描仪时,代码(在上面的路径中)在库存调整中起作用。

问题是,当我加载页面并调用我的条形码扫描仪时,会执行我的自定义方法,然后当我使用条形码扫描仪重播时,会调用本机方法。我的意思是,我的自定义方法被调用一次(在页面加载之后),本地方法在那之后被调用(第二次、第三次、第四次、第五次等)。

这是我的密码:

odoo.define('test_stock_barcode.ClientAction', function (require) {
"use strict";

var core = require('web.core');
var ClientAction = require('stock_barcode.ClientAction');
var GTINParser = require('custom_stock_barcode.GTINParser');

var client_action = ClientAction.include({
    _isProduct: function (barcode) {
        // natif method that being inherited
        // some codes
    },

    _getProductGTINs: function () {
        // some rpc call
    },

    willStart: function () {
        var self = this;
        var recordId = this.actionParams.pickingId || this.actionParams.inventoryId;
        return Promise.all([
            self._super.apply(self, arguments),
            self._getState(recordId),
            self._getProductBarcodes(),
            self._getProductGTINs(),
            self._getLocationBarcodes()
        ]).then(function () {
            return self._loadNomenclature();
        });
    },

    _step_product: function (barcode, linesActions) {
        var self = this;
        this.currentStep = 'product';
        var errorMessage;
        barcode = '010340093595583817230731100K17A';
        // barcode = '5901234123457';
        var temp_product = this._isProduct(barcode);
        var product = temp_product[0];
        barcode = temp_product[1] ? temp_product[1] : barcode;
        console.log('here');
        if (product) {
            if (product.tracking !== 'none') {
                this.currentStep = 'lot';
            }
            var res = this._incrementLines({'product': product, 'barcode': barcode});
            if (res.isNewLine) {
                if (this.actionParams.model === 'stock.inventory') {
                    // FIXME sle: add owner_id, prod_lot_id, owner_id, product_uom_id
                    return this._rpc({
                        model: 'product.product',
                        method: 'get_theoretical_quantity',
                        args: [
                            res.lineDescription.product_id.id,
                            res.lineDescription.location_id.id,
                        ],
                    }).then(function (theoretical_qty) {
                        res.lineDescription.theoretical_qty = theoretical_qty;
                        linesActions.push([self.linesWidget.addProduct, [res.lineDescription, self.actionParams.model]]);
                        self.scannedLines.push(res.id || res.virtualId);
                        return Promise.resolve({linesActions: linesActions});
                    });
                } else {
                    linesActions.push([this.linesWidget.addProduct, [res.lineDescription, this.actionParams.model]]);
                }
            } else {
                if (product.tracking === 'none') {
                    linesActions.push([this.linesWidget.incrementProduct, [res.id || res.virtualId, product.qty || 1, this.actionParams.model]]);
                } else {
                    linesActions.push([this.linesWidget.incrementProduct, [res.id || res.virtualId, 0, this.actionParams.model]]);
                }
            }
            this.scannedLines.push(res.id || res.virtualId);
            return Promise.resolve({linesActions: linesActions});
        } else {
            var success = function (res) {
                return Promise.resolve({linesActions: res.linesActions});
            };
            var fail = function (specializedErrorMessage) {
                self.currentStep = 'product';
                if (specializedErrorMessage) {
                    return Promise.reject(specializedErrorMessage);
                }
                if (!self.scannedLines.length) {
                    if (self.groups.group_tracking_lot) {
                        errorMessage = _t("You are expected to scan one or more products or a package available at the picking's location");
                    } else {
                        errorMessage = _t('You are expected to scan one or more products.');
                    }
                    return Promise.reject(errorMessage);
                }

                var destinationLocation = self.locationsByBarcode[barcode];
                if (destinationLocation) {
                    return self._step_destination(barcode, linesActions);
                } else {
                    errorMessage = _t('You are expected to scan more products or a destination location.');
                    return Promise.reject(errorMessage);
                }
            };
            return self._step_lot(barcode, linesActions).then(success, function () {
                return self._step_package(barcode, linesActions).then(success, fail);
            });
        }
    },
});

core.action_registry.add('stock_barcode_client_action', client_action);

return client_action;
});

我故意在代码中添加了console.log('here'),并在natif中添加了console.log(barcode),给出:dsqf, qdsf, dsq,如下图所示。

execution

我已经清理了浏览器缓存并更新了模块


Tags: selfidreturnifvarstockfunctionres