Пример #1
0
def save_application(request):
    params = json.loads(request.body)
    dct = {'categories': {}}
    model = ExpenseRow
    project_fy_id = params.get('project_fy_id')
    try:
        for cat_index, category in enumerate(params.get('categories')):
            dct['categories'][cat_index] = {'rows': {}}
            for ind, row in enumerate(category.get('rows')):
                if invalid(row, ['category_id', 'expense_id', 'amount']):
                    continue
                values = {
                    'category_id': row.get('category_id'),
                    'expense_id': row.get('expense_id'),
                    'amount': row.get('amount'),
                    'project_fy_id': project_fy_id,
                }
                submodel, created = model.objects.get_or_create(
                    id=row.get('id'), defaults=values)
                if not created:
                    submodel = save_model(submodel, values)
                dct['categories'][cat_index]['rows'][ind] = submodel.id
            delete_rows(category.get('deleted_rows'), model)
    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!'
    # delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)
Пример #2
0
def save_imprest_ledger(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    model = ImprestTransaction
    fy_id = params.get('fy_id')
    try:
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['date']):
                continue
            values = {'date': row.get('date', ''),
                      'name': row.get('name'),
                      'type': row.get('type'),
                      'date_of_payment': row.get('date_of_payment', ''),
                      'wa_no': row.get('wa_no'),
                      'amount_nrs': row.get('amount_nrs', None),
                      'amount_usd': row.get('amount_usd', None),
                      'exchange_rate': row.get('exchange_rate', None),
                      'fy_id': fy_id
                      }
            submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values)
            if not created:
                submodel = save_model(submodel, values)
            dct['rows'][ind] = submodel.id
    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!'
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)
Пример #3
0
def save_imprest_ledger(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    model = ImprestTransaction
    fy_id = params.get('fy_id')
    try:
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['date']):
                continue
            values = {
                'date': row.get('date', ''),
                'name': row.get('name'),
                'type': row.get('type'),
                'date_of_payment': row.get('date_of_payment', ''),
                'wa_no': row.get('wa_no'),
                'amount_nrs': row.get('amount_nrs', None),
                'amount_usd': row.get('amount_usd', None),
                'exchange_rate': row.get('exchange_rate', None),
                'fy_id': fy_id
            }
            submodel, created = model.objects.get_or_create(id=row.get('id'),
                                                            defaults=values)
            if not created:
                submodel = save_model(submodel, values)
            dct['rows'][ind] = submodel.id
    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!'
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)
Пример #4
0
def save_application(request):
    params = json.loads(request.body)
    dct = {'categories': {}}
    model = ExpenseRow
    project_fy_id = params.get('project_fy_id')
    try:
        for cat_index, category in enumerate(params.get('categories')):
            dct['categories'][cat_index] = {'rows': {}}
            for ind, row in enumerate(category.get('rows')):
                if invalid(row, ['category_id', 'expense_id', 'amount']):
                    continue
                values = {'category_id': row.get('category_id'),
                          'expense_id': row.get('expense_id'),
                          'amount': row.get('amount'),
                          'project_fy_id': project_fy_id,
                          }
                submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values)
                if not created:
                    submodel = save_model(submodel, values)
                dct['categories'][cat_index]['rows'][ind] = submodel.id
            delete_rows(category.get('deleted_rows'), model)
    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!'
    # delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)
