콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2080 화면

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
12366
0
3월 15
3873
1
3월 15
4524
7
6월 18
8309
0
5월 16
3356