Exemplo n.º 1
0
def make_bank_entry(dt, dn):
    doc = frappe.get_doc(dt, dn)
    payment_account = get_default_bank_cash_account(
        doc.company, account_type="Cash", mode_of_payment=doc.mode_of_payment)

    je = frappe.new_doc("Journal Entry")
    je.posting_date = nowdate()
    je.voucher_type = 'Bank Entry'
    je.company = doc.company
    je.remark = 'Payment against Employee Advance: ' + dn + '\n' + doc.purpose

    je.append(
        "accounts", {
            "account": doc.advance_account,
            "debit_in_account_currency": flt(doc.advance_amount),
            "reference_type": "Employee Advance",
            "reference_name": doc.name,
            "party_type": "Employee",
            "cost_center": erpnext.get_default_cost_center(doc.company),
            "party": doc.employee,
            "is_advance": "Yes"
        })

    je.append(
        "accounts", {
            "account": payment_account.account,
            "cost_center": erpnext.get_default_cost_center(doc.company),
            "credit_in_account_currency": flt(doc.advance_amount),
            "account_currency": payment_account.account_currency,
            "account_type": payment_account.account_type
        })

    return je.as_dict()
Exemplo n.º 2
0
    def create_disbursement_entry(self):
        je = frappe.new_doc("Journal Entry")
        je.voucher_type = 'Journal Entry'
        je.company = self.company
        je.remark = 'Loan Disbursement entry against Invoice Discounting: ' + self.name

        je.append(
            "accounts", {
                "account":
                self.bank_account,
                "debit_in_account_currency":
                flt(self.total_amount) - flt(self.bank_charges),
                "cost_center":
                erpnext.get_default_cost_center(self.company)
            })

        if self.bank_charges:
            je.append(
                "accounts", {
                    "account": self.bank_charges_account,
                    "debit_in_account_currency": flt(self.bank_charges),
                    "cost_center": erpnext.get_default_cost_center(
                        self.company)
                })

        je.append(
            "accounts", {
                "account": self.short_term_loan,
                "credit_in_account_currency": flt(self.total_amount),
                "cost_center": erpnext.get_default_cost_center(self.company),
                "reference_type": "Invoice Discounting",
                "reference_name": self.name
            })
        for d in self.invoices:
            je.append(
                "accounts", {
                    "account": self.accounts_receivable_discounted,
                    "debit_in_account_currency": flt(d.outstanding_amount),
                    "cost_center": erpnext.get_default_cost_center(
                        self.company),
                    "reference_type": "Invoice Discounting",
                    "reference_name": self.name,
                    "party_type": "Customer",
                    "party": d.customer
                })

            je.append(
                "accounts", {
                    "account": self.accounts_receivable_credit,
                    "credit_in_account_currency": flt(d.outstanding_amount),
                    "cost_center": erpnext.get_default_cost_center(
                        self.company),
                    "reference_type": "Invoice Discounting",
                    "reference_name": self.name,
                    "party_type": "Customer",
                    "party": d.customer
                })

        return je
Exemplo n.º 3
0
def reconcile_dr_cr_note(dr_cr_notes, company):
    for d in dr_cr_notes:
        voucher_type = ('Credit Note'
                        if d.voucher_type == 'Sales Invoice' else 'Debit Note')

        reconcile_dr_or_cr = ('debit_in_account_currency'
                              if d.dr_or_cr == 'credit_in_account_currency'
                              else 'credit_in_account_currency')

        company_currency = erpnext.get_company_currency(company)

        jv = frappe.get_doc({
            "doctype":
            "Journal Entry",
            "voucher_type":
            voucher_type,
            "posting_date":
            today(),
            "company":
            company,
            "multi_currency":
            1 if d.currency != company_currency else 0,
            "accounts": [{
                'account':
                d.account,
                'party':
                d.party,
                'party_type':
                d.party_type,
                d.dr_or_cr:
                abs(d.allocated_amount),
                'reference_type':
                d.against_voucher_type,
                'reference_name':
                d.against_voucher,
                'cost_center':
                erpnext.get_default_cost_center(company)
            }, {
                'account':
                d.account,
                'party':
                d.party,
                'party_type':
                d.party_type,
                reconcile_dr_or_cr:
                (abs(d.allocated_amount)
                 if abs(d.unadjusted_amount) > abs(d.allocated_amount) else
                 abs(d.unadjusted_amount)),
                'reference_type':
                d.voucher_type,
                'reference_name':
                d.voucher_no,
                'cost_center':
                erpnext.get_default_cost_center(company)
            }]
        })

        jv.submit()
