跳至内容
菜单
此问题已终结
2 回复
1984 查看

I wanna asked why it delete all the Done(True) users in this code, it inherits the function from the parent module and override the function. I thought the function of child module will only delete the current user

====Child Module====

​# -*- coding: utf-8 -*-

from odoo import fields,models,api

class TodoTask(models.Model):
_inherit = 'todo.task'

name = fields.Char(help='What needs to be done?')
user_id = fields.Many2one('res.users','Responsible')
date_deadline = fields.Date('Deadline')

@api.multi
def do_clear_done(self):
domain = [('is_Done', '=', True),
'|', ('user_id', '=', self.env.uid),
('user_id', '=', False)]
dones = self.search(domain)
dones.write({'active': False})
return True

====Parent Module==== 

# -*- coding: utf-8 -*-
from odoo import models,fields,api

class TodoTask(models.Model):
_name = 'todo.task'
_descrption = 'To-Do Task'

name = fields.Char('Description' , required=True)
is_Done = fields.Boolean('Done?')
active = fields.Boolean('Active?',default=True)

@api.multi
def do_toggle_done(self):
for task in self:
task.is_Done = not task.is_Done
return True

@api.multi
def do_clear_done(self):
dones = self.search([('is_Done','=',True)])
dones.write({'active':False})
return True 

Thank u in advance :)

形象
丢弃
最佳答案

Hi MaryChan,

I don't see any code deleting the users. But I see the code which is de-activating (active=False) the Done Tasks:  dones.write({'active':False}) 

形象
丢弃
编写者 最佳答案

Hi sudhir, ahm when I CLicked the clear all button, the user where the done is checked was disappeared and I thought that the extended function of do_clear_done is removing only the specific user.

形象
丢弃

No. It does not remove the users but it de-activate the task as I said.

相关帖文 回复 查看 活动
4
2月 25
2613
1
8月 24
2201
2
11月 24
3328
3
10月 23
14862
2
2月 23
2488