Skip to Content
Menu
This question has been flagged
1 Reply
2821 Views
class DHACalendar(models.Model):
_inherit = "resource.resource"

calendar_id = fields.Many2one(
"resource.calendar", string='Working Time',
default=None,
required=False,
help="Define the schedule of resource")

@api.model
def default_get(self, fields):
res = super(DHACalendar, self).default_get(fields)
if not res.get('calendar_id') and res.get('company_id'):
company = self.env['res.company'].browse(res['company_id'])
res['calendar_id'] = None
return res

@api.model
def create(self, values):
values["calendar_id"] = False
return super(DHACalendar, self).create(values)

@api.onchange('company_id')
def _onchange_company_id(self):
if self.company_id:
self.calendar_id = None

https://github.com/odoo/odoo/blob/11.0/addons/resource/models/resource.py#L655-L715

In odoo11alue - Resource, I want to not set default value. But it sets default.

How to Fix it?

Thanks.






Avatar
Discard
Best Answer

Hi DHA, 

In that case:

@api.model

def create(self, values):

return super(DHACalendar, self).create(values)

// if you don't have any other code to add in create, then just delete it.

and what you need to do is :

@api.model

def default_get(self, fields):

res = super(DHACalendar, self).default_get(fields)

if 'calendar_id' in fields:

res['calendar_id'] = None

return res

Avatar
Discard
Author

If someone chooses "calendar_id" then the data will be incorrect.

Thanks.

Answer updated.

Related Posts Replies Views Activity
1
Jul 18
2822
9
Jun 23
11127
2
Jan 22
2729
2
Dec 21
6265
0
Jun 21
1005