Skip to Content
Menu
This question has been flagged
1 Reply
1903 Views

Hello,

i need to do some work with odoo 14, i have 10 employees and everyone of them has 100 company, he is responsable of the and he should visite them at less once in the months

I have three models 

1- employees [10 employees], they are users from res.users

2- companies [1000 company] this is a special  model developed by me 

-- field 1 : company name 

-- field 2 : responsible [many2one from res.users]

3- visits  this is a special  model developed by me

-- field 1 : date

-- field 2 :  responsible [many2one from res.users]

-- field 3 :  company  [many2one from company ] 

this all work fine for me 

i want know i the reel time the progress o every employee 

for exemple: 

- user 1 : 25% it's mean he visit 25 company of his 100 

- user 2 : 30%  it's mean he visit 30 company of his 100 

** 100 not fix maybe one had 100 another on 105 or 96 .....

so please what the best way to do this  

Avatar
Discard
Best Answer

Hi @mestoof

Hope you are doing well

For you to know the progress of each employee you will need to add a fields in the employee which will track the progress.

Here is the code that you could use for the solution make changes as per you code.

import calendar
from datetime import date, timedelta

Please find code in comment. 

I hope this will be helpful.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

class HrEmployee(models.Model):
_inherit = "hr.employee"

progress = fields.Integer("Progress", compute="_compute_visits_ratio")

def _compute_visits_ratio(self):
for record in self:
# find current month dates
month = date.today().month
year = date.today().year
number_of_days = calendar.monthrange(year, month)[1]
first_date = date(year, month, 1)
last_date = date(year, month, number_of_days)
delta = last_date - first_date
dates = [(first_date + timedelta(days=i)).strftime('%Y-%m-%d') for i in range(delta.days + 1)]

# find companies assigned to employee
companies = self.env["companies"].search([('user_id', '=', record.user_id.id)])

# find visits made by employee in current month
visits = self.env["visits"].search([('company_id', 'in', companies.ids), ('user_id', '=', record.user_id.id), ('date', 'in', dates)])

if visits:
record.progress = ((len(visits)/len(companies)) * 100)
else:
record.progress = 0