def get_month(passed_date=None, passed_month=None, passed_year=None): if passed_date == None and passed_month == None and passed_year == None: current_date_object = HijriDate.today() else: current_date_object = HijriDate(passed_year, passed_month, passed_date, gr=True) return int(current_date_object.month)
def compute_age_display(self): for rec in self: today_date = date(int(HijriDate.today().year), int(HijriDate.today().month), int(HijriDate.today().day)) gr_birthday = fields.Date.from_string(rec.birthday) hijri_birthday = HijriDate(gr_birthday.year, gr_birthday.month, gr_birthday.day, gr=True) birthday = date(int(hijri_birthday.year), int(hijri_birthday.month), int(hijri_birthday.day)) born = birthday.replace(year=today_date.year) if born > today_date: years = today_date.year - birthday.year - 1 else: years = today_date.year - birthday.year if today_date.month < birthday.month: if today_date.day < birthday.day: months = 12 - (birthday.month - today_date.month) - 1 else: months = 12 - (birthday.month - today_date.month) else: if today_date.day < birthday.day and today_date.month != birthday.month: months = today_date.month - birthday.month - 1 else: months = today_date.month - birthday.month if today_date.month == birthday.month: if today_date.day >= birthday.day: days = today_date.day - birthday.day else: days = birthday.day - today_date.day else: if today_date.day >= birthday.day: days = today_date.day - birthday.day else: days = (30 - birthday.day) + today_date.day res = str(years) + " سنة و" + str(months) + " شهر و " + str( days) + "يوم" rec.age_display = res
def test_get_date_when_en_is_true(self): today = HijriDate.today() date = int(today.day) - int(1) year = int(today.year) month = int(today.month) weekday = today.day_name_en result = hijricalendar.get_date(en=True) expect = { 'date': date, 'year': year, 'weekday': weekday, 'month': month } self.assertEquals(result, expect)
def test_get_date(self): today = HijriDate.today() date = bangla.convert_english_digit_to_bangla_digit( int(today.day) - int(1)) year = bangla.convert_english_digit_to_bangla_digit(int(today.year)) month = bangla.convert_english_digit_to_bangla_digit(int(today.month)) weekday = hijricalendar.weekdays_dict[today.day_name_en] result = hijricalendar.get_date() expect = { 'date': date, 'year': year, 'weekday': weekday, 'month': month } self.assertEquals(result, expect)
def get_date(passed_date=None, passed_month=None, passed_year=None, en=False, arabic=False): if passed_date == None and passed_month == None and passed_year == None: current_date_object = HijriDate.today() else: current_date_object = HijriDate(passed_year, passed_month, passed_date, gr=True) passed_year = int(current_date_object.year) passed_month = int(current_date_object.month) if arabic == 1: passed_date = int(current_date_object.day) else: passed_date = int(current_date_object.day) - int(1) passed_week = current_date_object.day_name_en hijri_date_month_year_bn = { 'date': bangla.convert_english_digit_to_bangla_digit(passed_date), 'month': bangla.convert_english_digit_to_bangla_digit(passed_month), 'year': bangla.convert_english_digit_to_bangla_digit(passed_year), 'weekday': weekdays_dict[passed_week], } hijri_date_month_year_en = { 'date': passed_date, 'month': passed_month, 'year': passed_year, 'weekday': passed_week, } if en == 1: return hijri_date_month_year_en else: return hijri_date_month_year_bn
def generate_file(self): # TODO: must check all fields fp = TemporaryFile() header_key = '000000000000' calendar_type = 'H' current_date = HijriDate.today() year = str(int(current_date.year)).zfill(4) month = str(int(current_date.month)).zfill(2) day = str(int(current_date.day)).zfill(2) send_date = year + month + day today = fields.Date.from_string(fields.Date.today()) value_date_g = today + relativedelta(days=14) hijri_date = HijriDate(value_date_g.year, value_date_g.month, value_date_g.day, gr=True) value_date = str(int(hijri_date.year)).zfill(4) + str( int(hijri_date.month)).zfill(2) + str(int(hijri_date.day)).zfill(2) total_amount = str(self.amount_total).replace('.', '').replace(',', '').zfill(15) total_employees = str(len(self.slip_ids)).zfill(8) account_number = str(self.env.user.company_id.vat or '').zfill(13) file_parameter = '1' file_sequence = '01' filler = ''.rjust(65, ' ') file_dec = '' file_dec += u'%s%s%s%s%s%s%s%s%s%s\n' % ( header_key, calendar_type, send_date, value_date, total_amount, total_employees, account_number, file_parameter, file_sequence, filler) for playslip in self.slip_no_zero_ids: employee = playslip.employee_id # add line for each playslip employee_number = employee.number.ljust(12, ' ') # search account bank for this employee banks = self.env['res.partner.bank'].search([ ('employee_id', '=', employee.id), ('is_deposit', '=', True) ]) if not banks: raise UserError(u"يجب إنشاء حساب بنكي للإيداع للموظف %s " % employee.display_name) employee_bank = banks[0] employee_bank_id = employee_bank.bank_id.bic.ljust(4, ' ') employee_account_number = employee_bank.acc_number.ljust(24, ' ') employee_name = '*****'.ljust(50, ' ') employee_amount = str(playslip.salary_net).replace( '.', '').replace(',', '').zfill(15) civilian_id = employee.identification_id and employee.identification_id.zfill( 15) or ''.zfill(15) employee_id_type = '0' process_flag = ' ' block_amount = ' ' kawadar_flag = ' ' filler = ''.rjust(11, ' ') file_dec += u'%s%s%s%s%s%s%s%s%s%s%s\n' % ( employee_number, employee_bank_id, employee_account_number, employee_name, employee_amount, civilian_id, employee_id_type, process_flag, block_amount, kawadar_flag, filler) # remove the \n file_dec = file_dec[0:len(file_dec) - 1] fp.write(file_dec.encode('utf-8')) fp.seek(0) bank_file_name = u'مسير جماعي شهر %s.%s' % (self.period_id.name, 'txt') self.bank_file = base64.encodestring(fp.read()) self.bank_file_name = bank_file_name fp.close() return True
def get_today_date(): date = HijriDate.today() return date
def test_get_month(self): result = hijricalendar.get_month() today = HijriDate.today() month = int(today.month) expect = month self.assertEquals(result, expect)