Odoo PoS dropdown from Many2one (widget.pos?)

I want to add a dropdown from a Many2one I’ve created to the pos.xml file (I know how to inherit from this), can someone help me with this?

I saw in the code that for every dropdown they used widget.pos.name, but this I can’t seem to find it anywhere. Here is an example for countries (here I want to replace it by my variable).

                <select class='detail client-address-country' name='country_id'>
                    <option value=''>None</option>
                    <t t-foreach='widget.pos.countries' t-as='country'>
                        <option t-att-value='country.id' t-att-selected="partner_country_id ? ((country.id === partner.country_id[0]) ? true : undefined) : undefined"> 
                            <t t-esc='country.name'/>
                        </option>
                    </t>
               </select>

I don’t know where the t-foreach=’widget.pos.countries’ comes from and how I can manage this for my own variable called “domain” which is part of a class “domainnames”. And called from a Many2one from res.partner

2 thoughts on “Odoo PoS dropdown from Many2one (widget.pos?)”

  1. Your Que: I saw in the code that for every dropdown they used widget.pos.name, but this I can’t seem to find it anywhere.

    Answer: widget.pos.name come from the In POS, models.js line No: 130., Here Server side model are loaded. This is the list of the models that need to be loaded from the server. in your custom module you can also load other models according to your requirement.

    Que: I don’t know where the t-foreach=’widget.pos.countries’ comes from and how I can manage this for my own variable?

    Answer: For Country widget, it comes from models.js line No: 178, model:’res.country’ loaded from the server.
    In line 180: You can see that in loaded function they define countries(loaded: function(self,countries)) // You can give any naming conventions here.
    So you can directly pass that function parameters in your (Many2One Field) xml file.

    Example:
    Write in your JS File of custom module:

        module.PosModel.prototype.models.push({ //loaded model
        model:  'res.partner',
            fields: ['partner_id','name'],
            loaded: function(self,partners){ //pass parameters
            self.partners = partners;
    
        },
    });
    

    In XML File:

           <div class='client-detail'>
            <span class='label'>Partner</span>
                <select class='detail client-partner' name='partner_id'>
                     <option value=''>None</option>
                        <t t-foreach='widget.pos.partners' t-as='partner'>
                          <option t-att-value='partner.id' t-att-selected="partner_partner_id ? ((partner.id === partner.partner_id) ? true : undefined) : undefined">
    
                           <t t-esc='partner.name'/>
                       </option>
                      </t>
                  </select>
        </div>
    

    So, Just like that: In your js, you can load any of the model here and fetch data in your XML file.
    Hope this will help you..!!!
    Thanks…!!!

    Reply

Leave a Comment