Пример #5
0
def save_entry_report(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('type') == 'handover':
        source = Handover.objects.get(id=params.get('source_id'))
    else:
        source = PurchaseOrder.objects.get(id=params.get('source_id'))
    object_values = {
        'entry_report_no': empty_to_none(params.get('entry_report_no')),
        'fiscal_year': request.setting.fiscal_year,
        'source': source
    }
    if params.get('id'):
        obj = EntryReport.objects.get(id=params.get('id'))
    else:
        obj = EntryReport()
    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 = EntryReportRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['quantity', 'unit', 'item_id', 'rate']):
            continue
        if row.get('other_expenses') == '':
            other_expenses = 0
        else:
            other_expenses = row.get('other_expenses')
        values = {
            'sn': index + 1,
            'item_id': row.get('item_id'),
            'specification': row.get('specification'),
            'quantity': row.get('quantity'),
            'unit': row.get('unit'),
            'rate': row.get('rate'),
            'remarks': row.get('remarks'),
            'other_expenses': other_expenses,
            'entry_report': 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
        set_transactions(
            submodel,
            obj.source.date,
            ['dr', submodel.item.account, submodel.quantity],
        )
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)
Пример #6
0
def save_demand(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('release_no') == '':
        params['release_no'] = None
    object_values = {
        'release_no': params.get('release_no'),
        'fiscal_year': request.setting.fiscal_year,
        'date': params.get('date'),
        'purpose': params.get('purpose'),
        'status': 'Requested'
    }
    if params.get('id'):
        obj = Demand.objects.get(id=params.get('id'))
    else:
        obj = Demand()
        object_values['demandee_id'] = params.get('demandee')
    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 = DemandRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['item_id', 'quantity', 'unit']):
            continue
        # if row.get('release_quantity') == '':
        #     row['release_quantity'] = 1

        values = {
            'sn': index + 1,
            'item_id': row.get('item_id'),
            'specification': row.get('specification'),
            'quantity': row.get('quantity'),
            'unit': row.get('unit'),
            'release_quantity': row.get('release_quantity'),
            'remarks': row.get('remarks'),
            'demand': obj
        }
        submodel, created = model.objects.get_or_create(id=row.get('id'),
                                                        defaults=values)
        # set_transactions(submodel, request.POST.get('date'),
        #                  ['dr', bank_account, row.get('amount')],
        #                  ['cr', benefactor, row.get('amount')],
        # )
        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)
Пример #7
0
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)
Пример #8
0
def save_purchase_order(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    object_values = {
        'order_no': empty_to_none(params.get('order_no')),
        'fiscal_year': request.setting.fiscal_year,
        'date': params.get('date'),
        'party_id': params.get('party'),
        'due_days': params.get('due_days')
    }
    if params.get('id'):
        obj = PurchaseOrder.objects.get(id=params.get('id'))
    else:
        obj = PurchaseOrder()
    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 = PurchaseOrderRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['quantity', 'unit', 'rate', 'item_id']):
            continue
        if row.get('budget_title_no') == '':
            row['budget_title_no'] = None
        values = {
            'sn': index + 1,
            'item_id': row.get('item_id'),
            'specification': row.get('specification'),
            'rate': row.get('rate'),
            'quantity': row.get('quantity'),
            'unit': row.get('unit'),
            'vattable': row.get('vattable'),
            'budget_title_no': row.get('budget_title_no'),
            'remarks': row.get('remarks'),
            'purchase_order': obj
        }
        submodel, created = model.objects.get_or_create(id=row.get('id'),
                                                        defaults=values)
        # set_transactions(submodel, request.POST.get('date'),
        #                  ['dr', bank_account, row.get('amount')],
        #                  ['cr', benefactor, row.get('amount')],
        # )
        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)
Пример #9
0
def save_handover(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    object_values = {
        'addressee': params.get('addressee'),
        'fiscal_year': request.setting.fiscal_year,
        'date': params.get('date'),
        'office': params.get('office'),
        'type': params.get('type'),
        'designation': params.get('designation'),
        'voucher_no': empty_to_none(params.get('voucher_no')),
        'due_days': params.get('due_days'),
        'handed_to': params.get('handed_to')
    }
    if params.get('id'):
        obj = Handover.objects.get(id=params.get('id'))
    else:
        obj = Handover()
    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 = HandoverRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['quantity', 'unit', 'item_id', 'total_amount']):
            continue
        values = {
            'sn': index + 1,
            'item_id': row.get('item_id'),
            'specification': row.get('specification'),
            'quantity': row.get('quantity'),
            'unit': row.get('unit'),
            'received_date': row.get('received_date'),
            'total_amount': row.get('total_amount'),
            'condition': row.get('condition'),
            'handover': 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)