Exemplo n.º 4
0
    def make_gl_entries(self, cancel=0, adv_adj=0):
        gle_map = []

        if self.interest_amount:
            gle_map.append(
                self.get_gl_dict({
                    "account":
                    self.loan_account,
                    "party_type":
                    self.applicant_type,
                    "party":
                    self.applicant,
                    "against":
                    self.interest_income_account,
                    "debit":
                    self.interest_amount,
                    "debit_in_account_currency":
                    self.interest_amount,
                    "against_voucher_type":
                    "Loan",
                    "against_voucher":
                    self.loan,
                    "remarks":
                    _("Interest accrued from {0} to {1} against loan: {2}").
                    format(self.last_accrual_date, self.posting_date,
                           self.loan),
                    "cost_center":
                    erpnext.get_default_cost_center(self.company),
                    "posting_date":
                    self.posting_date
                }))

            gle_map.append(
                self.get_gl_dict({
                    "account":
                    self.interest_income_account,
                    "against":
                    self.loan_account,
                    "credit":
                    self.interest_amount,
                    "credit_in_account_currency":
                    self.interest_amount,
                    "against_voucher_type":
                    "Loan",
                    "against_voucher":
                    self.loan,
                    "remarks":
                    ("Interest accrued from {0} to {1} against loan: {2}"
                     ).format(self.last_accrual_date, self.posting_date,
                              self.loan),
                    "cost_center":
                    erpnext.get_default_cost_center(self.company),
                    "posting_date":
                    self.posting_date
                }))

        if gle_map:
            make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj)
Exemplo n.º 5
0
    def make_gl_entries(self, cancel=0, adv_adj=0):
        gle_map = []

        gle_map.append(
            self.get_gl_dict({
                "account":
                self.loan_account,
                "party_type":
                self.applicant_type,
                "party":
                self.applicant,
                "against":
                self.interest_income_account,
                "debit":
                self.interest_amount,
                "debit_in_account_currency":
                self.interest_amount,
                "against_voucher_type":
                "Loan",
                "against_voucher":
                self.loan,
                "remarks":
                _("Against Loan:") + self.loan,
                "cost_center":
                erpnext.get_default_cost_center(self.company),
                "posting_date":
                self.posting_date
            }))

        gle_map.append(
            self.get_gl_dict({
                "account":
                self.interest_income_account,
                "party_type":
                self.applicant_type,
                "party":
                self.applicant,
                "against":
                self.loan_account,
                "credit":
                self.interest_amount,
                "credit_in_account_currency":
                self.interest_amount,
                "against_voucher_type":
                "Loan",
                "against_voucher":
                self.loan,
                "remarks":
                _("Against Loan:") + self.loan,
                "cost_center":
                erpnext.get_default_cost_center(self.company),
                "posting_date":
                self.posting_date
            }))

        if gle_map:
            make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj)
Exemplo n.º 6
0
def make_bank_entry(dt, dn):
    doc = frappe.get_doc(dt, dn)
    payment_account = get_default_bank_cash_account(
        doc.company, account_type="Cash", mode_of_payment=doc.mode_of_payment)
    if not payment_account:
        frappe.throw(
            _("Please set a Default Cash Account in Company defaults"))

    advance_account_currency = frappe.db.get_value("Account",
                                                   doc.advance_account,
                                                   "account_currency")

    advance_amount, advance_exchange_rate = get_advance_amount_advance_exchange_rate(
        advance_account_currency, doc)

    paying_amount, paying_exchange_rate = get_paying_amount_paying_exchange_rate(
        payment_account, doc)

    je = frappe.new_doc("Journal Entry")
    je.posting_date = nowdate()
    je.voucher_type = "Bank Entry"
    je.company = doc.company
    je.remark = "Payment against Employee Advance: " + dn + "\n" + doc.purpose
    je.multi_currency = 1 if advance_account_currency != payment_account.account_currency else 0

    je.append(
        "accounts",
        {
            "account": doc.advance_account,
            "account_currency": advance_account_currency,
            "exchange_rate": flt(advance_exchange_rate),
            "debit_in_account_currency": flt(advance_amount),
            "reference_type": "Employee Advance",
            "reference_name": doc.name,
            "party_type": "Employee",
            "cost_center": erpnext.get_default_cost_center(doc.company),
            "party": doc.employee,
            "is_advance": "Yes",
        },
    )

    je.append(
        "accounts",
        {
            "account": payment_account.account,
            "cost_center": erpnext.get_default_cost_center(doc.company),
            "credit_in_account_currency": flt(paying_amount),
            "account_currency": payment_account.account_currency,
            "account_type": payment_account.account_type,
            "exchange_rate": flt(paying_exchange_rate),
        },
    )

    return je.as_dict()
