콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4182 화면

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?
아바타
취소
베스트 답변

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!

아바타
취소
관련 게시물 답글 화면 활동
0
3월 24
1624
0
11월 23
1693
2
9월 23
3925
0
4월 18
3560
2
3월 15
5974