コード例 #1
0
    def retire(self):
        gl_entry = []

        payment_account = get_bank_cash_account(self.mode_of_payment,
                                                self.company).get("account")
        # expense entries
        for data in self.requisition:
            gl_entry.append(
                self.get_gl_dict({
                    "account": data.default_account,
                    "debit": data.sanctioned_amount,
                    "debit_in_account_currency": data.sanctioned_amount,
                    "against": self.employee,
                    "cost_center": self.cost_center
                }))

        gl_entry.append(
            self.get_gl_dict({
                "account": self.receivable_account,
                "party_type": "Employee",
                "party": self.employee,
                "against": payment_account,
                "credit": self.total_sanctioned_amount,
                "credit_in_account_currency": self.total_sanctioned_amount,
                "against_voucher": self.name,
                "against_voucher_type": self.doctype,
            }))

        if flt(self.total_sanctioned_amount) > 0:
            make_gl_entries(gl_entry, False)

        update_retired_amount(self)
コード例 #2
0
 def before_save(self):
     self.total_disbursed = flt(self.amount) + flt(self.recovered_amount)
     self.total_charges = reduce(lambda a, x: a + x.charge_amount, self.charges, 0)
     account_dict = get_bank_cash_account(
         mode_of_payment=self.mode_of_payment or "Cash", company=self.company
     )
     self.payment_account = account_dict.get("account")
コード例 #3
0
ファイル: api.py プロジェクト: f-9t9it/vet_care
 def get_mode_of_payment(company, mop):
     data = get_bank_cash_account(mop.get("mode_of_payment"), company)
     return {
         "mode_of_payment": mop.get("mode_of_payment"),
         "amount": mop.get("amount"),
         "account": data.get("account"),
     }
コード例 #4
0
def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
    from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
    if mode_of_payment:
        account = get_bank_cash_account(mode_of_payment, company)
        if account.get("account"):
            account.update({"balance": get_balance_on(account.get("account"))})
            return account

    if voucher_type == "Bank Entry":
        account = frappe.db.get_value("Company", company,
                                      "default_bank_account")
        if not account:
            account = frappe.db.get_value("Account", {
                "company": company,
                "account_type": "Bank",
                "is_group": 0
            })
    elif voucher_type == "Cash Entry":
        account = frappe.db.get_value("Company", company,
                                      "default_cash_account")
        if not account:
            account = frappe.db.get_value("Account", {
                "company": company,
                "account_type": "Cash",
                "is_group": 0
            })

    if account:
        return {"account": account, "balance": get_balance_on(account)}
コード例 #5
0
 def before_save(self):
     self.total_amount = \
         flt(self.total_interests) + flt(self.principal_amount)
     self.total_charges = reduce(lambda a, x: a + x.charge_amount,
                                 self.charges, 0)
     self.total_received = self.total_amount + self.total_charges
     account_dict = get_bank_cash_account(
         mode_of_payment=self.mode_of_payment or 'Cash',
         company=self.company,
     )
     self.payment_account = account_dict.get('account')
     self.periods = []
     for period in allocate_interests(
             self.loan,
             self.posting_date,
             amount_to_allocate=self.total_interests,
             principal=self.principal_amount,
     ):
         self.append('periods', period)
     expected_outstanding = self.principal_amount + compose(
         sum, partial(map, pick('outstanding_amount')),
         partial(filter, lambda x: x.ref_interest is not None))(
             self.periods)
     if expected_outstanding > get_outstanding_principal(self.loan):
         frappe.throw('Cannot receive more than the current outstanding')
コード例 #6
0
ファイル: api.py プロジェクト: bibinqcs/vet_care
 def get_mode_of_payment(company, mop):
     data = get_bank_cash_account(mop.get('mode_of_payment'), company)
     return {
         'mode_of_payment': mop.get('mode_of_payment'),
         'amount': mop.get('amount'),
         'account': data.get('account'),
     }
コード例 #7
0
    def make_payment_entry(self, advance):
        payment = frappe.new_doc("Payment Entry")
        payment.posting_date = today()
        payment.payment_type = "Receive"
        payment.mode_of_payment = advance.mode_of_payment
        payment.party_type = "Customer"
        payment.party = self.customer
        payment.paid_amount = payment.received_amount = abs(advance.amount)
        if advance.cheque_reference:
            payment.reference_no = advance.cheque_reference
            payment.reference_date = advance.posting_date
        out = get_party_details(**dict(
            company=self.company,
            party_type="Customer",
            party=self.customer,
            date=today(),
        ))
        payment.paid_from = out.get("party_account")
        payment.paid_to = get_bank_cash_account(advance.mode_of_payment,
                                                self.company).get("account")

        payment.setup_party_account_field()
        payment.set_missing_values()
        payment.save()
        payment.submit()

        return payment