Exemplo n.º 7
0
def reconcile_dr_cr_note(dr_cr_notes, company):
    for inv in dr_cr_notes:
        voucher_type = "Credit Note" if inv.voucher_type == "Sales Invoice" else "Debit Note"

        reconcile_dr_or_cr = ("debit_in_account_currency"
                              if inv.dr_or_cr == "credit_in_account_currency"
                              else "credit_in_account_currency")

        company_currency = erpnext.get_company_currency(company)

        jv = frappe.get_doc({
            "doctype":
            "Journal Entry",
            "voucher_type":
            voucher_type,
            "posting_date":
            today(),
            "company":
            company,
            "multi_currency":
            1 if inv.currency != company_currency else 0,
            "accounts": [
                {
                    "account": inv.account,
                    "party": inv.party,
                    "party_type": inv.party_type,
                    inv.dr_or_cr: abs(inv.allocated_amount),
                    "reference_type": inv.against_voucher_type,
                    "reference_name": inv.against_voucher,
                    "cost_center": erpnext.get_default_cost_center(company),
                },
                {
                    "account":
                    inv.account,
                    "party":
                    inv.party,
                    "party_type":
                    inv.party_type,
                    reconcile_dr_or_cr:
                    (abs(inv.allocated_amount)
                     if abs(inv.unadjusted_amount) > abs(inv.allocated_amount)
                     else abs(inv.unadjusted_amount)),
                    "reference_type":
                    inv.voucher_type,
                    "reference_name":
                    inv.voucher_no,
                    "cost_center":
                    erpnext.get_default_cost_center(company),
                },
            ],
        })
        jv.flags.ignore_mandatory = True
        jv.submit()
Exemplo n.º 8
0
	def set_missing_values(self, amounts):
		if not self.posting_date:
			self.posting_date = get_datetime()

		if not self.cost_center:
			self.cost_center = erpnext.get_default_cost_center(self.company)

		if not self.interest_payable:
			self.interest_payable = amounts['interest_amount']

		if not self.penalty_amount:
			self.penalty_amount = amounts['penalty_amount']

		if not self.pending_principal_amount:
			self.pending_principal_amount = amounts['pending_principal_amount']

		if not self.payable_principal_amount and self.is_term_loan:
			self.payable_principal_amount = amounts['payable_principal_amount']

		if not self.payable_amount:
			self.payable_amount = amounts['payable_amount']

		if amounts.get('paid_accrual_entries'):
			self.paid_accrual_entries = frappe.as_json(amounts.get('paid_accrual_entries'))

		if amounts.get('due_date'):
			self.due_date = amounts.get('due_date')
Exemplo n.º 9
0
	def get_items_from_purchase_receipts(self):
		self.set("items", [])
		self.total_amount = 0
		self.total_weight = 0
		for pr in self.get("purchase_receipts"):
			if pr.receipt_document_type and pr.receipt_document:
				pr_items = frappe.db.sql("""
					select item.item_code, item.description,
						item.qty, item.total_weight, item.weight_uom, item.base_rate, item.base_amount, item.name, item.cost_center
					from `tab{doctype} Item` item where parent = %s
					and exists(select name from tabItem where name = item.item_code and is_stock_item = 1)
					""".format(doctype=pr.receipt_document_type), pr.receipt_document, as_dict=True)

				for d in pr_items:
					item = self.append("items")
					item.item_code = d.item_code
					item.description = d.description
					item.qty = d.qty
					item.rate = d.base_rate
					item.cost_center = d.cost_center or erpnext.get_default_cost_center(self.company)
					item.amount = d.base_amount
					item.receipt_document_type = pr.receipt_document_type
					item.receipt_document = pr.receipt_document
					item.purchase_receipt_item = d.name

					item_master = frappe.db.get_value("Item", item.item_code, ["weight_uom", "weight_per_unit"], as_dict=1)
					item.weight = flt(item_master.weight_per_unit * d.qty, item.precision("weight"))
					item.weight_uom = item_master.weight_uom

					self.total_amount += item.amount
					self.total_weight += item.weight
