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

Is this a recursion problem? Whats the best way to write this function in openerp?

By
Ademola Oke
on 12/8/13, 2:42 AM 707 views

I'm relatively new to python and openerp and in my new module, I'm trying to write a function that does this:

monthly_pay = float(int(annual_pay_1 / number_of_months))
      annual_pay_2 = monthly_pay * number_of_months
      diff = annual_pay_1 - annual_pay_2
      jan_pay = monthly_pay + diff 
      feb_pay = jan_pay + monthly_pay
      mar_pay = feb_pay + monthly_pay 
      apr_pay = mar_pay + monthly_pay 
      may_pay = apr_pay + monthly_pay 
      jun_pay = may_pay + monthly_pay 
      jul_pay = jun_pay + monthly_pay 
      aug_pay = jul_pay + monthly_pay 
      sep_pay = aug_pay + monthly_pay 
      oct_pay = sep_pay + monthly_pay 
      nov_pay = oct_pay + monthly_pay 
      dec_pay = nov_pay + monthly_pay

Sometimes, the number or months may not be up to 12. It could be say 8 or 9 for instance and it doesn't necessarily start from january or end in december.

Is this a proper recursion or for loop problem? Whats the best way to write the function to handle this?

0
peterm
On 12/9/13, 3:55 AM

Could be this (not complete):

start_month=3
number_of_months=7
annual_pay_1=40000

monthly_pay = float(int(annual_pay_1 / number_of_months))
annual_pay_2 = monthly_pay * number_of_months
diff = annual_pay_1 - annual_pay_2

pay = [0] * 12

pay[start_month] = monthly_pay + diff 
for i in range(start_month+1, start_month+number_of_months):
   pay[i] = monthly_pay

print(pay)

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

0 follower(s)

Stats

Asked: 12/8/13, 2:42 AM
Seen: 707 times
Last updated: 3/16/15, 8:10 AM