예제 #1
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #2
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #3
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #4
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #5
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #6
0
파일: views.py 프로젝트: ratna1234/nerp
def save_account(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    for index, row in enumerate(params.get('table_vm').get('rows')):
        entry = JournalEntry.objects.get(id=row.get('id'))
        try:
            account_row = entry.account_row
        except:
            account_row = InventoryAccountRow(journal_entry=entry)
        if row.get('expense_total_cost_price') == '':
            row['expense_total_cost_price'] = None
        if row.get('remaining_total_cost_price') == '':
            row['remaining_total_cost_price'] = None
        values = {
            'country_of_production_or_company_name':
            row.get('country_or_company'),
            'size': row.get('size'),
            'expected_life': row.get('expected_life'),
            'source': row.get('source'),
            'remarks': row.get('remarks'),
            'expense_total_cost_price': row.get('expense_total_cost_price'),
            'remaining_total_cost_price': row.get('remaining_total_cost_price')
        }
        account_row = save_model(account_row, values)
    return JsonResponse(dct)
예제 #7
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #8
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #9
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #10
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #11
0
파일: views.py 프로젝트: ratna1234/nerp
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)
예제 #12
0
파일: views.py 프로젝트: ratna1234/nerp
def approve_demand(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('id'):
        row = DemandRow.objects.get(id=params.get('id'))
    else:
        dct['error_message'] = 'Row needs to be saved before being approved!'
        return JsonResponse(dct)
    if not invalid(params, ['item_id', 'quantity', 'unit', 'release_quantity']):
        values = {'item_id': params.get('item_id'),
                  'specification': params.get('specification'),
                  'quantity': params.get('quantity'), 'unit': params.get('unit'),
                  'release_quantity': params.get('release_quantity'), 'remarks': params.get('remarks')}
        row = save_model(row, values)
    row.status = 'Approved'
    row.save()
    return JsonResponse(dct)
예제 #13
0
파일: views.py 프로젝트: ratna1234/nerp
def save_account(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    for index, row in enumerate(params.get('table_vm').get('rows')):
        entry = JournalEntry.objects.get(id=row.get('id'))
        try:
            account_row = entry.account_row
        except:
            account_row = InventoryAccountRow(journal_entry=entry)
        if row.get('expense_total_cost_price') == '':
            row['expense_total_cost_price'] = None
        if row.get('remaining_total_cost_price') == '':
            row['remaining_total_cost_price'] = None
        values = {'country_of_production_or_company_name': row.get('country_or_company'), 'size': row.get('size'),
                  'expected_life': row.get('expected_life'), 'source': row.get('source'), 'remarks': row.get('remarks'),
                  'expense_total_cost_price': row.get('expense_total_cost_price'),
                  'remaining_total_cost_price': row.get('remaining_total_cost_price')}
        account_row = save_model(account_row, values)
    return JsonResponse(dct)
예제 #14
0
파일: views.py 프로젝트: ratna1234/nerp
def approve_demand(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('id'):
        row = DemandRow.objects.get(id=params.get('id'))
    else:
        dct['error_message'] = 'Row needs to be saved before being approved!'
        return JsonResponse(dct)
    if not invalid(params,
                   ['item_id', 'quantity', 'unit', 'release_quantity']):
        values = {
            'item_id': params.get('item_id'),
            'specification': params.get('specification'),
            'quantity': params.get('quantity'),
            'unit': params.get('unit'),
            'release_quantity': params.get('release_quantity'),
            'remarks': params.get('remarks')
        }
        row = save_model(row, values)
    row.status = 'Approved'
    row.save()
    return JsonResponse(dct)