Exemplo n.º 10
0
    def get_items_from_purchase_receipts(self):
        self.set("items", [])
        for pr in self.get("purchase_receipts"):
            if pr.receipt_document_type and pr.receipt_document:
                pr_items = frappe.db.sql(
                    """select pr_item.item_code, pr_item.description,
					pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name, pr_item.cost_center
					from `tab{doctype} Item` pr_item where parent = %s
					and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 1)
					""".format(doctype=pr.receipt_document_type),
                    pr.receipt_document,
                    as_dict=True)

                for d in pr_items:
                    item = self.append("items")
                    item.item_code = d.item_code
                    item.description = d.description
                    item.qty = d.qty
                    item.rate = d.base_rate
                    item.cost_center = d.cost_center or \
                     erpnext.get_default_cost_center(self.company)
                    item.amount = d.base_amount
                    item.receipt_document_type = pr.receipt_document_type
                    item.receipt_document = pr.receipt_document
                    item.purchase_receipt_item = d.name
Exemplo n.º 11
0
    def set_missing_values(self, amounts):
        if not self.posting_date:
            self.posting_date = get_datetime()

        if not self.cost_center:
            self.cost_center = erpnext.get_default_cost_center(self.company)

        if not self.interest_payable:
            self.interest_payable = flt(amounts['interest_amount'], 2)

        if not self.penalty_amount:
            self.penalty_amount = flt(amounts['penalty_amount'], 2)

        if not self.pending_principal_amount:
            self.pending_principal_amount = flt(
                amounts['pending_principal_amount'], 2)

        if not self.payable_principal_amount and self.is_term_loan:
            self.payable_principal_amount = flt(
                amounts['payable_principal_amount'], 2)

        if not self.payable_amount:
            self.payable_amount = flt(amounts['payable_amount'], 2)

        if amounts.get('due_date'):
            self.due_date = amounts.get('due_date')
Exemplo n.º 12
0
 def validate(self):
     self.validate_trial_period()
     self.validate_plans_billing_cycle(
         self.get_billing_cycle_and_interval())
     self.validate_end_date()
     self.validate_to_follow_calendar_months()
     self.cost_center = erpnext.get_default_cost_center(self.get("company"))
Exemplo n.º 13
0
	def set_missing_values(self, amounts):
		precision = cint(frappe.db.get_default("currency_precision")) or 2

		if not self.posting_date:
			self.posting_date = get_datetime()

		if not self.cost_center:
			self.cost_center = erpnext.get_default_cost_center(self.company)

		if not self.interest_payable:
			self.interest_payable = flt(amounts['interest_amount'], precision)

		if not self.penalty_amount:
			self.penalty_amount = flt(amounts['penalty_amount'], precision)

		if not self.pending_principal_amount:
			self.pending_principal_amount = flt(amounts['pending_principal_amount'], precision)

		if not self.payable_principal_amount and self.is_term_loan:
			self.payable_principal_amount = flt(amounts['payable_principal_amount'], precision)

		if not self.payable_amount:
			self.payable_amount = flt(amounts['payable_amount'], precision)

		if amounts.get('due_date'):
			self.due_date = amounts.get('due_date')
Exemplo n.º 14
0
	def set_missing_values(self, amounts):
		precision = cint(frappe.db.get_default("currency_precision")) or 2

		if not self.posting_date:
			self.posting_date = get_datetime()

		if not self.cost_center:
			self.cost_center = erpnext.get_default_cost_center(self.company)

		if not self.interest_payable:
			self.interest_payable = flt(amounts['interest_amount'], precision)

		if not self.penalty_amount:
			self.penalty_amount = flt(amounts['penalty_amount'], precision)

		if not self.pending_principal_amount:
			self.pending_principal_amount = flt(amounts['pending_principal_amount'], precision)

		if not self.payable_principal_amount and self.is_term_loan:
			self.payable_principal_amount = flt(amounts['payable_principal_amount'], precision)

		if not self.payable_amount:
			self.payable_amount = flt(amounts['payable_amount'], precision)

		shortfall_amount = flt(frappe.db.get_value('Loan Security Shortfall', {'loan': self.against_loan, 'status': 'Pending'},
			'shortfall_amount'))

		if shortfall_amount:
			self.shortfall_amount = shortfall_amount

		if amounts.get('due_date'):
			self.due_date = amounts.get('due_date')