コード例 #8
0
ファイル: journal_entry.py プロジェクト: shreyasp/erpnext
def get_default_bank_cash_account(company, account_type=None, mode_of_payment=None, account=None):
	from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
	if mode_of_payment:
		account = get_bank_cash_account(mode_of_payment, company).get("account")

	if not account:
		if account_type=="Bank":
			account = frappe.db.get_value("Company", company, "default_bank_account")
			if not account:
				account = frappe.db.get_value("Account",
					{"company": company, "account_type": "Bank", "is_group": 0})

		elif account_type=="Cash":
			account = frappe.db.get_value("Company", company, "default_cash_account")
			if not account:
				account = frappe.db.get_value("Account",
					{"company": company, "account_type": "Cash", "is_group": 0})

	if account:
		account_details = frappe.db.get_value("Account", account,
			["account_currency", "account_type"], as_dict=1)
			
		return frappe._dict({
			"account": account,
			"balance": get_balance_on(account),
			"account_currency": account_details.account_currency,
			"account_type": account_details.account_type
		})
	else: return frappe._dict()
コード例 #9
0
 def set_account_for_mode_of_payment(self):
     self.payments = [
         d for d in self.payments if d.amount or d.base_amount or d.default
     ]
     for pay in self.payments:
         if not pay.account:
             pay.account = get_bank_cash_account(
                 pay.mode_of_payment, self.company).get("account")
コード例 #10
0
    def before_save(self):
        self.total_disbursed = flt(self.disburse_amount)

        account_dict = get_bank_cash_account(
            mode_of_payment=self.mode_of_payment or 'Cash',
            company=self.company,
        )
        self.payment_account = account_dict.get('account')
コード例 #11
0
    def allocate_amount(self):
        self.total_amount = (self.paid_amount if self.loan_type == "EMI" else
                             flt(self.total_interests) +
                             flt(self.principal_amount))
        self.total_charges = reduce(lambda a, x: a + x.charge_amount,
                                    self.get("charges", []), 0)
        self.total_received = self.total_amount + self.total_charges
        account_dict = get_bank_cash_account(
            mode_of_payment=self.mode_of_payment or "Cash",
            company=self.company)
        self.payment_account = account_dict.get("account")
        self.periods = []
        if self.loan_type == "EMI":
            to_allocate = self.paid_amount
            interests = frappe.get_all(
                "Microfinance Loan Interest",
                filters={
                    "loan": self.loan,
                    "status": ("!=", "Clear")
                },
                fields=[
                    "period as period_label",
                    "start_date",
                    "end_date",
                    "billed_amount",
                    "principal_amount",
                    "fine_amount",
                    "billed_amount + principal_amount + fine_amount - paid_amount as outstanding_amount",  # noqa
                    "name as ref_interest",
                ],
                order_by="start_date",
            )
            for interest in interests:
                allocated_amount = min(to_allocate,
                                       interest.get("outstanding_amount"))
                if allocated_amount == 0:
                    break
                self.append(
                    "periods",
                    merge(interest, {"allocated_amount": allocated_amount}))
                to_allocate -= allocated_amount

        else:
            for period in allocate_interests(
                    self.loan,
                    self.posting_date,
                    amount_to_allocate=self.total_interests,
                    principal=self.principal_amount,
            ):
                self.append("periods", period)
            expected_outstanding = self.principal_amount + compose(
                sum,
                partial(map, pick("outstanding_amount")),
                partial(filter, lambda x: x.ref_interest is not None),
            )(self.periods)
            if expected_outstanding > get_outstanding_principal(self.loan):
                frappe.throw(
                    "Cannot receive more than the current outstanding")
コード例 #12
0
 def _get_payment_gl_entries(self):
     payment_account = get_bank_cash_account(self.mode_of_payment,
                                             self.company)["account"]
     credit_or_debit = _get_direction(self.payment_type)
     return [{
         "account": payment_account,
         credit_or_debit: self.total_amount,
         "against": self.party,
     }]
