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