using odoo 10
在我的模块中,我通过使用条形码创建修理订单来管理车间,因此我要做的就是通过使用条形码扫描仪读取条形码值来单击按钮start_btn
,以便我可以在扫描我的维修单后启动计时器,在我的Methode 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>
我在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
Methode,则可以使用Python单击一个按钮。
祝你好运。