Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
Add record using own button from JS (Odoo)?

I'm making my own list using the list_editable_renderer.js file and extending the one2many widget according to my needs, now I want to put an add button when creating a record in the attribute_line_ids field, currently Odoo saves when the save button is clicked but it What do I want to save when I click on my new button

enter image description here

My xml:

 <field name="attribute_line_ids" widget="table_one2many" context="{'show_attribute': False}" attrs="{'invisible':[('has_variants','=', False)]}" >
                                            <tree string="Variants" editable="top" multi_edit="1" options="{'only_one_row': 'True', 'add_record_button': 'True'}" >
                                                <field name="attribute_id" attrs="{'readonly': [('id', '!=', False)]}" string="Opción"/>
                                                <field name="value_ids" string="Valores (Sepáralos con un tab)" widget="many2many_tags_variaciones_bb" options="{'no_create_edit': False}" context="{'default_attribute_id': attribute_id, 'show_attribute': False}"/>
                                            </tree>
 </field>

My button action is:

'click tr .o_list_record_add': '_onAddIconClick',

and the function:

_onAddIconClick: function(event){
        this._onAddRecord(event,true)
},

My error is:

web.assets_backend.js:1144 Uncaught (in promise) TypeError: Cannot read property 'then' of undefined

I am not sure if it is the correct way or if you can guide me I would appreciate it.

Note: Odoo14

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Front JS new button:

 _onAddIconClick: function(event){
        var self = this;
        this._rpc({
            model: record.model,
            method: 'save_record',
            context: {
                    model: record.model,
                    record: record,
                },
        }).then(function () {
            self._render()
        });

    }

in the backend I collect the context and apply your criteria

@api.model
def save_record(self):
    record = self.env.context['record']
    pt = self.env['product.template'].sudo().browse(record['context']['params']['id'])
    if pt:
        attribute_id_rec = record['data']['attribute_id']
        value_ids_rec = record['data']['value_ids']
        obj ={}
        obj['has_variants'] = True
        value_ids = {}
        value_ids['attribute_id'] = attribute_id_rec['res_id']
        value_ids['value_ids'] = [[6, False, value_ids_rec['res_ids']]]
        lista = [[0, record['ref'], value_ids]]
        obj['attribute_line_ids'] = lista
        return pt.write(obj)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda