コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
3104 ビュー

I have created a button in POS product screen, to display a new screen. 

The js file for the button is : 

odoo.define('cdc_pos.ProductTotalSalesButton', function (require) {
    'use strict';
    const PosComponent=require('point_of_sale.PosComponent');
    const ProductScreen=require('point_of_sale.ProductScreen');
    const { useListener } =require("@web/core/utils/hooks");
    const Registries=require('point_of_sale.Registries');
    class ProductTotalSalesButton extends PosComponent {
    ​setup() {
          ​super.setup();
          ​​useListener('click', this.onClick);
        ​}
​​async onClick() {
                this.showScreen('ProductTotalSalesScreen')
        ​}                  
    }
    ProductTotalSalesButton.template='ProductTotalSalesButton';
   ProductScreen.addControlButton({
       component:ProductTotalSalesButton,
       condition:function() {
           returntrue;       },
    });
   Registries.Component.add(ProductTotalSalesButton);
   return ProductTotalSalesButton;
});

The button is added correctly and it is used to show a new screen called ProductTotalSalesScreen using the showScreen function.

The js and xml files for the new screen are:

odoo.define('cdc_pos.ProductTotalSalesScreen', function(require) {
    'use strict';
    const PosComponent=require('point_of_sale.PosComponent');
   const Registries=require('point_of_sale.Registries');
   class ProductTotalSalesScreen extends PosComponent {
        setup(){
            super.setup();
       }
        back() {
            this.showScreen('ProductScreen');
        }
    };
    ProductTotalSalesScreen.template='ProductTotalSalesScreen';
    Registries.Component.add(ProductTotalSalesScreen);
    return ProductTotalSalesScreen;
});

xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
    <t t-name="ProductTotalSalesScreen" owl="1">
        <div class="top-content">
            <div class="button back" t-on-click="back">
                Back
            div>
        div>
        <t t-foreach="[1, 2, 3]" t-as="i">
            <p><t t-out="i"/>p>
        t>
    t>
templates>
When I click the show ProductTotalSalesScreen, there is an error in the browser console which just says "undefined"

If I comment out the t-foreach loop then the screen is displayed.

Is there any reason why the t-foreach loop part causes the undefined error?
I can't make t-foreach work for this new screen template...
アバター
破棄
最善の回答

<tt-set="cp"t-value="env.pos.componente_activo"/>

<tt-foreach="cp"t-as="componente"t-key="componente.id"> 

<td style="width: 30%"class="text-center">

<tt-esc="componente.name"/>

td>  

 

アバター
破棄
最善の回答

Hi,

In this provided code there is an syntax mistake , update your code like this

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
    <t t-name="ProductTotalSalesScreen" owl="1">
        <div class="top-content">
            <div class="button back" t-on-click="back">
                Back
            </div>
        </div>
        <t t-foreach="[1, 2, 3]" t-as="i">
            <p><t t-out="i"/></p>
        </t>
    </t>
</templates>


Regards

アバター
破棄
著作者

Hi! Thanks for the answer!

My code is exactly as yours (The missing "</" parts were removed by the forum engine when I posted).

The problem is that the template works if I omit the t-foreach loop, displaying a page with only the Back button visible. As soon as I include the foreach part, then I get an 'undefined' error in my console. I've used the most simplified qweb t-foreach loop. It doesn't work. Neither does any other t-foreach loop (in the specific xml file). I have used many times t-foreach loops in my xml files without any problem. I can't understand why it throws an error now.

I actually followed a tutorial from your blog: https://www.cybrosys.com/blog/how-to-add-custom-screens-in-the-odoo-16-pos

The example I present here is a simplified version, just to present the problem I'm facing.

著作者

I just realized I can't use t-foreach, anywhere in POS xmls. It works in q-web reports, but not in POS screens or POS screen elements.

関連投稿 返信 ビュー 活動
3
3月 25
7308
0
1月 24
1400
2
9月 23
8877
0
9月 20
38
4
5月 18
12914