def get_or_create_for_fy(self, fy=None): if not fy: fy = FiscalYear.get() elif type(fy) in [int, str]: fy = FiscalYear.get(fy) return ProjectFy.objects.get_or_create(project=self, fy=fy)
def change_fiscal_year(request): if request.POST: old_fiscal_year = FiscalYear.get() new_fiscal_year_str = request.POST.get('fiscal_year') # app_setting.fiscal_year = new_fiscal_year_str # from dbsettings.models import Setting # fiscal_year_setting = Setting.objects.get(module_name='core.models', attribute_name='fiscal_year') # fiscal_year_setting.value = new_fiscal_year_str # fiscal_year_setting.save() from core.models import AppSetting app_setting = AppSetting.get_solo() app_setting.fiscal_year = new_fiscal_year_str app_setting.save() new_fiscal_year = FiscalYear.get(new_fiscal_year_str) fiscal_year_signal.send(sender=None, new_fiscal_year_str=new_fiscal_year_str, old_fiscal_year=old_fiscal_year, new_fiscal_year=new_fiscal_year) context = { 'has_permission': True, # required for user tools to show at admin 'fiscal_years': FISCAL_YEARS, 'current_fiscal_year': FiscalYear.get() } return render(request, 'change_fiscal_year.html', context)
def imprest_ledger(request, project_id): project = Project.objects.get(pk=project_id) context = { 'fy': FiscalYear.get(), 'project': project, } return render(request, 'imprest_ledger.html', context)
def save_receipt(request): params = json.loads(request.body) dct = {'rows': {}} object_values = { 'no': params.get('no'), 'fiscal_year': FiscalYear.get(AppSetting.get_solo().fiscal_year), 'date': params.get('date') } if params.get('id'): obj = Receipt.objects.get(id=params.get('id')) else: obj = Receipt() try: obj = save_model(obj, object_values) except Exception as e: if hasattr(e, 'messages'): dct['error_message'] = '; '.join(e.messages) elif str(e) != '': dct['error_message'] = str(e) else: dct['error_message'] = 'Error in form data!' dct['id'] = obj.id model = ReceiptRow for index, row in enumerate(params.get('table_view').get('rows')): if invalid(row, ['budget_head_id', 'account_id', 'tax_scheme_id']): continue values = { 'sn': index + 1, 'budget_head_id': row.get('budget_head_id'), 'account_id': row.get('account_id'), 'invoice_no': row.get('invoice_no'), 'nepal_government': row.get('nepal_government'), 'foreign_cash_grant': row.get('foreign_cash_grant'), 'foreign_compensating_grant': row.get('foreign_compensating_grant'), 'foreign_cash_loan': row.get('foreign_cash_loan'), 'foreign_compensating_loan': row.get('foreign_compensating_loan'), 'foreign_substantial_aid': row.get('foreign_substantial_aid'), 'advanced': row.get('advanced'), 'cash_returned': row.get('cash_returned'), 'advanced_settlement': row.get('advanced_settlement'), 'vattable': row.get('vattable'), 'tax_scheme_id': row.get('tax_scheme_id'), 'activity_id': row.get('activity_id'), 'remarks': row.get('remarks'), 'receipt': obj } submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values) if not created: submodel = save_model(submodel, values) dct['rows'][index] = submodel.id delete_rows(params.get('table_view').get('deleted_rows'), model) return JsonResponse(dct)
def save_receipt(request): params = json.loads(request.body) dct = {'rows': {}} object_values = {'no': params.get('no'), 'fiscal_year': FiscalYear.get(AppSetting.get_solo().fiscal_year), 'date': params.get('date')} if params.get('id'): obj = Receipt.objects.get(id=params.get('id')) else: obj = Receipt() try: obj = save_model(obj, object_values) except Exception as e: if hasattr(e, 'messages'): dct['error_message'] = '; '.join(e.messages) elif str(e) != '': dct['error_message'] = str(e) else: dct['error_message'] = 'Error in form data!' dct['id'] = obj.id model = ReceiptRow for index, row in enumerate(params.get('table_view').get('rows')): if invalid(row, ['budget_head_id', 'account_id', 'tax_scheme_id']): continue values = {'sn': index + 1, 'budget_head_id': row.get('budget_head_id'), 'account_id': row.get('account_id'), 'invoice_no': row.get('invoice_no'), 'nepal_government': row.get('nepal_government'), 'foreign_cash_grant': row.get('foreign_cash_grant'), 'foreign_compensating_grant': row.get('foreign_compensating_grant'), 'foreign_cash_loan': row.get('foreign_cash_loan'), 'foreign_compensating_loan': row.get('foreign_compensating_loan'), 'foreign_substantial_aid': row.get('foreign_substantial_aid'), 'advanced': row.get('advanced'), 'cash_returned': row.get('cash_returned'), 'advanced_settlement': row.get('advanced_settlement'), 'vattable': row.get('vattable'), 'tax_scheme_id': row.get('tax_scheme_id'), 'activity_id': row.get('activity_id'), 'remarks': row.get('remarks'), 'receipt': obj} submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values) if not created: submodel = save_model(submodel, values) dct['rows'][index] = submodel.id delete_rows(params.get('table_view').get('deleted_rows'), model) return JsonResponse(dct)