Пример #10
0
def save_entry_report(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('type') == 'handover':
        source = Handover.objects.get(id=params.get('source_id'))
    else:
        source = PurchaseOrder.objects.get(id=params.get('source_id'))
    object_values = {'entry_report_no': empty_to_none(params.get('entry_report_no')),
                     'fiscal_year': request.setting.fiscal_year,
                     'source': source}
    if params.get('id'):
        obj = EntryReport.objects.get(id=params.get('id'))
    else:
        obj = EntryReport()
    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 = EntryReportRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['quantity', 'unit', 'item_id', 'rate']):
            continue
        if row.get('other_expenses') == '':
            other_expenses = 0
        else:
            other_expenses = row.get('other_expenses')
        values = {'sn': index + 1, 'item_id': row.get('item_id'),
                  'specification': row.get('specification'),
                  'quantity': row.get('quantity'), 'unit': row.get('unit'), 'rate': row.get('rate'),
                  'remarks': row.get('remarks'), 'other_expenses': other_expenses,
                  'entry_report': 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
        set_transactions(submodel, obj.source.date,
                         ['dr', submodel.item.account, submodel.quantity],
        )
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)
Пример #11
0
def save_demand(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('release_no') == '':
        params['release_no'] = None
    object_values = {'release_no': params.get('release_no'), 'fiscal_year': request.setting.fiscal_year,
                     'date': params.get('date'), 'purpose': params.get('purpose'), 'status': 'Requested'}
    if params.get('id'):
        obj = Demand.objects.get(id=params.get('id'))
    else:
        obj = Demand()
        object_values['demandee_id'] = params.get('demandee')
    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 = DemandRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['item_id', 'quantity', 'unit']):
            continue
        # if row.get('release_quantity') == '':
        #     row['release_quantity'] = 1

        values = {'sn': index + 1, 'item_id': row.get('item_id'),
                  'specification': row.get('specification'),
                  'quantity': row.get('quantity'), 'unit': row.get('unit'),
                  'release_quantity': row.get('release_quantity'), 'remarks': row.get('remarks'),
                  'demand': obj}
        submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values)
        # set_transactions(submodel, request.POST.get('date'),
        #                  ['dr', bank_account, row.get('amount')],
        #                  ['cr', benefactor, row.get('amount')],
        # )
        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)
Пример #12
0
def save_purchase_order(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    object_values = {'order_no': empty_to_none(params.get('order_no')), 'fiscal_year': request.setting.fiscal_year,
                     'date': params.get('date'), 'party_id': params.get('party'),
                     'due_days': params.get('due_days')}
    if params.get('id'):
        obj = PurchaseOrder.objects.get(id=params.get('id'))
    else:
        obj = PurchaseOrder()
    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 = PurchaseOrderRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['quantity', 'unit', 'rate', 'item_id']):
            continue
        if row.get('budget_title_no') == '':
            row['budget_title_no'] = None
        values = {'sn': index + 1, 'item_id': row.get('item_id'),
                  'specification': row.get('specification'), 'rate': row.get('rate'),
                  'quantity': row.get('quantity'), 'unit': row.get('unit'), 'vattable': row.get('vattable'),
                  'budget_title_no': row.get('budget_title_no'), 'remarks': row.get('remarks'),
                  'purchase_order': obj}
        submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values)
        # set_transactions(submodel, request.POST.get('date'),
        #                  ['dr', bank_account, row.get('amount')],
        #                  ['cr', benefactor, row.get('amount')],
        # )
        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)
Пример #13
0
def save_receipt(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    object_values = {'no': params.get('no'), 'fiscal_year': request.setting.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)
Пример #14
0
def save_handover(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    object_values = {'addressee': params.get('addressee'), 'fiscal_year': request.setting.fiscal_year,
                     'date': params.get('date'), 'office': params.get('office'), 'type': params.get('type'),
                     'designation': params.get('designation'), 'voucher_no': empty_to_none(params.get('voucher_no')),
                     'due_days': params.get('due_days'), 'handed_to': params.get('handed_to')}
    if params.get('id'):
        obj = Handover.objects.get(id=params.get('id'))
    else:
        obj = Handover()
    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 = HandoverRow
    for index, row in enumerate(params.get('table_view').get('rows')):
        if invalid(row, ['quantity', 'unit', 'item_id', 'total_amount']):
            continue
        values = {'sn': index + 1, 'item_id': row.get('item_id'),
                  'specification': row.get('specification'),
                  'quantity': row.get('quantity'), 'unit': row.get('unit'), 'received_date': row.get('received_date'),
                  'total_amount': row.get('total_amount'), 'condition': row.get('condition'),
                  'handover': 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)