简体   繁体   English

Odoo Javascript,如何访问此对象的值?

[英]Odoo Javascript, how can I access to the value of this object?

So I'm workin in POS module in Odoo 14, I've created a field in 'pos.order' called 'ticket_number' which is related to the id of the record.所以我在 Odoo 14 的 POS 模块中工作,我在“pos.order”中创建了一个名为“ticket_number”的字段,它与记录的 ID 相关。 So if the id is 15, the ticket_number will be 15 too.因此,如果 id 为 15,则ticket_number 也将为 15。 This field is already charged to the 'pos.order' model:此字段已被计入 'pos.order' 模型:

odoo.define("custom_pos_order.models", function (require) {
"use strict";

    var models = require('point_of_sale.models');

    models.load_fields('pos.order', 'id');
    models.load_fields('pos.order', 'ticket_number');

});

My purpose is to show this new field in the voucher when you get to the last screen:我的目的是在您到达最后一个屏幕时在凭证中显示这个新字段: POS 最后一屏

As you can see, in the red box I would like to show this field.如您所见,我想在红色框中显示此字段。

But, as this field is not native, I have to workaround with some Javascript.但是,由于这个领域不是原生的,我必须使用一些 Javascript 来解决。 I have this object in the console, and this object contains the value of the id of the order:我在控制台中有这个对象,这个对象包含订单的 id 值: JS 对象

So my question is, how can I access to that value in JS code, to assign it to a new variable?所以我的问题是,如何在 JS 代码中访问该值,并将其分配给一个新变量?

Please use the below line to load fields in a single line instead writing two and more lines for each fields请使用下面的行在一行中加载字段,而不是为每个字段写两行或更多行

models.load_fields("pos.order",['id','ticket_number']);

Also mention the field in the below function to get it in the receipt screen还要提及以下功能中的字段以在收据屏幕中获取它

get_receipt_render_env: function() {
    var order = this.pos.get_order();
    return {
        widget: this,
        pos: this.pos,
        order: order,
        receipt: order.export_for_printing(),
        orderlines: order.get_orderlines(),
        paymentlines: order.get_paymentlines(),
    };
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM