Skip to Content
Menu
This question has been flagged
1300 Views

Hi fellow odoo'ers,


I have a field to display and select year. But the year is displayed as "2.022" - I want to get rid of the interpunctation. But because of function I need to have the field set to "Integer". Is there any work around I am missing, where I can display Integer for a single case without interpunctation.

sc_month = fields.Selection(MONTH_LIST, string='Month', required=True, index=True,
default=str(int(datetime.now().strftime('%m'))), tracking=True)

sc_year = fields.Integer("Year", default=datetime.now().strftime('%Y'), tracking=True, required=True)


@api.onchange('sc_year', 'sc_month')
def onchange_year_month(self):
if self.sc_year and self.sc_month:
month_date = date(self.sc_year, int(self.sc_month), 1)
self.sc_date_from = month_date.replace(day=1)
self.sc_date_to = month_date.replace(day=calendar.monthrange(month_date.year, month_date.month)[1])
else: raise UserError(_('Year and Month can not be left empty'))

@api.depends('sc_project_id.name', 'sc_year', 'sc_month', 'sc_cost_type_id.name')
def _get_budget_name(self):
for rec in self:
name = ''
if rec.sc_project_id:
name += ('/' if name else '') + rec.sc_project_id.name
if rec.sc_year:
name += ('/' if name else '') + str(rec.sc_year)
if rec.sc_month:
name += ('/' if name else '') + rec.sc_month
if rec.sc_cost_type_id:
name += ('/' if name else '') + rec.sc_cost_type_id.name
rec.name = name


Avatar
Discard

The correct approach is to save sc_year as a Date field and convert it to an integer where ever you want to compute other things based on its value.

Related Posts Replies Views Activity
3
Sep 24
9964
2
Feb 24
594
1
Jul 23
1000
2
Jun 23
1387
1
May 23
11434