我正在尝试创建一个将AD日期转换为BS日期的模块,但是我遇到了一个问题,即在进入AD日期时,odoo会继续加载小时和小时。我认为它在nepali_date中搜索,因此需要很长时间。我怎么解决这个问题? 提前谢谢你。
nepali_date=((2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),(2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),(2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31),(2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),(2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),(2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
(2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),(2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),(2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
(2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),(2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),(2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
(2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30),
(2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),(2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
(2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
(2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),(2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31),
(2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
(2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),(2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
(2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
(2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),(2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
(2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30),
(2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),(2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
(2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
(2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),(2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
(2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),(2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
(2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),(2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30),(2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),(2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31),(2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31),(2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),(2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30),(2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
(2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),(2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),(2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
(2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),(2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
(2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),(2081, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30),
(2082, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30),(2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30),
(2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30),(2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30),
(2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30),(2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30),
(2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30),(2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30),
(2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30))
start_english=datetime.date(1943,04,14)
end_english=datetime.date(2034,04,13)
start_nepali="2000/01/01"
class Date(models.Model):
_name = 'date'
english_date = fields.Char(required=True, string='English Date')
nep_date = fields.Char(compute='_converttonepali', store=True, string='Nepali Date')
@api.multi
@api.depends('english_date')
def _converttonepali(self):
yearsd = 2000
monthd = 1
eng_date = input(self.english_date)
engl_date = datetime.datetime.strptime(eng_date, '%Y/%m/%d')
engli_date = datetime.date(int(engl_date[0:4]), int(engl_date[5:7]), int(engl_date[8:]))# .strftime("%Y, %m, %d")
dayslapsed = (engli_date - start_english).days
for item in nepali_date:
for month in range(1, 13):
if dayslapsed >= item[month]:
monthd = month + 1
yearsd = int(item[0])
if monthd == 13:
monthd = 1
yearsd =yearsd + 1
self.nep_date = str(yearsd) + '/' + str(monthd) + '/' + str(dayslapsed + 1)
self.nep_date = datetime.date(int(self.nep_date[0:4]), int(self.nep_date[5:7]),int(self.nep_date[8:]))
return self.nep_date
答案 0 :(得分:0)
问题是odoo仍在等待值:
eng_date = input(self.english_date)
您只需删除input()
:
eng_date = self.english_date