Exemplo n.º 15
0
def make_bank_entry(dt, dn):
	from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account

	expense_claim = frappe.get_doc(dt, dn)
	default_bank_cash_account = get_default_bank_cash_account(expense_claim.company, "Bank")
	if not default_bank_cash_account:
		default_bank_cash_account = get_default_bank_cash_account(expense_claim.company, "Cash")

	payable_amount = (
		flt(expense_claim.total_sanctioned_amount)
		- flt(expense_claim.total_amount_reimbursed)
		- flt(expense_claim.total_advance_amount)
	)

	je = frappe.new_doc("Journal Entry")
	je.voucher_type = "Bank Entry"
	je.company = expense_claim.company
	je.remark = "Payment against Expense Claim: " + dn

	je.append(
		"accounts",
		{
			"account": expense_claim.payable_account,
			"debit_in_account_currency": payable_amount,
			"reference_type": "Expense Claim",
			"party_type": "Employee",
			"party": expense_claim.employee,
			"cost_center": erpnext.get_default_cost_center(expense_claim.company),
			"reference_name": expense_claim.name,
		},
	)

	je.append(
		"accounts",
		{
			"account": default_bank_cash_account.account,
			"credit_in_account_currency": payable_amount,
			"reference_type": "Expense Claim",
			"reference_name": expense_claim.name,
			"balance": default_bank_cash_account.balance,
			"account_currency": default_bank_cash_account.account_currency,
			"cost_center": erpnext.get_default_cost_center(expense_claim.company),
			"account_type": default_bank_cash_account.account_type,
		},
	)

	return je.as_dict()
Exemplo n.º 16
0
def get_expense_claim_account_and_cost_center(expense_claim_type, company):
	data = get_expense_claim_account(expense_claim_type, company)
	cost_center = erpnext.get_default_cost_center(company)

	return {
		"account": data.get("account"),
		"cost_center": cost_center
	}
Exemplo n.º 17
0
	def close_loan(self):
		je = frappe.new_doc("Journal Entry")
		je.voucher_type = 'Journal Entry'
		je.company = self.company
		je.remark = 'Loan Settlement entry against Invoice Discounting: ' + self.name

		je.append("accounts", {
			"account": self.short_term_loan,
			"debit_in_account_currency": flt(self.total_amount),
			"cost_center": erpnext.get_default_cost_center(self.company),
			"reference_type": "Invoice Discounting",
			"reference_name": self.name,
		})

		je.append("accounts", {
			"account": self.bank_account,
			"credit_in_account_currency": flt(self.total_amount),
			"cost_center": erpnext.get_default_cost_center(self.company)
		})

		if getdate(self.loan_end_date) > getdate(nowdate()):
			for d in self.invoices:
				outstanding_amount = frappe.db.get_value("Sales Invoice", d.sales_invoice, "outstanding_amount")
				if flt(outstanding_amount) > 0:
					je.append("accounts", {
						"account": self.accounts_receivable_discounted,
						"credit_in_account_currency": flt(outstanding_amount),
						"cost_center": erpnext.get_default_cost_center(self.company),
						"reference_type": "Invoice Discounting",
						"reference_name": self.name,
						"party_type": "Customer",
						"party": d.customer
					})

					je.append("accounts", {
						"account": self.accounts_receivable_unpaid,
						"debit_in_account_currency": flt(outstanding_amount),
						"cost_center": erpnext.get_default_cost_center(self.company),
						"reference_type": "Invoice Discounting",
						"reference_name": self.name,
						"party_type": "Customer",
						"party": d.customer
					})

		return je
Exemplo n.º 18
0
    def set_missing_values(self):
        if not self.disbursement_date:
            self.disbursement_date = nowdate()

        if not self.cost_center:
            self.cost_center = erpnext.get_default_cost_center(self.company)

        if not self.posting_date:
            self.posting_date = self.disbursement_date or nowdate()
