Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
22130 Переглядів

hello every body,

i need to unlink some lines in my one2Many field while adding news ..

i try this code:

class Devis(models.Model):
_inherit = 'sale.order'

@api.onchange('order_line')
def _onchange_price(self):
for record in self.order_line:
if record.product_id.typea == "t":
record.unlink()

but the instruction :

record.unlink()
do not work !
Аватар
Відмінити

update your question with logs if any, usually this is the method we are using to delete the records using unlink() method. so please check whether it is record.product_id.type and you have the correct value "t". if the type is a many2one field then you will get the id instead of name, if selection then check the values.

Найкраща відповідь

Hii,

Use filtered and update the recordset instead of calling unlink() :

from odoo import models, api


class Devis(models.Model):

    _inherit = 'sale.order'


    @api.onchange('order_line')

    def _onchange_price(self):

        self.order_line = self.order_line.filtered(lambda line: line.product_id.typea != 't')

try this 
i hope it is use full

Аватар
Відмінити
Найкраща відповідь

Hi,

Can you try use the following.

self.order_line = [(3, ID)]

ID = Id of record want to remove

Regards

Аватар
Відмінити
Найкраща відповідь

I think it's might help you.

def create_progress_history(self):
for task_id in self.task_ids:
for progress_history in task_id.task_progress_ids:
if progress_history.status == "forecast" or progress_history.status == False:
progress_history.unlink()
Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
вер. 23
144
2
січ. 24
16256
1
квіт. 17
6135
1
лип. 25
1940
1
трав. 24
10853