Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
3629 Prikazi
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
Opusti
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
Opusti
Avtor

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

Thanks.

Answer updated.

Related Posts Odgovori Prikazi Aktivnost
1
jul. 18
3593
9
jun. 23
13005
2
jan. 22
3802
2
dec. 21
7816
0
jun. 21
1889