예제 #1
0
def cheque_deposit_save(request):
    if request.is_ajax():
        params = json.loads(request.POST.get("cheque_deposit"))
    dct = {"rows": {}}
    company = request.company
    if params.get("voucher_no") == "":
        params["voucher_no"] = None
    object_values = {
        "voucher_no": int(params.get("voucher_no")),
        "date": params.get("date"),
        "bank_account_id": params.get("bank_account"),
        "clearing_date": params.get("clearing_date"),
        "benefactor_id": params.get("benefactor"),
        "deposited_by": params.get("deposited_by"),
        "narration": params.get("narration"),
        "status": params.get("status"),
        "company": company,
    }
    if params.get("id"):
        obj = ChequeDeposit.objects.get(id=params.get("id"), company__in=request.company.get_all())
    else:
        obj = ChequeDeposit(company=request.company)
    model = ChequeDepositRow
    try:
        obj = save_model(obj, object_values)
        if request.FILES:
            dct["attachment"] = []
            for _file, description in zip(request.FILES.getlist("file"), request.POST.getlist("file_description")):
                attach_file = AttachFile.objects.create(attachment=_file, description=description)
                obj.files.add(attach_file)
                dct["attachment"].append(FileSerializer(attach_file).data)
        if params.get("file"):
            for i, o in enumerate(params.get("file")):
                attach_file_update = get_object_or_404(AttachFile, id=o.get("id"))
                attach_file_update.description = o.get("description")
                attach_file_update.save()
        dct["id"] = obj.id
        for ind, row in enumerate(params.get("table_view").get("rows")):
            if invalid(row, ["cheque_number", "amount"]):
                continue
            else:
                values = {
                    "sn": ind + 1,
                    "cheque_number": row.get("cheque_number"),
                    "cheque_date": row.get("cheque_date"),
                    "drawee_bank": row.get("drawee_bank"),
                    "drawee_bank_address": row.get("drawee_bank_address"),
                    "amount": row.get("amount"),
                    "cheque_deposit": obj,
                }
                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:
        dct = write_error(dct, e)
        mail_exception(request)
    delete_rows(params.get("table_view").get("deleted_rows"), model)
    delete_rows(params.get("deleted_files"), AttachFile)
    return JsonResponse(dct)
예제 #2
0
def save_entry(request):
    if request.is_ajax():
        params = json.loads(request.POST.get('entry'))
    dct = {'rows': {}}
    company = request.company
    if params.get('entry_no') == '':
        params['entry_no'] = None
    object_values = {
        'entry_no': int(params.get('entry_no')),
        'company': company
    }
    if params.get('id'):
        obj = Entry.objects.get(id=params.get('id'),
                                company__in=request.company.get_all())
    else:
        obj = Entry(company=request.company)
    model = EntryRow
    try:
        obj = save_model(obj, object_values)
        dct['id'] = obj.id
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['employee_id', 'pay_heading_id']):
                continue
            else:
                values = {
                    'sn': ind + 1,
                    'employee_id': row.get('employee_id'),
                    'pay_heading_id': row.get('pay_heading_id'),
                    'amount': row.get('amount'),
                    'hours': row.get('hours'),
                    'tax': row.get('tax'),
                    'remarks': row.get('remarks'),
                    'entry': obj
                }
                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
                set_transactions(
                    submodel, obj.created,
                    ['dr', submodel.pay_heading, submodel.amount], [
                        'cr',
                        Account.objects.get(name='Payroll Tax',
                                            company=obj.company), submodel.tax
                    ], [
                        'cr', submodel.employee,
                        float(submodel.amount) - float(submodel.tax)
                    ])
        delete_rows(params.get('table_view').get('deleted_rows'), model)
    except Exception as e:
        dct = write_error(dct, e)
        mail_exception(request)
    return JsonResponse(dct)
