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 compare a value if it between two values from a master table for a customized module need help....... [Closed]

By
Odoo
on 6/16/14, 8:11 AM 1,176 views

The Question has been closed for reason: too subjective and argumentative

by
Odoo
on 06/30/2014 08:31:50

Hi,

First here I explain my scenario and code pls replay...

eg: model 1(scheme.type.info ) form

Scheme Type   1

interval type   100

vacation criteria  2 ticket

model 2 :hr.employee

date_of join=1-01-2014

current_date=1-30-2014

eligibilty_details=value should come based on date_of join and current_date

 

Here a add a button Check,when I click on this button it first it returns the date difference between date_of join and current_date (eg :40 days),

after based on this days just compare  the field  (eg.interval type   100 days) type from   scheme.type.info ,if its there just returns the  vacation criteria (eg.vacation criteria  2 ticket) field.

suppose if the total_days=67 [from date comparison ]

then  how to check if these days between 50 and 100(use scheme.type.infomodel  interval type field )  ,here 50 means 'interval field from  scheme.type.info and 100 (interval) means next id from  scheme.type.info table  ----- please help ..... here i attached my code

__________________________________________

class hr_employee(osv.osv):

     _inherit='hr.employee'

_columns={
              'date_of_join' :fields.date('Date of Join',required=True),
              'current_date':fields.date('Applied date',require=True),
              'eligible_details':fields.char('Eligibility Details')

}

def  check_eligibility(self,cr,uid,ids,context=None):
         if ids:
             day_obj=self.read(cr,uid,ids,['date_of_join','current_date'],context=context)
             scheme_ids = self.pool.get('scheme.type.info').search(cr, uid, [], context=context)
             calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','scheme_id'],context=context)
             
             print "day_obj####################",day_obj
             print "scheme_ids################",scheme_ids
             print "calc_vacation#######################",calc_vacation
             
             
             dateformat="%Y-%m-%d"
             d1=datetime.strptime(day_obj[0]['date_of_join'],dateformat)
             d2=datetime.strptime(day_obj[0]['current_date'],dateformat)
             v1=d2-d1
             
             total_days=v1.days
             print "total_days",total_days
             
             if total_days <=calc_vacation[0]['interval']:
                    msg=calc_vacation[0]['criteria']   # How to change this code


             # here I need to  use the logic of check the date  based on worked days and returned the  msg,now i can return only one value based on total_days ,But i cant compare a date in between two intervals(eg.betwwn 50 and 100 days)

             else:
                   msg="Not a valid"
             vals={
                   'eligible_details':msg
                   }
             self.write(cr,uid,ids,vals)
        
         return True

hr_employee()

 

class scheme_type_info(osv.osv):
    
    _name='scheme.type.info'
    
    _columns={
              'scheme_id':fields.integer('Scheme Type',required=True,size=50),
              'interval':fields.integer('interval type ',required=True,size=64),
              'criteria':fields.text('vacation criteria',required=True,size=50),
              'active':fields.boolean('Active')
              }
    _sql_constraints=[('unique_scheme_id','unique(scheme_id)','Error! Enter unique scheme Id')]

    _sql_constraints=[('unique_interval','unique(interval)','Error! Enter unique Interval Type')]
    
scheme_type_info()

 

 

 

 

 

 

 

 


make the changes in the code like ---------------

for cal_val in calc_vacation:
                 interval = calc_vacation['interval']
                 print "Interval", interval
                 if total_days <= interval:
                    msg=calc_vacation['criteria']
             vals={
                   'eligible_details':msg
                   }
             self.write(cr,uid,ids,vals)

It populates errro like

interval = calc_vacation['interval']
TypeError: list indices must be integers, not str





On Mon, Jun 16, 2014 at 5:55 PM, prakash <prakash-jain-sunarctechnologies-com@openerp.my.openerp.com> wrote:

Is there any relation is available between two table?.. i.e many2one particular Employee assign to particular Scheme type Info or Particular Scheme type Info assign to particular Employee?...

--
prakash Sent by OpenERP S.A. using OpenERP. Access your messages and documents in Odoo



--
Thanks&Regards
Libu Koshy
Odoo
on 6/16/14, 9:25 AM
Hi,
Prakash

Actually the scenario is--

when i click on eligibility function first calculate the date difference of current_date-joining date=n days

then check the condition with master table field,  'interval':fields.integer('interval type ',required=True,size=64),

