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

I'm working on the project.task  module. I extended the model with a datetime field and extended the view so that I set the attribute required to true. Now I need a to fill this fields with a button so the user can "take" the task. 

But when the button is pressed I get the red popup "The following fields are invalid".

def take_over_task(self):
        uid = self._context.get('uid')
        now = datetime.now(pytz.timezone('Europe/Ljubljana'))

        self.sudo().task_start = datetime.strftime(now, DEFAULT_SERVER_DATETIME_FORMAT)
        self.sudo().date_deadline = datetime.strftime((now + timedelta(days=1)), DEFAULT_SERVER_DATETIME_FORMAT)
        self.sudo().user_id = uid

I know I could just execute a SQL and write this fields directly into the DB, but would like to do this a better correct way.



 

아바타
취소
베스트 답변

The point is that when you push any Odoo button, before the actual method is executed the current record is saved (either 'created' or 'written'). It means, that check for 'required' and being filled is made before you fill the value in your method.

Basically, I can't see a reason to make a field required in case you fill it with the button (not manually). But if it is really needed, I would suggest the following:

  1. Make a field not required, but required under conditions. E.g. attrs="{'required': [('some_field', '=', True)]}"

  2. Make 'some_field' being True right in the button body. Thus, checks in write and create would be passed correctly until the button is actually pressed.

아바타
취소
작성자

hm... I don' exactly understand what you're saying. If I make the filed True with the button won't that return the same result? The problem is that I need to allow manually filling and with a quick button. Maybe I'll just make the fields not required and then fill them with default values.

작성자

It would probably work your way but I don't have time to figure out how. So I just removed the required attribute and check if the fields are set when the task gets to a certain stage with the api.constrains.

베스트 답변

Also you can use this module, that allow bypass required fields validation using special context

https://apps.odoo.com/apps/modules/10.0/xf_form_button_upgrade/

아바타
취소
관련 게시물 답글 화면 활동
2
12월 19
2953
0
11월 18
3247
2
11월 23
7482
2
5월 23
7724
2
3월 22
9768