Skip to Content
Menú
This question has been flagged
1 Respondre
1949 Vistes

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!


Avatar
Descartar
Best Answer

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

Avatar
Descartar
Autor

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.

Related Posts Respostes Vistes Activitat
5
de març 16
12266
0
de març 15
3778
1
de març 15
4475
7
de juny 18
8219
0
de maig 16
3266