Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
4112 Zobrazení

Hi i am trying to add two new fields to the Barcode mobile view. I went through the default js code of odoo, but didn't find a way to add my custome fields to it.

Here is the default code stock_barcode/static/src/js/client_action/lines_widget.js

init: function (parent, page, pageIndex, nbPages) {
    this._super.apply(this, arguments);
    this.page = page; #don't know where this argument page coming from in argument list.
    this.pageIndex = pageIndex;
    this.nbPages = nbPages;
    this.mode = parent.mode;
    this.groups = parent.groups;
    this.model = parent.actionParams.model;
    this.show_entire_packs = parent.show_entire_packs;
    this.displayControlButtons = this.nbPages > 0 && parent._isControlButtonsEnabled();
    this.displayOptionalButtons = parent._isOptionalButtonsEnabled();
    this.isPickingRelated = parent._isPickingRelated();
    this.isImmediatePicking = parent.isImmediatePicking ? true : false;
    this.sourceLocations = parent.sourceLocations;
    this.destinationLocations = parent.destinationLocations;
    // detect if touchscreen (more complicated than one would expect due to browser differences...)
    this.istouchSupported = 'ontouchend' in document ||
                           'ontouchstart' in document ||
                           'ontouchstart' in window ||
                           navigator.maxTouchPoints > 0 ||
                           navigator.msMaxTouchPoints > 0;
},


In _renderLines function,



_renderLines: function () {
//Skipped some codes here
// Render and append the lines, if any.
    var $body = this.$el.filter('.o_barcode_lines');
    console.log('this model',this.model);
    if (this.page.lines.length) {
        var $lines = $(QWeb.render('stock_barcode_lines_template', {
            lines: this.getProductLines(this.page.lines),
            packageLines: this.getPackageLines(this.page.lines),
            model: this.model,
            groups: this.groups,
            isPickingRelated: this.isPickingRelated,
            istouchSupported: this.istouchSupported,
        }));
        $body.prepend($lines);
        for (const line of $lines) {
            if (line.dataset) {
                this._updateIncrementButtons($(line));
            }
        }
        $lines.on('click', '.o_edit', this._onClickEditLine.bind(this));
        $lines.on('click', '.o_package_content', this._onClickTruckLine.bind(this));
    }
In the above code, you can see this.page.lines field, i need to add my custom two more fields. Actually it's dead-end for me. Any solution?
Avatar
Zrušit
Nejlepší odpověď

Hi Kabeer,

To add new fields/values to the line widgets in the Barcode mobile view in Odoo14 Enterprise Edition, you need to modify the stock_barcode/static/src/js/client_action/lines_widget.js file. Here's how you can do it:

  1. Add your custom fields to the lines object in the _renderLines function.
javascriptCopy code_renderLines: function () {
    // Skipped some codes here
    // Render and append the lines, if any.
    var $body = this.$el.filter('.o_barcode_lines');
    console.log('this model',this.model);
    if (this.page.lines.length) {
        var $lines = $(QWeb.render('stock_barcode_lines_template', {
            lines: this.getProductLines(this.page.lines),
            packageLines: this.getPackageLines(this.page.lines),
            model: this.model,
            groups: this.groups,
            isPickingRelated: this.isPickingRelated,
            istouchSupported: this.istouchSupported,
            custom_field_1: 'custom value 1',
            custom_field_2: 'custom value 2',
        }));
        $body.prepend($lines);
        for (const line of $lines) {
            if (line.dataset) {
                this._updateIncrementButtons($(line));
            }
        }
        $lines.on('click', '.o_edit', this._onClickEditLine.bind(this));
        $lines.on('click', '.o_package_content', this._onClickTruckLine.bind(this));
    }
}
  1. Modify the stock_barcode_lines_template to include your custom fields. You can access these fields using .custom_field_1 and .custom_field_2.
phpCopy code
id="stock_barcode_lines_template">
    
    t-if="lines">
        
        t-foreach="lines" t-as="line">
            
            class="o_data_cell">
                t-esc="line.product_name"/>
                t-esc="line.custom_field_1"/>
                t-esc="line.custom_field_2"/>
            
            
        
    

These changes should allow you to add two new fields to the line widgets in the Barcode mobile view in Odoo14 Enterprise Edition.

Regards,

Team Ksolves!

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
bře 24
1591
0
lis 23
1664
2
zář 23
3869
0
dub 18
3514
2
bře 15
5928