Exemplo n.º 19
0
def create_jv(transaction):
    je_doc = frappe.new_doc("Journal Entry")
    for tran in transaction:
        if je_doc.posting_date != tran['posting_date']:
            je_doc.company = tran['company']
            je_doc.voucher_type = "Journal Entry"
            je_doc.posting_date = tran['posting_date']
        #debit lines
        if tran['debit'] > 0:
            je_doc.append(
                "accounts", {
                    "account": tran['account'],
                    "warehouse": tran['store_code'],
                    "debit_in_account_currency": tran['debit'],
                    "debit": tran['debit'],
                    "credit_in_account_currency": 0,
                    "credit": 0,
                    "user_remark": tran['user_remark'],
                    "cost_center": erpnext.get_default_cost_center(
                        tran['company'])
                })
        #credit lines
        elif tran['credit'] > 0:
            je_doc.append(
                "accounts", {
                    "account": tran['account'],
                    "warehouse": tran['store_code'],
                    "debit_in_account_currency": 0,
                    "debit": 0,
                    "credit_in_account_currency": tran['credit'],
                    "credit": tran['credit'],
                    "user_remark": tran['user_remark'],
                    "cost_center": erpnext.get_default_cost_center(
                        tran['company'])
                })

    try:
        if je_doc:
            je_doc.insert(ignore_permissions=True)
            je_doc.submit()
            return je_doc.name
    except Exception as e:
        frappe.log_error(message=e, title="Clearing JV Error")
Exemplo n.º 20
0
	def set_missing_values(self):
		if not self.disbursement_date:
			self.disbursement_date = nowdate()

		if not self.cost_center:
			self.cost_center = erpnext.get_default_cost_center(self.company)

		if not self.posting_date:
			self.posting_date = self.disbursement_date or nowdate()

		if not self.bank_account and self.applicant_type == "Customer":
			self.bank_account = frappe.db.get_value("Customer", self.applicant, "default_bank_account")
Exemplo n.º 21
0
    def get_items_from_purchase_receipts(self):
        self.set("items", [])
        for pr in self.get("purchase_receipts"):
            if pr.receipt_document_type and pr.receipt_document:
                po_field = "purchase_order"
                if pr.receipt_document_type == "Purchase Invoice":
                    po_detail_field = "po_detail"
                elif pr.receipt_document_type == "Purchase Receipt":
                    po_detail_field = "purchase_order_item"
                else:
                    po_detail_field = "name"
                    po_field = "parent"

                pr_items = frappe.db.sql("""
					select
						pr_item.item_code, pr_item.item_name, pr_item.total_weight,
						pr_item.gross_weight_lbs, i.gross_weight,
						i.purchase_pallets,
						pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.amount, pr_item.name,
						pr_item.{po_detail_field}, pr_item.{po_field} as purchase_order, pr_item.cost_center
					from `tab{doctype} Item` pr_item
					inner join tabItem i on i.name = pr_item.item_code and i.is_stock_item = 1
					where pr_item.parent = %s
					order by pr_item.idx
				""".format(doctype=pr.receipt_document_type,
                po_detail_field=po_detail_field,
                po_field=po_field),
                                         pr.receipt_document,
                                         as_dict=True)

                for d in pr_items:
                    item = self.append("items")
                    item.item_code = d.item_code
                    item.item_name = d.item_name
                    item.qty = d.qty
                    item.weight = d.total_weight
                    item.gross_weight = flt(d.qty) * flt(d.gross_weight_lbs
                                                         or d.gross_weight)
                    item.pallets = flt(d.qty) / flt(
                        d.purchase_pallets) if d.purchase_pallets else 0
                    item.rate = d.base_rate
                    item.cost_center = d.cost_center or erpnext.get_default_cost_center(
                        self.company)
                    item.amount = d.base_amount
                    item.purchase_order = d.purchase_order
                    item.purchase_order_item = d.get(po_detail_field)
                    if pr.receipt_document_type == "Purchase Receipt":
                        item.purchase_receipt = pr.receipt_document
                        item.purchase_receipt_item = d.name
                    elif pr.receipt_document_type == "Purchase Invoice":
                        item.purchase_invoice = pr.receipt_document
                        item.purchase_invoice_item = d.name