if total_days in between master forms any of intervals field  (like eg. if total days =67 ,from the date difference then check with master models interval fields ,suppose initially i set the master datas interval field like interval= 50,criteria="1 ticket", next data is interval= 100,criteria="2 ticket"  or interval= 200,criteria="3 ticket" ,then based on total days comparison ,corresponding criteria field should come ,now 67 is come between 50 and 100 based on master table ,then the corresponding criteria field should come ,ie.# criteria = 2 ticket )

This is the scenario.............



On Mon, Jun 16, 2014 at 6:55 PM, libu koshy <libukoshym@gmail.com> wrote:

make the changes in the code like ---------------

for cal_val in calc_vacation:
                 interval = calc_vacation['interval']
                 print "Interval", interval
                 if total_days <= interval:
                    msg=calc_vacation['criteria']
             vals={
                   'eligible_details':msg
                   }
             self.write(cr,uid,ids,vals)

It populates errro like

interval = calc_vacation['interval']
TypeError: list indices must be integers, not str





On Mon, Jun 16, 2014 at 5:55 PM, prakash <prakash-jain-sunarctechnologies-com@openerp.my.openerp.com> wrote:

Is there any relation is available between two table?.. i.e many2one particular Employee assign to particular Scheme type Info or Particular Scheme type Info assign to particular Employee?...

--
prakash Sent by OpenERP S.A. using OpenERP. Access your messages and documents in Odoo



--
Thanks&Regards
Libu Koshy



--
Thanks&Regards
Libu Koshy
Odoo
on 6/16/14, 12:35 PM
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 6/16/14, 8:43 AM

scheme_ids = self.pool.get('scheme.type.info').search(cr, uid, [], context=context)        calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','scheme_id'],context=context)

In below code to read only I record id value:-

calc_vacation[0]['interval']

If  below code to read all the record value:- [Try the below code to compare all the master id values]

for cal_val in calc_valcation:

     interval = calc_val['interval']

     print "Interval", interval

     if total_days <= interval:
                    msg=calc_val['criteria']  

 

Refer the link to check value between range http://stackoverflow.com/questions/13628791/how-do-i-check-if-int-is-between-the-range-of-two-numbers-tried-various-solutio

 

can u explain scenario in more details after comparing all the master records based on which condition?.. if condition meet then next steps what will do?..

Prakash
on 6/16/14, 9:09 AM

Hi Praksh, I make the changes in the code like --------------- dateformat="%Y-%m-%d" d1=datetime.strptime(day_obj[0]['date_of_join'],dateformat) d2=datetime.strptime(day_obj[0]['current_date'],dateformat) v1=d2-d1 total_days=v1.days print "total_days",total_days for cal_val in calc_vacation: interval = calc_vacation['interval'] print "Interval", interval if total_days

Odoo
on 6/16/14, 9:22 AM

after compard to master records... if total days

Odoo
on 6/16/14, 12:10 PM

Hi, Prakash Actually the scenario is-- when i click on eligibility function first calculate the date difference of current_date-joining date=n days then check the condition with master table field, 'interval':fields.integer('interval type ',required=True,size=64), if total_days in between master forms any of intervals field (like eg. if total days =67 ,from the date difference then check with master models interval fields ,suppose initially i set the master datas interval field like interval= 50,criteria="1 ticket", next data is interval= 100,criteria="2 ticket" or interval= 200,criteria="3 ticket" ,then based on total days comparison ,corresponding criteria field should come ,now 67 is come between 50 and 100 based on master table ,then the corresponding criteria field should come ,ie.# criteria = 2 ticket )

Odoo
on 6/16/14, 10:17 PM

Here ---------------calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','scheme_id'],context=context), here criteria is a text field so error comes from the list iteration

Odoo
on 6/16/14, 10:29 PM

How to compare 55 is in between 50 and 100 of master tables interval field

Odoo
on 6/16/14, 10:39 PM

total_days 42 inside for loop------------------------------------- def check_eligibility(self,cr,uid,ids,context=None): if ids: day_obj=self.read(cr,uid,ids,['date_of_join','current_date'],context=context) scheme_ids = self.pool.get('scheme.type.info').search(cr, uid, [], context=context) calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','scheme_id'],context=context) print "day_obj####################",day_obj print "scheme_ids################",scheme_ids print "calc_vacation#######################",calc_vacation dateformat="%Y-%m-%d" d1=datetime.strptime(day_obj[0]['date_of_join'],dateformat) d2=datetime.strptime(day_obj[0]['current_date'],dateformat) v1=d2-d1 total_days=v1.days print "total_days",total_days for cal_val in calc_vacation: print "inside for loop" interval1 = calc_vacation['interval'] print "########Interval###############################", interval1 if total_days

Odoo
on 6/17/14, 12:14 AM

Hi , Thanks Prakash,error is resolved ,but scenario is not completed yet ,means if total days is 56 in master table i set two intervals one for 50 days and one for 100 days ,then if 56 is total days ,then it should print 100 days criteria. how can i check this value in between 50 and 100 it should be print the criteria between 50 and 100

Odoo
on 6/17/14, 12:43 AM

Hi Prakash, I checked your link but ,i dont want any hard coded value ,i want to check with my existing scheme.type.info' table, interval field values,How its possible

Odoo
on 6/17/14, 3:39 AM
0
klacus
On 6/17/14, 1:11 AM

Hi.

You can use for timedelta for the comparsion the result will be in days:

http://stackoverflow.com/questions/8258432/days-between-two-dates-in-python

if days < 50:

       print 'code here what you need if days is smaller then 50'

else:

       print 'code here what you need if days is larger then 50'

 

or may I missunderstand your problem :-)

 

 

 

About This Community

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

Question tools

2 follower(s)

Stats

Asked: 6/16/14, 8:11 AM
Seen: 1176 times
Last updated: 3/16/15, 8:10 AM