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

Hello, I find it hard to understand why there is not a central calendar for all modules to use just as there is for mail. Anyway, now that is off my chest, I am trying to update records in the calendar.event module when a date/time is changed in the project.task model. I have no problems creating the record but updating it is causing me some grief. Here is the code I am working on:

@api.model
def write(self, vals):
print("Vals==================", vals)
# self.env['calendar.event'].write('3', {"name": vals['name'], "start": vals['planned_date_begin'], "stop": vals['planned_date_end']})
return super(ProjectTask, self).write(vals)
# return super().write(vals)


When I call the super write with either method, I get the following error:

  result = method(recs, *args, **kwargs)
TypeError: ProjectTask.write() takes 2 positional arguments but 3 were given
The above server error caused the following client error: null

I'm using v16.0.

Can anyone give me a few pointers as to how to fix it?

Thank you!


形象
丢弃
最佳答案

Hi,

You need to remove `@api.model` and try it like this.

def write(self, vals):

        return super().write(vals)

Your `Write` method for the model 'calendar.event' seems to be incorrect, as you cannot write to the database without an object. `self.env['calendar.event']` is not an object itself. You either need to create, browse, or search for an object using methods like \

`self.env['calendar.event'].create(...)`, 

`self.env['calendar.event'].browse(...)`, or 

`self.env['calendar.event'].search(...)`,

 unless you have a relational field that provides the object.


Hope it helps

形象
丢弃
编写者

Thank you. I was paying about with the write line and have it commented out. The solution you have provided is that the decorator needed to be removed. I'm not sure I understand why a decorator is needed for a create but not a write. Anyway, I can now move on. Thank you.

相关帖文 回复 查看 活动
5
3月 16
12278
0
3月 15
3784
1
3月 15
4477
7
6月 18
8223
0
5月 16
3267