Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
1960 Ansichten

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
Verwerfen
Beste Antwort

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
Verwerfen
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.

Verknüpfte Beiträge Antworten Ansichten Aktivität
5
März 16
12278
0
März 15
3784
1
März 15
4477
7
Juni 18
8223
0
Mai 16
3267