예제 #3
0
파일: views.py 프로젝트: iraycd/awecounting
def save_sale(request):
    if request.is_ajax():
        params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('voucher_no') == '':
        params['voucher_no'] = None
    object_values = {'voucher_no': params.get('voucher_no'), 'date': params.get('date'),
                     'party_id': params.get('party_id'), 'due_date': params.get('due_date'),
                     'credit': params.get('credit'), 'company': request.company}
    if params.get('id'):
        obj = Sale.objects.get(id=params.get('id'), company=request.company)
    else:
        obj = Sale(company=request.company)
    try:
        obj = save_model(obj, object_values)
        dct['id'] = obj.id
        model = SaleRow
        grand_total = 0
        for ind, row in enumerate(params.get('table_view').get('rows')):
            invalid_check = invalid(row, ['item_id', 'quantity', 'unit_id'])
            if invalid_check:
                continue
            values = {'sn': ind + 1, 'item_id': row.get('item')['id'], 'quantity': row.get('quantity'),
                      'rate': row.get('rate'), 'unit_id': row.get('unit')['id'], 'discount': row.get('discount'),
                      'sale': obj}
            submodel, created = model.objects.get_or_create(id=row.get('id'), defaults=values)
            if not created:
                submodel = save_model(submodel, values)
            grand_total += submodel.get_total()
            dct['rows'][ind] = submodel.id
            set_transactions(submodel, obj.date,
                             ['cr', submodel.item.account, submodel.quantity],
                             )
            if obj.credit:
                set_ledger_transactions(submodel, obj.date,
                                        ['dr', obj.party.account, obj.total],
                                        ['cr', submodel.item.ledger, obj.total],
                                        # ['cr', sales_tax_account, tax_amount],
                                        )
            else:
                set_ledger_transactions(submodel, obj.date,
                                        ['dr', Account.objects.get(name='Cash', company=request.company), obj.total],
                                        ['cr', submodel.item.ledger, obj.total],
                                        # ['cr', sales_tax_account, tax_amount],
                                        )
        delete_rows(params.get('table_view').get('deleted_rows'), model)
        obj.total_amount = grand_total
        if obj.credit:
            obj.pending_amount = grand_total
        obj.save()
    except Exception as e:
        dct = write_error(dct, e)
    return JsonResponse(dct)
예제 #4
0
파일: views.py 프로젝트: iraycd/awecounting
def save_cash_receipt(request):
    params = json.loads(request.body)
    dct = {'rows': {}}
    if params.get('voucher_no') == '':
        params['voucher_no'] = None
    object_values = {'party_id': params.get('party_id'), 'date': params.get('date'),
                     'voucher_no': params.get('voucher_no'),
                     'reference': params.get('reference'), 'company': request.company}
    if params.get('id'):
        obj = CashReceipt.objects.get(id=params.get('id'), company=request.company)
    else:
        obj = CashReceipt(company=request.company)
    try:
        obj = save_model(obj, object_values)
        dct['id'] = obj.id
        model = CashReceiptRow
        cash_account = Account.objects.get(name='Cash', company=request.company)
        if params.get('table_vm').get('rows'):
            total = 0
            for index, row in enumerate(params.get('table_vm').get('rows')):
                if invalid(row, ['payment']):
                    continue
                row['payment'] = zero_for_none(empty_to_none(row['payment']))
                invoice = Sale.objects.get(voucher_no=row.get('voucher_no'), company=request.company)
                invoice.pending_amount = row.get('pending_amount')
                invoice.save()
                values = {'receipt': row.get('payment'), 'cash_receipt': obj, 'invoice': invoice}
                try:
                    old_value = model.objects.get(invoice_id=row.get('id'), cash_receipt_id=obj.id).receipt or 0
                except CashReceiptRow.DoesNotExist:
                    old_value = 0
                submodel, created = model.objects.get_or_create(invoice=invoice, cash_receipt=obj, defaults=values)
                if created:
                    invoice.pending_amount -= float(row.get('payment'))
                else:
                    submodel = save_model(submodel, values)
                    invoice.pending_amount -= float(row.get('payment')) - old_value
                    invoice.save()
                dct['rows'][index] = submodel.id
                total += float(row.get('payment'))
            obj.amount = total
        else:
            obj.amount = params.get('amount')
        set_ledger_transactions(obj, obj.date,
                                ['dr', cash_account, obj.amount],
                                ['cr', obj.party.account, obj.amount]
                                )
        # obj.status = 'Unapproved'
        obj.save()
    except Exception as e:
        dct = write_error(dct, e)
    return JsonResponse(dct)
