odoo 10扫描条形码并开始动作

时间:2018-02-14 16:23:18

标签: javascript python odoo

using odoo 10在我的模块中,我通过创建带有条形码的维修订单来管理我的工作室,所以我想要做的是通过使用条形码扫描仪读取条形码值来点击按钮start_btn,这样我就可以扫描我的修复订单后启动计时器,在我的方法on_barcode_scanned上我已调用toggle_start按钮状态确实发生了变化,但计时器未启动

我被告知我必须使用javascript,所以我可以神奇地点击按钮,但我不知道该怎么做,等待你的帮助。

提前感谢,最好的关注。

class project_task(models.Model):
    _name = 'project.task'
    _inherit = ['project.task', 'barcodes.barcode_events_mixin']

    # _barcode_scanned is in the formview
    _barcode_scanned = fields.Char("Barcode Scanned", help="Value of the last barcode scanned.", store=False)

    def on_barcode_scanned(self, barcode):
        self.toggle_start()

在我看来:

            <div name="button_box" position="inside">
                <field name='test_barcode' options="{'barcode_events': 'True'}" widget="field_float_scannable"/>
                <button name="toggle_start" id="start_btn" type="object"
                        class="oe_stat_button" icon="fa-clock-o">
                    <field name="task_timer" widget="boolean_button"
                        options='{"terminology": {
                                "string_true": "Started",
                                "hover_true": "Pause",
                                "string_false": "Timer",
                                "hover_false": "Start"
                            }}'/>
                </button>
            </div>

1 个答案:

答案 0 :(得分:1)

我在arodoo_stock_barcode模块深入研究后发现的内容,以及project_task_timer您尝试使用的模块:

  • 您必须在模型中添加_barcode_scanned字段

    class project_task(models.Model):
        _name = 'project.task'
        _inherit = ['project.task', 'barcodes.barcode_events_mixin']
    
        # _barcode_scanned is in the formview
        _barcode_scanned = fields.Char("Barcode Scanned", help="Value of the last barcode scanned.", store=False)
        test_barcode = fields.Char("barcode")
    
  • 不要使用on_barcode_scanned方法:只使用javascript文件,以便如何操作:

    odoo.define('project_task_timer.MyScript', function (require) {
    "use strict";
        var core = require('web.core');
        var Model = require('web.Model');
        var flag = false;
        var FormViewBarcodeHandler = require('barcodes.FormViewBarcodeHandler');
    var _t = core._t;
    var MyScript = FormViewBarcodeHandler.extend({
    
    init: function (parent, context) {
        if (parent.ViewManager.action) {
            this.form_view_initial_mode = parent.ViewManager.action.context.form_view_initial_mode;
        } else if (parent.ViewManager.view_form) {
            this.form_view_initial_mode = parent.ViewManager.view_form.options.initial_mode;
        }
    },
    start: function () {
         });
       },
    pre_onchange_hook: function (barcode) {
    
        var barcode_filed = this.form_view.datarecord.test_barcode;
        var deferred = $.Deferred();
        if (barcode_filed === barcode) { 
           // to change the stage from new to being serviced              
               $(".o_form_view ul.oe_form_status_clickable li:nth-child(2)").click();
                $(".oe_button_box button:nth-child(3)").click();
    
            return deferred.reject();
        }
    },
    
    open_wizard: function (action) {
        var self = this;
        this.form_view.trigger('detached');
        this.do_action(action, {
            on_close: function () {
                self.form_view.trigger('attached');
                self.form_view.reload();
            }
        });
    }
    });
         core.form_widget_registry.add('myscript', MyScript);
         return MyScript;
    });
    

ps:如果你想将on_barcode_scanned方法添加到你继承的模型中,你可以这样做,但是你不能使用python单击一个按钮。

祝你好运。

相关问题