Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

377
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda