@api.depends('join_date', 'todays_time')
def compute_exprience(self):
for rec in self:
if rec.join_date and rec.todays_time:
r1 = datetime.datetime.strptime(str(self.todays_time), '%Y-%m-%d')
r2 = datetime.datetime.strptime(str(self.join_date), '%Y-%m-%d')
rec.Experience = (r1.year - r2.year)
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Financeiro
- Inventário
- PoS
- Project
- MRP
Esta pergunta foi sinalizada
Hi
amina lifam,
Try,
experience = fields.Char(string='Experience', compute='compute_experience')
@api.depends('join_date')
def compute_experience(self):
for rec in self:
if rec.join_date:
join_date = rec.join_date
current_date = fields.Date.today()
years_diff = current_date.year - join_date.year
months_diff = current_date.month - join_date.month
if current_date.day < join_date.day:
months_diff -= 1
if months_diff < 0:
years_diff -= 1
months_diff += 12
experience_str = '{} years {} months'.format(years_diff, months_diff)
rec.experience = experience_str
else:
rec.experience = 'N/A'
Output:
Hope it helps,
Kiran K
Try this:
from datetime import datetime
joining_date = datetime.strptime("join_date", "%Y-%m-%d")
today = datetime.today()
# Calculate total months and years
total_months = (today.year - joining_date.year) * 12 + (today.month - joining_date.month)
years, months = divmod(total_months, 12)
Then put it in rec.experience.....
Note: Don't use capital letter in fields like rec.Experience...
Está gostando da discussão? Não fique apenas lendo, participe!
Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!
Inscreva-sePublicações relacionadas | Respostas | Visualizações | Atividade | |
---|---|---|---|---|
|
1
jun. 25
|
1777 | ||
|
3
jul. 25
|
3381 | ||
|
1
mai. 25
|
1530 | ||
|
1
mai. 25
|
1788 | ||
|
4
mai. 25
|
2919 |