Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
1967 Представления

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.

Related Posts Ответы Просмотры Активность
5
мар. 16
12278
0
мар. 15
3786
1
мар. 15
4478
7
июн. 18
8224
0
мая 16
3270