예제 #5
0
파일: views.py 프로젝트: bkawan/awecounting
def cheque_deposit_save(request):
    if request.is_ajax():
        params = json.loads(request.POST.get('cheque_deposit'))
    dct = {'rows': {}}
    company = request.company
    if params.get('voucher_no') == '':
        params['voucher_no'] = None
    object_values = {'voucher_no': int(params.get('voucher_no')), 'date': params.get('date'),
                     'bank_account_id': params.get('bank_account'),
                     'clearing_date': params.get('clearing_date'), 'benefactor_id': params.get('benefactor'),
                     'deposited_by': params.get('deposited_by'),
                     'narration': params.get('narration'), 'status': params.get('status'), 'company': company}
    if params.get('id'):
        obj = ChequeDeposit.objects.get(id=params.get('id'), company__in=request.company.get_all())
    else:
        obj = ChequeDeposit(company=request.company)
    model = ChequeDepositRow
    try:
        obj = save_model(obj, object_values)
        if request.FILES:
            dct['attachment'] = []
            for _file, description in zip(request.FILES.getlist('file'), request.POST.getlist('file_description')):
                attach_file = AttachFile.objects.create(attachment=_file, description=description)
                obj.files.add(attach_file)
                dct['attachment'].append(FileSerializer(attach_file).data)
        if params.get('file'):
            for i, o in enumerate(params.get('file')):
                attach_file_update = get_object_or_404(AttachFile, id=o.get('id'))
                attach_file_update.description = o.get('description')
                attach_file_update.save()
        dct['id'] = obj.id
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['cheque_number', 'amount']):
                continue
            else:
                values = {'sn': ind + 1, 'cheque_number': row.get('cheque_number'),
                          'cheque_date': row.get('cheque_date'), 'drawee_bank': row.get('drawee_bank'),
                          'drawee_bank_address': row.get('drawee_bank_address'),
                          'amount': row.get('amount'), 'cheque_deposit': obj}
                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:
        dct = write_error(dct, e)
        mail_exception(request)
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    delete_rows(params.get('deleted_files'), AttachFile)
    return JsonResponse(dct)
예제 #6
0
파일: views.py 프로젝트: iraycd/awecounting
def cheque_deposit_save(request):
    if request.is_ajax():
        params = json.loads(request.POST.get('cheque_deposit'))
    dct = {'rows': {}}
    company = request.company
    if params.get('voucher_no') == '':
        params['voucher_no'] = None
    object_values = {'voucher_no': int(params.get('voucher_no')), 'date': params.get('date'),
                     'bank_account_id': params.get('bank_account'),
                     'clearing_date': params.get('clearing_date'), 'benefactor_id': params.get('benefactor'),
                     'deposited_by': params.get('deposited_by'),
                     'narration': params.get('narration'), 'status': params.get('status'), 'company': company}
    if params.get('id'):
        obj = ChequeDeposit.objects.get(id=params.get('id'), company=request.company)
    else:
        obj = ChequeDeposit(company=request.company)
    model = ChequeDepositRow
    try:
        obj = save_model(obj, object_values)
        if request.FILES:
            dct['attachment'] = []
            for _file, description in zip(request.FILES.getlist('file'), request.POST.getlist('file_description')):
                attach_file = AttachFile.objects.create(attachment=_file, description=description)
                obj.files.add(attach_file)
                dct['attachment'].append(FileSerializer(attach_file).data)
        if params.get('file'):
            for i, o in enumerate(params.get('file')):
                attach_file_update = get_object_or_404(AttachFile, id=o.get('id'))
                attach_file_update.description = o.get('description')
                attach_file_update.save()
        dct['id'] = obj.id
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['cheque_number', 'amount']):
                continue
            else:
                values = {'sn': ind + 1, 'cheque_number': row.get('cheque_number'),
                          'cheque_date': row.get('cheque_date'), 'drawee_bank': row.get('drawee_bank'),
                          'drawee_bank_address': row.get('drawee_bank_address'),
                          'amount': row.get('amount'), 'cheque_deposit': obj}
                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:
        dct = write_error(dct, e)
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    delete_rows(params.get('deleted_files'), AttachFile)
    return JsonResponse(dct)