Exemplo n.º 22
0
	def get_items_from_purchase_receipts(self):
		self.set("items", [])
		for pr in self.get("purchase_receipts"):
			if pr.receipt_document_type and pr.receipt_document:
				pr_items = frappe.db.sql("""select pr_item.item_code, pr_item.description,
					pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name, pr_item.cost_center
					from `tab{doctype} Item` pr_item where parent = %s
					and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 1)
					""".format(doctype=pr.receipt_document_type), pr.receipt_document, as_dict=True)

				for d in pr_items:
					item = self.append("items")
					item.item_code = d.item_code
					item.description = d.description
					item.qty = d.qty
					item.rate = d.base_rate
					item.cost_center = d.cost_center or \
						erpnext.get_default_cost_center(self.company)
					item.amount = d.base_amount
					item.receipt_document_type = pr.receipt_document_type
					item.receipt_document = pr.receipt_document
					item.purchase_receipt_item = d.name
Exemplo n.º 23
0
    def set_missing_values(self, amounts):
        precision = cint(frappe.db.get_default("currency_precision")) or 2

        if not self.posting_date:
            self.posting_date = get_datetime()

        if not self.cost_center:
            self.cost_center = erpnext.get_default_cost_center(self.company)

        if not self.interest_payable:
            self.interest_payable = flt(amounts["interest_amount"], precision)

        if not self.penalty_amount:
            self.penalty_amount = flt(amounts["penalty_amount"], precision)

        if not self.pending_principal_amount:
            self.pending_principal_amount = flt(
                amounts["pending_principal_amount"], precision)

        if not self.payable_principal_amount and self.is_term_loan:
            self.payable_principal_amount = flt(
                amounts["payable_principal_amount"], precision)

        if not self.payable_amount:
            self.payable_amount = flt(amounts["payable_amount"], precision)

        shortfall_amount = flt(
            frappe.db.get_value("Loan Security Shortfall", {
                "loan": self.against_loan,
                "status": "Pending"
            }, "shortfall_amount"))

        if shortfall_amount:
            self.shortfall_amount = shortfall_amount

        if amounts.get("due_date"):
            self.due_date = amounts.get("due_date")
Exemplo n.º 24
0
def make_return_entry(
    employee,
    company,
    employee_advance_name,
    return_amount,
    advance_account,
    currency,
    exchange_rate,
    mode_of_payment=None,
):
    bank_cash_account = get_default_bank_cash_account(
        company, account_type="Cash", mode_of_payment=mode_of_payment)
    if not bank_cash_account:
        frappe.throw(
            _("Please set a Default Cash Account in Company defaults"))

    advance_account_currency = frappe.db.get_value("Account", advance_account,
                                                   "account_currency")

    je = frappe.new_doc("Journal Entry")
    je.posting_date = nowdate()
    je.voucher_type = get_voucher_type(mode_of_payment)
    je.company = company
    je.remark = "Return against Employee Advance: " + employee_advance_name
    je.multi_currency = 1 if advance_account_currency != bank_cash_account.account_currency else 0

    advance_account_amount = (flt(return_amount) if advance_account_currency
                              == currency else flt(return_amount) *
                              flt(exchange_rate))

    je.append(
        "accounts",
        {
            "account":
            advance_account,
            "credit_in_account_currency":
            advance_account_amount,
            "account_currency":
            advance_account_currency,
            "exchange_rate":
            flt(exchange_rate) if advance_account_currency == currency else 1,
            "reference_type":
            "Employee Advance",
            "reference_name":
            employee_advance_name,
            "party_type":
            "Employee",
            "party":
            employee,
            "is_advance":
            "Yes",
            "cost_center":
            erpnext.get_default_cost_center(company),
        },
    )

    bank_amount = (flt(return_amount) if bank_cash_account.account_currency
                   == currency else flt(return_amount) * flt(exchange_rate))

    je.append(
        "accounts",
        {
            "account":
            bank_cash_account.account,
            "debit_in_account_currency":
            bank_amount,
            "account_currency":
            bank_cash_account.account_currency,
            "account_type":
            bank_cash_account.account_type,
            "exchange_rate":
            flt(exchange_rate)
            if bank_cash_account.account_currency == currency else 1,
            "cost_center":
            erpnext.get_default_cost_center(company),
        },
    )

    return je.as_dict()
Exemplo n.º 25
0
	def set_missing_values(self):
		if not self.cost_center:
			self.cost_center = erpnext.get_default_cost_center(self.company)
