Skip to Content
Menú
This question has been flagged
2 Respostes
3168 Vistes

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...
Avatar
Descartar
Best Answer

<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>  

 

Avatar
Descartar
Best Answer

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

Avatar
Descartar
Autor

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.

Autor

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.

Related Posts Respostes Vistes Activitat
3
de març 25
7742
0
de gen. 24
1449
2
de set. 23
9118
0
de set. 20
38
4
de maig 18
12972