예제 #7
0
파일: views.py 프로젝트: iraycd/awecounting
def save_fixed_asset(request):
    if request.is_ajax():
        # params = json.loads(request.body)
        params = json.loads(request.POST.get('fixed_asset'))
    dct = {'rows': {}, 'additional_detail': {}, }
    company = request.company
    if params.get('voucher_no') == '':
        params['voucher_no'] = None
    object_values = {'voucher_no': int(params.get('voucher_no')), 'date': params.get('date'),
                     'from_account_id': params.get('from_account'),
                     'reference': params.get('reference'), 'description': params.get('description'), 'company': company}
    if params.get('id'):
        obj = FixedAsset.objects.get(id=params.get('id'), company=request.company)
    else:
        obj = FixedAsset(company=request.company)
    try:
        obj = save_model(obj, object_values)
        dct['id'] = obj.id
        model = FixedAssetRow
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['asset_ledger', 'amount']):
                continue
            else:
                values = {'asset_ledger_id': row.get('asset_ledger'),
                          'description': row.get('description'), 'amount': row.get('amount'),
                          'fixed_asset': obj}
                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
        delete_rows(params.get('table_view').get('deleted_rows'), model)
        additional_detail = AdditionalDetail
        for ind, row in enumerate(params.get('additional_detail').get('rows')):
            values = {'assets_code': row.get('assets_code'), 'assets_type': row.get('assets_type'),
                      'vendor_name': row.get('vendor_name'), 'vendor_address': row.get('vendor_address'),
                      'amount': row.get('amount'), 'useful_life': row.get('useful_life'),
                      'description': row.get('description'), 'warranty_period': row.get('warranty_period'),
                      'maintenance': row.get('maintenance'), 'fixed_asset': obj}
            submodel, created = additional_detail.objects.get_or_create(id=row.get('id'), defaults=values)
            if not created:
                submodel = save_model(submodel, values)
            dct['additional_detail'][ind] = submodel.id
        delete_rows(params.get('additional_detail').get('deleted_rows'), additional_detail)
    except Exception as e:
        dct = write_error(dct, e)
    return JsonResponse(dct)
예제 #8
0
def save_entry(request):
    if request.is_ajax():
        params = json.loads(request.POST.get('entry'))
    dct = {'rows': {}}
    company = request.company
    if params.get('entry_no') == '':
        params['entry_no'] = None
    object_values = {'entry_no': int(params.get('entry_no')), 'company': company}
    if params.get('id'):
        obj = Entry.objects.get(id=params.get('id'), company__in=request.company.get_all())
    else:
        obj = Entry(company=request.company)
    model = EntryRow
    try:
        obj = save_model(obj, object_values)
        dct['id'] = obj.id
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['employee_id', 'pay_heading_id']):
                continue
            else:
                values = {'sn': ind + 1, 'employee_id': row.get('employee_id'),
                          'pay_heading_id': row.get('pay_heading_id'), 'amount': row.get('amount'),
                          'hours': row.get('hours'), 'tax': row.get('tax'), 'remarks': row.get('remarks'),
                          'entry': obj}
                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
                set_transactions(submodel, obj.created,
                                 ['dr', submodel.pay_heading, submodel.amount],
                                 ['cr', Account.objects.get(name='Payroll Tax', company=obj.company), submodel.tax],
                                 ['cr', submodel.employee, float(submodel.amount) - float(submodel.tax)]
                                 )
        delete_rows(params.get('table_view').get('deleted_rows'), model)
    except Exception as e:
        dct = write_error(dct, e)
        mail_exception(request)
    return JsonResponse(dct)
예제 #9
0
파일: views.py 프로젝트: iraycd/awecounting
def journal_voucher_save(request):
    if request.is_ajax():
        params = json.loads(request.body)
    dct = {'rows': {}}
    company = request.company
    if params.get('voucher_no') == '':
        params['voucher_no'] = None
    object_values = {'voucher_no': int(params.get('voucher_no')), 'date': params.get('date'),
                     'narration': params.get('narration'),
                     'status': params.get('status'), 'company': company}

    if params.get('id'):
        obj = JournalVoucher.objects.get(id=params.get('id'), company=request.company)
    else:
        obj = JournalVoucher(company=request.company)
    try:
        obj = save_model(obj, object_values)
        dct['id'] = obj.id

        model = JournalVoucherRow
        for ind, row in enumerate(params.get('table_view').get('rows')):
            if invalid(row, ['account']):
                continue
            else:
                values = {'type': row.get('type'), 'account_id': row.get('account'),
                          'description': row.get('description'), 'dr_amount': empty_to_none(float(row.get('dr_amount'))),
                          'cr_amount': empty_to_none(float(row.get('cr_amount'))),
                          'journal_voucher': obj}
                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:
        dct = write_error(dct, e)
    delete_rows(params.get('table_view').get('deleted_rows'), model)
    return JsonResponse(dct)