コード例 #13
0
	def get_gl_entries(self):
		gl_entry = []
		self.validate_account_details()
		
		# payable entry
		gl_entry.append(
			self.get_gl_dict({
				"account": self.payable_account,
				"credit": self.total_sanctioned_amount,
				"credit_in_account_currency": self.total_sanctioned_amount,
				"against": ",".join([d.default_account for d in self.expenses]),
				"party_type": "Employee",
				"party": self.employee,
				"against_voucher_type": self.doctype,
				"against_voucher": self.name
			})
		)

		# expense entries
		for data in self.expenses:
			gl_entry.append(
				self.get_gl_dict({
					"account": data.default_account,
					"debit": data.sanctioned_amount,
					"debit_in_account_currency": data.sanctioned_amount,
					"against": self.employee,
					"cost_center": self.cost_center
				})
			)

		if self.is_paid:
			# payment entry
			payment_account = get_bank_cash_account(self.mode_of_payment, self.company).get("account")
			gl_entry.append(
				self.get_gl_dict({
					"account": payment_account,
					"credit": self.total_sanctioned_amount,
					"credit_in_account_currency": self.total_sanctioned_amount,
					"against": self.employee
				})
			)

			gl_entry.append(
				self.get_gl_dict({
					"account": self.payable_account,
					"party_type": "Employee",
					"party": self.employee,
					"against": payment_account,
					"debit": self.total_sanctioned_amount,
					"debit_in_account_currency": self.total_sanctioned_amount,
					"against_voucher": self.name,
					"against_voucher_type": self.doctype,
				})
			)

		return gl_entry
コード例 #14
0
	def get_gl_entries(self):
		gl_entry = []
		self.validate_account_details()
		
		# payable entry
		gl_entry.append(
			self.get_gl_dict({
				"account": self.payable_account,
				"credit": self.total_sanctioned_amount,
				"credit_in_account_currency": self.total_sanctioned_amount,
				"against": ",".join([d.default_account for d in self.expenses]),
				"party_type": "Employee",
				"party": self.employee,
				"against_voucher_type": self.doctype,
				"against_voucher": self.name
			})
		)

		# expense entries
		for data in self.expenses:
			gl_entry.append(
				self.get_gl_dict({
					"account": data.default_account,
					"debit": data.sanctioned_amount,
					"debit_in_account_currency": data.sanctioned_amount,
					"against": self.employee,
					"cost_center": self.cost_center
				})
			)

		if self.is_paid:
			# payment entry
			payment_account = get_bank_cash_account(self.mode_of_payment, self.company).get("account")
			gl_entry.append(
				self.get_gl_dict({
					"account": payment_account,
					"credit": self.total_sanctioned_amount,
					"credit_in_account_currency": self.total_sanctioned_amount,
					"against": self.employee
				})
			)

			gl_entry.append(
				self.get_gl_dict({
					"account": self.payable_account,
					"party_type": "Employee",
					"party": self.employee,
					"against": payment_account,
					"debit": self.total_sanctioned_amount,
					"debit_in_account_currency": self.total_sanctioned_amount,
					"against_voucher": self.name,
					"against_voucher_type": self.doctype,
				})
			)

		return gl_entry
コード例 #15
0
def get_default_bank_cash_account(company,
                                  account_type=None,
                                  mode_of_payment=None,
                                  account=None):
    from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
    if mode_of_payment:
        account = get_bank_cash_account(mode_of_payment,
                                        company).get("account")

    if not account:
        '''
			Set the default account first. If the user hasn't set any default account then, he doesn't
			want us to set any random account. In this case set the account only if there is single
			account (of that type), otherwise return empty dict.
		'''
        if account_type == "Bank":
            account = frappe.db.get_value("Company", company,
                                          "default_bank_account")
            if not account:
                account_list = frappe.get_all("Account",
                                              filters={
                                                  "company": company,
                                                  "account_type": "Bank",
                                                  "is_group": 0
                                              })
                if len(account_list) == 1:
                    account = account_list[0].name

        elif account_type == "Cash":
            account = frappe.db.get_value("Company", company,
                                          "default_cash_account")
            if not account:
                account_list = frappe.get_all("Account",
                                              filters={
                                                  "company": company,
                                                  "account_type": "Cash",
                                                  "is_group": 0
                                              })
                if len(account_list) == 1:
                    account = account_list[0].name

    if account:
        account_details = frappe.db.get_value(
            "Account",
            account, ["account_currency", "account_type"],
            as_dict=1)

        return frappe._dict({
            "account": account,
            "balance": get_balance_on(account),
            "account_currency": account_details.account_currency,
            "account_type": account_details.account_type
        })
    else:
        return frappe._dict()
コード例 #16
0
	def validate(self):
		if not self.total_fees:
			self.total_fees = self.get_total_fees()
		if not self.total_amount:
			self.total_amount = \
			flt(self.interest_amount) + flt(self.principal_amount)
		if not self.total_received:
			self.total_received = \
			flt(self.total_amount) + flt(self.total_fees)

		account_dict = get_bank_cash_account(
			mode_of_payment=self.mode_of_payment or 'Cash',
			company=self.company,
			)
		self.payment_account = account_dict.get('account')