Exemplo n.º 26
0
    def make_gl_entries(self):
        gl_entries = []

        # cash
        if self.debit_to == "Employee":
            cash_debit_account = frappe.get_value(
                "Company", self.company, "default_employee_advance_account")
            if not cash_debit_account:
                frappe.throw(
                    "Please define default employee advance account for the Company"
                )
        else:
            cash_debit_account = self.debit_account

        income_account = self.get_income_account()
        cost_center = get_default_cost_center(self.company)

        # CASH ENTRY AGAINST INCOME ACCOUNT
        gl_entries.append(
            self.get_gl_dict({
                "account":
                income_account,
                "against":
                self.debit_employee
                if self.debit_to == "Employee" else self.debit_account,
                "credit":
                self.base_total_cash_sales,
                "cost_center":
                cost_center
            }))

        gl_entries.append(
            self.get_gl_dict({
                "account":
                cash_debit_account,
                "against":
                income_account,
                "debit":
                self.base_total_cash_sales,
                "party_type":
                "Employee" if self.debit_to == "Employee" else None,
                "party":
                self.debit_employee if self.debit_to == "Employee" else None
            }))

        # CREDIT ENTRY AGAINST INCOME ACCOUNT
        for cc in self.credit_sales:
            gl_entries.append(
                self.get_gl_dict({
                    "account": income_account,
                    "against": cc.customer,
                    "credit": cc.base_amount,
                    "cost_center": cost_center
                }))

            gl_entries.append(
                self.get_gl_dict({
                    "account": cc.receivable_account,
                    "against": income_account,
                    "debit": cc.base_amount,
                    "party_type": "Customer",
                    "party": cc.customer
                }))

        from erpnext.accounts.general_ledger import make_gl_entries
        make_gl_entries(gl_entries,
                        cancel=(self.docstatus == 2),
                        update_outstanding='Yes',
                        merge_entries=False)
Exemplo n.º 27
0
def create_payment_entry(
    company,
    customer,
    amount,
    currency,
    mode_of_payment,
    reference_date=None,
    reference_no=None,
    posting_date=None,
    submit=0,
):
    # TODO : need to have a better way to handle currency
    date = nowdate() if not posting_date else posting_date
    party_type = "Customer"
    party_account = get_party_account(party_type, customer, company)
    party_account_currency = get_account_currency(party_account)
    if party_account_currency != currency:
        frappe.throw(
            _("Currency is not correct, party account currency is {party_account_currency} and transaction currency is {currency}"
              ).format(party_account_currency=party_account_currency,
                       currency=currency))
    payment_type = "Receive"

    bank = get_bank_cash_account(company, mode_of_payment)
    company_currency = frappe.get_value("Company", company, "default_currency")
    conversion_rate = get_exchange_rate(currency, company_currency, date,
                                        "for_selling")
    paid_amount, received_amount = set_paid_amount_and_received_amount(
        party_account_currency, bank, amount, payment_type, None,
        conversion_rate)

    pe = frappe.new_doc("Payment Entry")
    pe.payment_type = payment_type
    pe.company = company
    pe.cost_center = erpnext.get_default_cost_center(company)
    pe.posting_date = date
    pe.mode_of_payment = mode_of_payment
    pe.party_type = party_type
    pe.party = customer

    pe.paid_from = party_account if payment_type == "Receive" else bank.account
    pe.paid_to = party_account if payment_type == "Pay" else bank.account
    pe.paid_from_account_currency = (party_account_currency if payment_type
                                     == "Receive" else bank.account_currency)
    pe.paid_to_account_currency = (party_account_currency if payment_type
                                   == "Pay" else bank.account_currency)
    pe.paid_amount = paid_amount
    pe.received_amount = received_amount
    pe.letter_head = frappe.get_value("Company", company,
                                      "default_letter_head")
    pe.reference_date = reference_date
    pe.reference_no = reference_no
    if pe.party_type in ["Customer", "Supplier"]:
        bank_account = get_party_bank_account(pe.party_type, pe.party)
        pe.set("bank_account", bank_account)
        pe.set_bank_account_data()

    pe.setup_party_account_field()
    pe.set_missing_values()

    if party_account and bank:
        pe.set_amounts()
    if submit:
        pe.docstatus = 1
    pe.insert(ignore_permissions=True)
    return pe