Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
8365 Widoki

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.



 

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor

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.

Autor

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.

Najlepsza odpowiedź

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/

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
gru 19
2954
0
lis 18
3247
2
lis 23
7484
2
maj 23
7725
2
mar 22
9773