Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1434 Vistas

Hello, i'm really struggling with an issue recently

i have a one2many / many2one relation between ResPartner/product.template.

i have a many2many widget to create the link between the two objects. 
(add products linked to the respartner)

However i have an api.onchange on a boolean that trigger the unlink that lead to an error :


ERROR adir odoo.sql_db: bad query: DELETE FROM "product_template" WHERE id IN (24)
ERROR: update or delete on table "product_product" violates foreign key constraint "sale_order_line_product_id_fkey" on table "sale_order_line"
DETAIL:  Key (id)=(32) is still referenced from table "sale_order_line".
WARNING adir odoo.http: L'opération ne peut pas être terminée : un autre modèle nécessite la suppression de l'enregistrement. Si possible, archivez-le à la place.
Modèle : Sales Order Line (sale.order.line)
Contrainte : sale_order_line_product_id_fkey


my code is when i do an api.onchange on a boolean : 

for product in self.custom_products :                

​self.write({'custom_products ' : [(3,product.id)]})

i really don't understand WHY there is query with a DELETE ???  


all my many2one fields avec ondelete='set null', tried also 'restrict'..... 

in product :

    product_custom_holder     = fields.Many2one('res.partner' ,ondelete='set null')

in res partner 
custom_products = fields.One2many('product.template')





Avatar
Descartar
Mejor respuesta

Hi,


Please use the following code for unblinking records from one2many field.


@api.onchange('boolean_filed')

def _inchange_boolean_filed(self)

    for product in self.custom_products :                


          self.write({'custom_products ' : [fileds.Command.unlink(product.id)]})


Please replace the 'boolean_filed' with your actual field name


Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
abr 25
1261
2
mar 24
1443
Odoo App Resuelto
1
nov 23
1822
0
may 24
1514
0
sept 23
2477