コード例 #17
0
 def make_gl_entries(self, cancel=0):
     payment_account = get_bank_cash_account(
         self.mode_of_payment, self.company
     )
     gl_entries = [
         self.get_gl_dict({
             'account': self.loan_account,
             'debit': self.principal,
         }),
         self.get_gl_dict({
             'account': payment_account.get('account'),
             'credit': self.principal,
             'against': self.customer,
         })
     ]
     make_gl_entries(gl_entries, cancel=cancel, adv_adj=0)
コード例 #18
0
 def make_gl_entries(self, cancel=0):
     payment_account = get_bank_cash_account(
         self.mode_of_payment, self.company
     )
     gl_entries = map(self.get_gl_dict, [
         {
             'account': self.loan_account,
             'debit': self.principal,
         },
         {
             'account': payment_account.get('account'),
             'credit': self.principal,
             'against': self.customer,
             'remarks': 'Loan disbursed',
         },
     ])
     make_gl_entries(gl_entries, cancel=cancel, adv_adj=0)
コード例 #19
0
def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
    from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
    if mode_of_payment:
        account = get_bank_cash_account(mode_of_payment, company)
        if account.get("bank_cash_account"):
            account.update(
                {"balance": get_balance_on(account.get("cash_bank_account"))})
            return account

    account = frappe.db.get_value("Company", company, \
     voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")

    if account:
        return {
            "cash_bank_account": account,
            "balance": get_balance_on(account)
        }
コード例 #20
0
ファイル: journal_entry.py プロジェクト: netfirms/erpnext
def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
    from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account

    if mode_of_payment:
        account = get_bank_cash_account(mode_of_payment, company)
        if account.get("account"):
            account.update({"balance": get_balance_on(account.get("account"))})
            return account

    if voucher_type == "Bank Entry":
        account = frappe.db.get_value("Company", company, "default_bank_account")
        if not account:
            account = frappe.db.get_value("Account", {"company": company, "account_type": "Bank", "is_group": 0})
    elif voucher_type == "Cash Entry":
        account = frappe.db.get_value("Company", company, "default_cash_account")
        if not account:
            account = frappe.db.get_value("Account", {"company": company, "account_type": "Cash", "is_group": 0})

    if account:
        return {"account": account, "balance": get_balance_on(account)}
コード例 #21
0
 def before_save(self):
     gold_loan = frappe.get_doc('Gold Loan', self.loan)
     if not self.mode_of_payment:
         self.mode_of_payment = gold_loan.mode_of_payment
     if not self.payment_account:
         self.payment_account = get_bank_cash_account(
             self.mode_of_payment, self.company
         ).get('account')
     if not self.loan_account:
         self.loan_account = gold_loan.loan_account
     if not self.interest_income_account:
         self.interest_income_account = gold_loan.interest_income_account
     outstanding = get_outstanding(
         self.loan, posting_date=self.posting_date
     )
     interest = outstanding * gold_loan.interest / 100.0
     self.total_interest = self.interest_months * interest
     if self.interest_months > 0:
         self.make_interests(gold_loan, interest)
     self.total_amount = self.capital + self.total_interest
コード例 #22
0
ファイル: journal_entry.py プロジェクト: havid0707/erpnext
def get_default_bank_cash_account(company, account_type=None, mode_of_payment=None, account=None):
	from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
	if mode_of_payment:
		account = get_bank_cash_account(mode_of_payment, company).get("account")

	if not account:
		'''
			Set the default account first. If the user hasn't set any default account then, he doesn't
			want us to set any random account. In this case set the account only if there is single
			account (of that type), otherwise return empty dict.
		'''
		if account_type=="Bank":
			account = frappe.db.get_value("Company", company, "default_bank_account")
			if not account:
				account_list = frappe.get_all("Account", filters = {"company": company,
					"account_type": "Bank", "is_group": 0})
				if len(account_list) == 1:
					account = account_list[0].name

		elif account_type=="Cash":
			account = frappe.db.get_value("Company", company, "default_cash_account")
			if not account:
				account_list = frappe.get_all("Account", filters = {"company": company,
					"account_type": "Cash", "is_group": 0})
				if len(account_list) == 1:
					account = account_list[0].name

	if account:
		account_details = frappe.db.get_value("Account", account,
			["account_currency", "account_type"], as_dict=1)

		return frappe._dict({
			"account": account,
			"balance": get_balance_on(account),
			"account_currency": account_details.account_currency,
			"account_type": account_details.account_type
		})
	else: return frappe._dict()
コード例 #23
0
    def pay(self):
        gl_entry = []
        self.validate_account_details()

        # payment entry
        payment_account = get_bank_cash_account(self.mode_of_payment,
                                                self.company).get("account")
        gl_entry.append(
            self.get_gl_dict({
                "account": payment_account,
                "credit": self.total_sanctioned_amount,
                "credit_in_account_currency": self.total_sanctioned_amount,
                "against": self.employee
            }))

        # payable entry
        gl_entry.append(
            self.get_gl_dict({
                "account":
                self.receivable_account,
                "debit":
                self.total_sanctioned_amount,
                "debit_in_account_currency":
                self.total_sanctioned_amount,
                "against":
                ",".join([d.default_account for d in self.requisition]),
                "party_type":
                "Employee",
                "party":
                self.employee,
                "against_voucher_type":
                self.doctype,
                "against_voucher":
                self.name
            }))

        if flt(self.total_sanctioned_amount) > 0:
            make_gl_entries(gl_entry, False)
コード例 #24
0
 def before_save(self):
     gold_loan = frappe.get_doc('Gold Loan', self.loan)
     if not self.mode_of_payment:
         self.mode_of_payment = gold_loan.mode_of_payment
     if not self.payment_account:
         self.payment_account = get_bank_cash_account(
             self.mode_of_payment, self.company
         ).get('account')
     if not self.loan_account:
         self.loan_account = gold_loan.loan_account
     if not self.interest_income_account:
         self.interest_income_account = gold_loan.interest_income_account
     outstanding = get_outstanding(
         self.loan, posting_date=self.posting_date
     )
     interest = outstanding * gold_loan.interest / 100.0
     self.total_interest = cint(self.interest_months) * interest
     if not self.capital_amount and not self.total_interest:
         return frappe.throw('Cannot transaction with zero amount')
     self.interests = []
     if self.interest_months > 0:
         self.make_interests(gold_loan, interest)
     self.total_amount = self.capital_amount + self.total_interest
コード例 #25
0
ファイル: pos_invoice.py プロジェクト: ankush/erpnext
	def set_account_for_mode_of_payment(self):
		for pay in self.payments:
			if not pay.account:
				pay.account = get_bank_cash_account(pay.mode_of_payment, self.company).get("account")
コード例 #26
0
def submit_invoice(data):
    data = json.loads(data)
    invoice_doc = frappe.get_doc("Sales Invoice", data.get("name"))

    cash_account = get_bank_cash_account("Cash", invoice_doc.company)

    # creating advance payment
    if data.get("credit_change"):
        advance_payment_entry = frappe.get_doc({
            "doctype":
            "Payment Entry",
            "mode_of_payment":
            "Cash",
            "paid_to":
            cash_account["account"],
            "payment_type":
            "Receive",
            "party_type":
            "Customer",
            "party":
            data.get("customer"),
            "paid_amount":
            data.get("credit_change"),
            "received_amount":
            data.get("credit_change"),
        })

        advance_payment_entry.flags.ignore_permissions = True
        frappe.flags.ignore_account_permission = True
        advance_payment_entry.save()
        advance_payment_entry.submit()

    # calculating cash
    total_cash = 0
    if data.get("redeemed_customer_credit"):
        total_cash = invoice_doc.total - float(
            data.get("redeemed_customer_credit"))

    is_payment_entry = 0
    if data.get("redeemed_customer_credit"):
        for row in data.get("customer_credit_dict"):
            if row["type"] == "Advance" and row["credit_to_redeem"]:
                advance = frappe.get_doc("Payment Entry", row["credit_origin"])

                advance_payment = {
                    "reference_type": "Payment Entry",
                    "reference_name": advance.name,
                    "remarks": advance.remarks,
                    "advance_amount": advance.unallocated_amount,
                    "allocated_amount": row["credit_to_redeem"],
                }

                invoice_doc.append("advances", advance_payment)
                invoice_doc.is_pos = 0
                is_payment_entry = 1

    payments = []
    # redeeming customer loyalty
    if data.get("loyalty_amount") > 0:
        invoice_doc.loyalty_amount = data.get("loyalty_amount")
        invoice_doc.redeem_loyalty_points = data.get("redeem_loyalty_points")
        invoice_doc.loyalty_points = data.get("loyalty_points")

    if data.get("is_cashback") and not is_payment_entry:
        for payment in data.get("payments"):
            for i in invoice_doc.payments:
                if i.mode_of_payment == payment["mode_of_payment"]:
                    i.amount = payment["amount"]
                    i.base_amount = 0
                    if i.amount:
                        payments.append(i)
                    break

        if len(payments
               ) == 0 and not invoice_doc.is_return and invoice_doc.is_pos:
            payments = [invoice_doc.payments[0]]
    else:
        invoice_doc.is_pos = 0

    invoice_doc.payments = payments

    invoice_doc.due_date = data.get("due_date")
    invoice_doc.flags.ignore_permissions = True
    frappe.flags.ignore_account_permission = True
    invoice_doc.posa_is_printed = 1
    invoice_doc.save()

    if frappe.get_value(
            "POS Profile",
            invoice_doc.pos_profile,
            "posa_allow_submissions_in_background_job",
    ):
        invoices_list = frappe.get_all(
            "Sales Invoice",
            filters={
                "posa_pos_opening_shift": invoice_doc.posa_pos_opening_shift,
                "docstatus": 0,
                "posa_is_printed": 1,
            },
        )
        for invoice in invoices_list:
            enqueue(
                method=submit_in_background_job,
                queue="short",
                timeout=1000,
                is_async=True,
                kwargs={
                    "invoice": invoice.name,
                    "data": data,
                    "is_payment_entry": is_payment_entry,
                    "total_cash": total_cash,
                    "cash_account": cash_account,
                },
            )
    else:
        invoice_doc.submit()
        redeeming_customer_credit(invoice_doc, data, is_payment_entry,
                                  total_cash, cash_account)

    return {"name": invoice_doc.name, "status": invoice_doc.docstatus}
コード例 #27
0
ファイル: expense_claim.py プロジェクト: MorezMartin/erpnext
    def get_gl_entries(self):
        gl_entry = []
        self.validate_account_details()

        # payable entry
        if self.grand_total:
            gl_entry.append(
                self.get_gl_dict(
                    {
                        "account":
                        self.payable_account,
                        "credit":
                        self.grand_total,
                        "credit_in_account_currency":
                        self.grand_total,
                        "against":
                        ",".join([d.default_account for d in self.expenses]),
                        "party_type":
                        "Employee",
                        "party":
                        self.employee,
                        "against_voucher_type":
                        self.doctype,
                        "against_voucher":
                        self.name,
                        "cost_center":
                        self.cost_center
                    },
                    item=self))

        # expense entries
        for data in self.expenses:
            gl_entry.append(
                self.get_gl_dict(
                    {
                        "account": data.default_account,
                        "debit": data.sanctioned_amount,
                        "debit_in_account_currency": data.sanctioned_amount,
                        "against": self.employee,
                        "cost_center": data.cost_center or self.cost_center
                    },
                    item=data))

        for data in self.advances:
            gl_entry.append(
                self.get_gl_dict({
                    "account":
                    data.advance_account,
                    "credit":
                    data.allocated_amount,
                    "credit_in_account_currency":
                    data.allocated_amount,
                    "against":
                    ",".join([d.default_account for d in self.expenses]),
                    "party_type":
                    "Employee",
                    "party":
                    self.employee,
                    "against_voucher_type":
                    "Employee Advance",
                    "against_voucher":
                    data.employee_advance
                }))

        self.add_tax_gl_entries(gl_entry)

        if self.is_paid and self.grand_total:
            # payment entry
            payment_account = get_bank_cash_account(
                self.mode_of_payment, self.company).get("account")
            gl_entry.append(
                self.get_gl_dict(
                    {
                        "account": payment_account,
                        "credit": self.grand_total,
                        "credit_in_account_currency": self.grand_total,
                        "against": self.employee
                    },
                    item=self))

            gl_entry.append(
                self.get_gl_dict(
                    {
                        "account": self.payable_account,
                        "party_type": "Employee",
                        "party": self.employee,
                        "against": payment_account,
                        "debit": self.grand_total,
                        "debit_in_account_currency": self.grand_total,
                        "against_voucher": self.name,
                        "against_voucher_type": self.doctype,
                    },
                    item=self))

        return gl_entry
コード例 #28
0
ファイル: expense_claim.py プロジェクト: MahmoudFawzy/erpnext
    def get_gl_entries(self):
        gl_entry = []
        self.validate_account_details()

        payable_amount = flt(self.total_sanctioned_amount) - flt(
            self.total_advance_amount)

        comp = frappe.get_doc("Company", self.company)

        # payable entry
        if payable_amount:
            gl_entry.append(
                self.get_gl_dict({
                    "account":
                    self.payable_account,
                    "credit":
                    payable_amount,
                    "credit_in_account_currency":
                    payable_amount,
                    "against":
                    ",".join([d.default_account for d in self.expenses]),
                    "party_type":
                    "Employee",
                    "party":
                    self.employee,
                    "against_voucher_type":
                    self.doctype,
                    "against_voucher":
                    self.name
                }))

        # expense entries
        for data in self.expenses:
            if comp.expenses_vat_account:
                gl_entry.append(
                    self.get_gl_dict({
                        "account":
                        comp.expenses_vat_account,
                        "debit":
                        data.sanctioned_amount - data.claim_amount,
                        "debit_in_account_currency":
                        data.sanctioned_amount - data.claim_amount,
                        "against":
                        self.employee,
                        "cost_center":
                        self.cost_center
                    }))
            gl_entry.append(
                self.get_gl_dict({
                    "account": data.default_account,
                    "debit": data.claim_amount,
                    "debit_in_account_currency": data.claim_amount,
                    "against": self.employee,
                    "cost_center": self.cost_center
                }))

        for data in self.advances:
            gl_entry.append(
                self.get_gl_dict({
                    "account":
                    data.advance_account,
                    "credit":
                    data.allocated_amount,
                    "credit_in_account_currency":
                    data.allocated_amount,
                    "against":
                    ",".join([d.default_account for d in self.expenses]),
                    "party_type":
                    "Employee",
                    "party":
                    self.employee,
                    "against_voucher_type":
                    self.doctype,
                    "against_voucher":
                    self.name
                }))

        if self.is_paid and payable_amount:
            # payment entry
            payment_account = get_bank_cash_account(
                self.mode_of_payment, self.company).get("account")
            gl_entry.append(
                self.get_gl_dict({
                    "account": payment_account,
                    "credit": payable_amount,
                    "credit_in_account_currency": payable_amount,
                    "against": self.employee
                }))

            gl_entry.append(
                self.get_gl_dict({
                    "account": self.payable_account,
                    "party_type": "Employee",
                    "party": self.employee,
                    "against": payment_account,
                    "debit": payable_amount,
                    "debit_in_account_currency": payable_amount,
                    "against_voucher": self.name,
                    "against_voucher_type": self.doctype,
                }))

        return gl_entry
コード例 #29
0
def on_submit(doc, method):
    if doc.patient and not cint(doc.is_return):
        lab_tests = []
        patient = frappe.get_doc('Patient', doc.patient)
        for item in doc.items:
            if not item.lab_test_center:
                test = frappe.get_doc('Lab Test', item.reference_dn) \
                    if item.reference_dt and item.reference_dn else None
                if test and test.status != 'Cancelled':
                    if not test.invoice:
                        test.invoice = doc.name
                        test.save(ignore_permissions=True)
                        lab_tests.append(item.reference_dn)
                else:
                    template = _get_lab_test_template(item.item_code)
                    if template:
                        test = _make_lab_test(patient, template, doc,
                                              item.lab_test_result_date)
                        test.insert(ignore_permissions=True)
                        create_sample_collection(test, template, patient,
                                                 doc.name)
                        load_result_format(test, template, None, doc.name)
                        frappe.db.set_value(
                            'Sales Invoice Item',
                            item.name,
                            'reference_dt',
                            'Lab Test',
                        )
                        frappe.db.set_value(
                            'Sales Invoice Item',
                            item.name,
                            'reference_dn',
                            test.name,
                        )
                        lab_tests.append(test.name)
            else:
                _make_purchase_invoice(doc, item)
        if lab_tests:
            frappe.msgprint('Lab Test(s) {} created.'.format(
                ', '.join(lab_tests)))
        else:
            frappe.msgprint('No Lab Test created.')
        doc.reload()
    if doc.sales_partner and not cint(doc.is_return):
        settings = frappe.get_single('ND Settings')
        je = _make_journal_entry(
            doc,
            frappe._dict({
                'voucher_type':
                'Cash Entry'
                if settings.sales_partner_mop == 'Cash' else 'Bank Entry',
                'accounts': [
                    frappe._dict({
                        'account': settings.sales_partner_ca,
                        'cost_center': settings.sales_partner_cc,
                        'party_type': 'Sales Partner',
                        'party': doc.sales_partner,
                        'debit': 0,
                    }),
                    frappe._dict({
                        'account':
                        get_bank_cash_account(settings.sales_partner_mop,
                                              doc.company).get('account'),
                        'credit':
                        0,
                    }),
                ],
                'user_remark':
                _get_je_remark(doc),
                'pay_to_recd_from':
                doc.sales_partner,
            }))
        je.insert(ignore_permissions=True)
コード例 #30
0
def make_payment(booking,
                 amount,
                 posting_date,
                 mode_of_payment='Cash',
                 is_refund=0,
                 cheque_no=None,
                 cheque_date=None,
                 submit=True):
    is_refund = cint(is_refund)

    from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
    company = frappe.defaults.get_user_default(
        'company', user=frappe.session.user)
    cost_center = frappe.db.get_value('Company', company, 'cost_center')
    bank_cash_account = get_bank_cash_account(mode_of_payment, company)
    receivable_payable_account = frappe.db.get_value(
        "Company", company, "default_receivable_account")
    amount = flt(amount)
    remark = 'Payment received against Booking %s' % (
        booking) if not is_refund else 'Deposit refund against Booking %s' % (
            booking)

    booking_doc = frappe.db.get_values(
        "Accommodation Booking", {"name": booking}, [
            'invoice', 'customer', 'customer_group', 'customer_contact',
            'invoice_amount', 'outstanding_amount', 'advance_amount'
        ],
        as_dict=1)[0]
    invoice = booking_doc.get('invoice', None)
    customer = booking_doc.get('customer', None)
    customer_contact = booking_doc.get('customer_contact', None)
    is_advance = "No" if is_refund or invoice else "Yes"
    if booking_doc.get('customer_group', None) == "Internal":
        remark = _("Internal Voucher for {0} instructed by {1}").format(
            customer, customer_contact)

    journal_entry_to_adjust = get_journal_entry_to_adjust(
        company, customer, amount) if is_refund else None

    if not is_refund and invoice:
        check_outstanding(invoice, amount)

    if mode_of_payment == "Internal Voucher":
        cheque_date = posting_date
        cheque_no = customer_contact

    je = frappe.get_doc({
        "doctype":
        "Journal Entry",
        "voucher_type":
        "Cash Entry" if mode_of_payment == "Cash" else "Bank Entry",
        "posting_date":
        posting_date,
        "company":
        company,
        "remark":
        remark,
        "accommodation_booking":
        booking,
        "cheque_date":
        cheque_date,
        "cheque_no":
        cheque_no
    })

    je.set(
        "accounts",
        [{
            "account": bank_cash_account.get("account"),
            "cost_center": cost_center,
            "debit_in_account_currency": amount if not is_refund else 0,
            "credit_in_account_currency": amount if is_refund else 0,
            "is_advance": is_advance,
        },
         {
             "cost_center": cost_center,
             "account": receivable_payable_account,
             "party_type": "Customer",
             "party": customer,
             "debit_in_account_currency": amount if is_refund else 0,
             "credit_in_account_currency": amount if not is_refund else 0,
             "is_advance": is_advance,
             "reference_type":
             "Sales Invoice" if invoice and not is_refund else None,
             "reference_name": invoice if not is_refund else None
         }])

    je.insert(ignore_permissions=True)
    je.submit()

    # update_payment_status()

    if journal_entry_to_adjust:
        # Update payment JE with reference. Adjust against first unadjusted voucher with amount = refund amount
        voucher_no = journal_entry_to_adjust.reference_name
        entries = frappe.db.get_all(
            "Journal Entry Account",
            filters={
                "parent": voucher_no,
                "account": receivable_payable_account,
                "against_account": bank_cash_account
            })
        for d in entries:
            if not d.reference_type and not d.reference_name:
                frappe.db.set_value('Journal Entry Account', d.name,
                                    'reference_type', "Journal Entry")
                frappe.db.set_value('Journal Entry Account', d.name,
                                    'reference_name', je.name)
        entries = frappe.db.get_all(
            "GL Entry",
            filters={
                "voucher_type": "Journal Entry",
                "voucher_no": voucher_no,
                "party": customer
            })
        for d in entries:
            if not d.against_voucher_type and not d.against_voucher:
                frappe.db.set_value("GL Entry", d.name, "against_voucher_type",
                                    "Journal Entry")
                frappe.db.set_value("GL Entry", d.name, "against_voucher",
                                    je.name)

    advance = booking_doc.advance_amount + (amount
                                            if not is_refund else 0 - amount)
    outstanding = booking_doc.outstanding_amount + (amount if is_refund else
                                                    0 - amount)

    invoice_status = None if not invoice else frappe.db.get_value(
        "Sales Invoice", invoice, 'status')
    frappe.db.sql(
        """
    update `tabAccommodation Booking`
    set advance_amount = %s, outstanding_amount = %s, invoice_status = %s
    where name = %s""", (advance, outstanding, invoice_status, booking))

    # frappe.db.set_value(
    #     "Accommodation Booking",
    #     booking,
    #     "advance_amount",
    #     advance,
    #     update_modified=False)

    # frappe.db.set_value(
    #     "Accommodation Booking",
    #     booking,
    #     "outstanding_amount",
    #     outstanding,
    #     update_modified=False)

    frappe.db.commit()
    return je.name
コード例 #31
0
ファイル: wire_transfer.py プロジェクト: libermatic/vn_custom
 def before_save(self):
     self.status = self.workflow_state
     mop = get_bank_cash_account(self.mode_of_payment, self.company) or {}
     self.cash_account = mop.get("account")