Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

367
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!