Skip to Content
Menu
This question has been flagged
1 Reply
8662 Views

class similar_contact(models.Model):

_inherit= 'res.partner'

@api.onchange("name")

def onchange_name(self):

if self.name:

val=self.env['softandgrid'].search([('name','=','Name')])

self._cr.execute("SELECT b FROM rel2 WHERE b=%s",(val.id,))

res = self._cr.fetchall()

logging.info(res)===>([3,])

self._cr.execute("DELETE FROM rel2 WHERE b=%s",(val.id,))

class checked_criteria(models.Model):

_name="checked.criteria"

soft=fields.Many2many('softandgrid','rel1','a','b',string="Soft Duplicates Fields")

grid=fields.Many2many('softandgrid','rel2','a','b',string="Grid Duplicates Fields")

class softandgrid(models.Model):

_name="softandgrid"

name=fields.Char("Name")


self._cr.execute("DELETE FROM rel2 WHERE b=%s",(val.id,)) cannot delet records from rel2.

How to clear all datas from rel2?Thank You.

Avatar
Discard
Best Answer

You should learn more about the onchange decorator odoo. deletion and creation are not promoted here, it is dealing with virtual data and after the process, it is sent back to the client. If it is not returned back the data will not get saved.

This is the definition provided by odoo

""" Return a decorator to decorate an onchange method for given fields.
Each argument must be a field name::
@api.onchange('partner_id')
def _onchange_partner(self):
self.message = "Dear %s" % (self.partner_id.name or "")
In the form views where the field appears, the method will be called
when one of the given fields is modified. The method is invoked on a
pseudo-record that contains the values present in the form. Field
assignments on that record are automatically sent back to the client.
The method may return a dictionary for changing field domains and pop up
a warning message, like in the old API::
return {
'domain': {'other_id': [('partner_id', '=', partner_id)]},
'warning': {'title': "Warning", 'message': "What is this?"},
}
.. warning:: ``@onchange`` only supports simple field names, dotted names
(fields of relational fields e.g. ``partner_id.tz``) are not
supported and will be ignored"""


https://www.odoo.com/documentation/11.0/reference/orm.html#module-odoo.api

Avatar
Discard
Author

Thank You.

Related Posts Replies Views Activity
2
Jul 24
940
1
Jun 24
3561
1
Oct 23
8584
1
Oct 23
97
1
Aug 23
2192