I wanna show only one of these three in Odoo but I seem to not do it. I have tried importing datetime module and doing datetime.now().year but Odoo isn't recognizing it. How do I solve this?
Many thanks!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I wanna show only one of these three in Odoo but I seem to not do it. I have tried importing datetime module and doing datetime.now().year but Odoo isn't recognizing it. How do I solve this?
Many thanks!
By context i think it is a function call problem. To import correctly the datetime module you should do this:
from datetime import datetime
current_year = datetime.now().year
print(current_year)
But then it says "field current_year doesn't exist". I have another option where I could just strip each piece from Odoo's datetime field but to me looks performance expensive doing stripping where I may have easier ways.
Ok. Your issue is clearer now. Try this:
from datetime import datetime
from odoo import models, fields
class MyModel(models.Model):
_name = 'my.model'
current_year = fields.Integer(string='Current Year', default=lambda self: datetime.now().year)
Big UP Bro! It really worked! But I have this problem that year 2023 is with a comma as 2,023. I have searched and tried like "widget='integer' " and also added the format options but it didn't work too. How do I solve this?
You can edit the field to Char. Try this:
current_year = fields.Char(string='Current Year', default=lambda self: datetime.now().year)
Bless you my friend! It worked like a charm!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
DaftarPost Terkait | Replies | Tampilan | Aktivitas | |
---|---|---|---|---|
|
1
Apr 22
|
2646 | ||
How to track One2many field in Odoo12?
Diselesaikan
|
|
3
Nov 23
|
17302 | |
Error: Couldn't load module web
Diselesaikan
|
|
3
Nov 24
|
24897 | |
How I get the current ID of a record ?
Diselesaikan
|
|
1
Apr 23
|
6060 | |
Binary field as attachment in mail in Odoo 13
Diselesaikan
|
|
2
Des 22
|
6783 |