Skip to Content
Menu
This question has been flagged
2 Replies
6963 Views

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.



 

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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.

Author

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.

Best Answer

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/

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 19
1648
0
Nov 18
2263
2
Nov 23
5926
2
May 23
5648
2
Mar 22
7908