Skip to Content
Menu
This question has been flagged
2 Replies
4606 Views

I have an onchange function to update two fields on2many, when the function is executed odoo is deleting the records that related to them from database, here is my code:

@api.onchange('ticket_type_id')
def set_ticket_type_id(self):
if self.ticket_type_id and self.ticket_type_id.product_ids:
    self.write({'product_ids':[(6, 0, self.ticket_type_id.product_ids.ids)]})
if self.ticket_type_id and self.ticket_type_id.keywords_ids:
    self.keyword_ids = self.ticket_type_id.keywords_ids



and here is the messages from the log :
            odoo.models.unlink: User #2 deleted product.template records with IDs: [43] 

            odoo.models.unlink: User #2 deleted helpdesk.keywords records with IDs: [3]

Am I missing something !! 

Note: Odoo13

Avatar
Discard
Author Best Answer

Hilar AK, i just want to replacing the existing records, I followed what Odoo is doing in the final stage, it is executing the (2, id..) which is deleting from database, I don't know why.

(Can't comment on your reponse...)

Avatar
Discard

In your code you are using flag 6. which will do 5, _, _ unlink from existing one, 4, _, ids append new one

Author
Hello Hilarak,

 Thank you for your respond as I couldn't respond you in forum (it's been deleted in my profil)

The flag 6 will do 5 then Unlink with 4 that's right, when debugging, it is executing the 2 also which mean unlink and delete the record,
I don't know why yet, but I resolve the issue by changing the One2many to Many2many, and it's working fine (with the 6 flag)

I just want you to know, thanks again.


De : Hilar AK <hilarak@gmail.com>
Envoyé : mardi 16 juin 2020 12:57
À : Imed <imed08@hotmail.fr>
Objet : Re: Odoo is deleting my records !!
 

In your code you are using flag 6. which will do 5, _, _ unlink from existing one, 4, _, ids append new one


Sent by Odoo S.A. using Odoo.

Best Answer

The used flag in your answer will replace all existing records.

``(0, _, values)``
adds a new record created from the provided ``value`` dict.
``(1, id, values)``
updates an existing record of id ``id`` with the values in
``values``. Can not be used in :meth:`~.create`.
``(2, id, _)``
removes the record of id ``id`` from the set, then deletes it
(from the database). Can not be used in :meth:`~.create`.
``(3, id, _)``
removes the record of id ``id`` from the set, but does not
delete it. Can not be used in
:meth:`~.create`.
``(4, id, _)``
adds an existing record of id ``id`` to the set.
``(5, _, _)``
removes all records from the set, equivalent to using the
command ``3`` on every record explicitly. Can not be used in
:meth:`~.create`.
``(6, _, ids)``
replaces all existing records in the set by the ``ids`` list,
equivalent to using the command ``5`` followed by a command
``4`` for each ``id`` in ``ids``.

If you need to append, then use flag with 4

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1614
2
Apr 23
14533
1
Mar 23
1137
4
Aug 24
21119
0
Dec 21
1469