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 convert Islamic date to Hijri date using python code?(My code shows error)

By
Remya
on 5/7/14, 2:47 AM 1,976 views

I have two textbox.

In first textbox i'll manually enter islamic date, at the same time on the second textbox it changes to geogorian date.

I wrote code for it, but its shows error.

from openerp.osv import fields, osv

import math

def intPart(floatNum):

    if floatNum < -0.0000001: return math.ceil(floatNum - 0.0000001)

    return math.floor(floatNum + 0.0000001)

def Hijri2Gregorian(yr,mth,day):

    jd1 = intPart((11 * yr + 3) / 30.0)

    jd2 = intPart((mth - 1) / 2.0)

    jd = jd1 + 354 * yr + 30 * mth - jd2 + day + 1948440 - 385

    if jd > 2299160:

    l = jd + 68569

    n = intPart((4 * l) / 146097.0)

    l = l - intPart((146097 * n + 3) / 4.0)

    i = intPart((4000 * (l + 1)) / 1461001.0)

    l = l - intPart((1461 * i) / 4.0) + 31

    j = intPart((80 * l) / 2447.0)

    d = l - intPart((2447 * j) / 80.0)

    l = intPart(j / 11.0)

    m = j + 2 - 12 * l

    y = 100 * (n - 49) + i + l

    else:

    j = jd + 1402

    k = intPart((j - 1) / 1461.0)

    l = j - 1461 * k

    n = intPart((l - 1) / 365.0) - intPart(l / 1461.0)

    i = l - 365 * n + 30

    j = intPart((80 * i) / 2447.0)

    d = i - intPart((2447 * j) / 80.0)

    i = intPart(j / 11.0)

    m = j + 2 - 12 * i

    y = 4 * k + n + i - 4716

    return y, m, d

 

class hr_extra(osv.osv):

_inherit = "hr.employee"

def _get_hijr_date(self, cr, uid, ids, name, arg,context=None):

res = {}

for self_data in self.browse(cr, uid, ids, context=context):

    islamic_date = self_data.islamic_date

    # get Pass yesr, month and day in this function

    Hijri2Gregorian(yr,mth,day)

   return res

_columns = {

    'islamic_date' : fields.char('Islamic Date'),

    'english_date' : fields.function(Hijri2Gregorian,'English Date'), }

hr_extra()

 

Error: TypeError: Hijri2Gregorian() takes exactly 3 arguments (7 given)

 

Updated Code

 

class hr_extra(osv.osv):

_inherit = "hr.employee"

def _get_hijri_date(self, cr, uid, ids, name, args, context=None):

    res = {}

    for self_data in self.browse(cr, uid, ids, context=context):

        islamic_date = self_data.islamic_date

        islamic_date = '%.2f' % islamic_date

        list = str(islamic_date).split('.')

        yr = islamic_date(int(list[0]))

        mth = islamic_date(int(list[1]))

        day = islamic_date(int(list[2]))

        # get Pass yesr, month and day in this function

        #yr = 1428

        #mth = 1

        #day = 2

Hijri2Gregorian(yr,mth,day)

return res _

columns = {

    'islamic_date' : fields.char('Islamic Date'),

    'english_date' : fields.function(_get_hijri_date,type='date', select=True,string='English Date'), }

hr_extra()

 

Is this code correct?? Please help me...

update the log or error message for ur updated code ?

senthil
on 5/7/14, 3:52 AM

Module installed: When i click on the existing employee. It shows error: File "/opt/openerp/server/openerp/addons/date22/hr_date.py", line 52, in _get_hijri_date list = islamic_date.split('.') AttributeError: 'bool' object has no attribute 'split'

Remya
on 5/7/14, 4:20 AM

When i created new employee and give islamic date as 1428.1.2, then save. i got error: File "/opt/openerp/server/openerp/addons/date22/hr_date.py", line 53, in _get_hijri_date yr = islamic_date(str(list[0])) TypeError: 'unicode' object is not callable

Remya
on 5/7/14, 4:21 AM

Any idea, senthilnathan?

Remya
on 5/7/14, 5:59 AM

if it says bool then there is no data so it can't split

senthil
on 5/7/14, 4:05 PM

unicode error means u need to convert it before passing print type of the value passed and check

senthil
on 5/7/14, 4:06 PM

Did you know the code?

Remya
on 5/8/14, 4:36 AM

Did you know solve the issue?

Remya
on 5/8/14, 4:40 AM

How i convert these values?

Remya
on 5/9/14, 4:08 AM

Did you mean to Hijri to Gregorian?

Hesham ELMAHDY
on 12/24/14, 5:16 AM
0

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 12/24/14, 9:50 AM

Could you try this:

class hr_extra(osv.osv):

_inherit = "hr.employee"

 def _get_hijri_date(self, cr, uid, ids, name, args, context=None):

      res = {}

      for self_data in self.browse(cr, uid, ids, context=context):

          islamic_date = self_data.islamic_date

          list = str(islamic_date).split('.')

         yr = int(list[0])

         mth = int(list[1])

         day =int(list[2])

         # get Pass yesr, month and day in this function

         #yr = 1428

         #mth = 1

         #day = 2

        Hijri2Gregorian(yr,mth,day)

return res

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

2 follower(s)

Stats

Asked: 5/7/14, 2:47 AM
Seen: 1976 times
Last updated: 3/16/15, 8:10 AM