Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get total business days using month and year?

By
vadivel
on 9/1/16, 12:32 AM 189 views

Hi everyone,

I have a situation here.If i give month name(August) and year(2016) and  5.5 (5.5 means including saturday(1/2) ) or 5 (5 means monday-friday) or 6 (6 means monday-Saturday) days/per week as input then i need to calculate total business days for that month.

Please share me if any options or functions to achieve it.Thanks in advance.

1
Premananth
On 9/1/16, 6:12 AM

Hi

 

try this function

import calendar

def onchange_type(self,cr,uid,ids,type,month,year,context=None):

res = {}

cal = calendar.Calendar()

count = 0.0

if type and month and year:

if type == '5':

for week in cal.monthdayscalendar(int(year), int(month)):

for i, day in enumerate(week):

if i not in [5,6] and day > 0:

count += 1

elif type == '5.5':

for week in cal.monthdayscalendar(int(year), int(month)):

for i, day in enumerate(week):

if i not in [5,6] and day > 0:

count += 1

elif i == 5 and day > 0:

count += .5

elif type == '6':

for week in cal.monthdayscalendar(int(year), int(month)):

for i, day in enumerate(week):

if i not in [6] and day > 0:

count += 1

res = {'value':{

'no_of_days' : count

}}

return res

i hope this will help you.

1
Jerome Guerriat
On 9/1/16, 6:48 AM


Instead of using 5, 5.5 ad 6, i would add two boolean fields on the company: is_working_saturday and is_working_sunday.


Then i would iterate over the dates and test.

if date.isoweekday() < 6:

    total+=1

if date.isoweekday() == 6 and company.is_working_saturday:

    total +=1

if date.isoweekday == 7 and company.is_working_sunday:

    total +=1


This is not completely clean (i leave you the enhancement to do :D), but with a code like this you would even be able to compute number of business day for a company that work on sunday, but not on saturday

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/1/16, 12:32 AM
Seen: 189 times
Last updated: 9/1/16, 6:48 AM