コード例 #1
0
	def set_exchange_rate(self):
		company_currency = erpnext.get_company_currency(self.doc.company)
		for d in self.doc.get(self.tax_field):
			if d.account_currency == company_currency:
				d.exchange_rate = 1
			elif not d.exchange_rate:
				d.exchange_rate = get_exchange_rate(self.doc.posting_date, account=d.expense_account,
					account_currency=d.account_currency, company=self.doc.company)

			if not d.exchange_rate:
				frappe.throw(_("Row {0}: Exchange Rate is mandatory").format(d.idx))
コード例 #2
0
ファイル: payment_tool.py プロジェクト: saurabh6790/erpnext-1
    def make_journal_entry(self):
        from erpnext.accounts.utils import get_balance_on
        total_payment_amount = 0.00

        jv = frappe.new_doc('Journal Entry')
        jv.voucher_type = 'Journal Entry'
        jv.company = self.company
        jv.cheque_no = self.reference_no
        jv.cheque_date = self.reference_date

        party_account_currency, party_account_type = frappe.db.get_value(
            "Account", self.party_account,
            ["account_currency", "account_type"])

        bank_account_currency, bank_account_type = None, None
        if self.payment_account:
            bank_account_currency, bank_account_type = frappe.db.get_value(
                "Account", self.payment_account,
                ["account_currency", "account_type"])

        if not self.total_payment_amount:
            frappe.throw(_("Please enter Payment Amount in atleast one row"))

        for v in self.get("vouchers"):
            if not frappe.db.get_value(v.against_voucher_type,
                                       {"name": v.against_voucher_no}):
                frappe.throw(
                    _("Row {0}: {1} is not a valid {2}").format(
                        v.idx, v.against_voucher_no, v.against_voucher_type))

            if v.payment_amount:
                exchange_rate = get_exchange_rate(self.party_account,
                                                  party_account_currency,
                                                  self.company,
                                                  v.against_voucher_type,
                                                  v.against_voucher_no)

                d1 = jv.append("accounts")
                d1.account = self.party_account
                d1.party_type = self.party_type
                d1.party = self.party
                d1.account_currency = party_account_currency
                d1.account_type = party_account_type
                d1.balance = get_balance_on(self.party_account)
                d1.party_balance = get_balance_on(party=self.party,
                                                  party_type=self.party_type)
                d1.exchange_rate = exchange_rate
                d1.set("debit_in_account_currency" if self.received_or_paid=="Paid" \
                 else "credit_in_account_currency", flt(v.payment_amount))
                d1.reference_type = v.against_voucher_type
                d1.reference_name = v.against_voucher_no
                d1.is_advance = 'Yes' \
                 if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No'

                amount = flt(d1.debit_in_account_currency) - flt(
                    d1.credit_in_account_currency)
                if bank_account_currency == party_account_currency:
                    total_payment_amount += amount
                else:
                    total_payment_amount += amount * exchange_rate

        d2 = jv.append("accounts")
        if self.payment_account:
            bank_account_currency, bank_account_type = frappe.db.get_value(
                "Account", self.payment_account,
                ["account_currency", "account_type"])

            d2.account = self.payment_account
            d2.account_currency = bank_account_currency
            d2.account_type = bank_account_type
            d2.exchange_rate = get_exchange_rate(self.payment_account,
                                                 self.company)
            d2.account_balance = get_balance_on(self.payment_account)

        amount_field_bank = 'debit_in_account_currency' if total_payment_amount < 0 \
         else 'credit_in_account_currency'

        d2.set(amount_field_bank, abs(total_payment_amount))

        company_currency = frappe.db.get_value("Company", self.company,
                                               "default_currency")
        if party_account_currency != company_currency or \
         (bank_account_currency and bank_account_currency != company_currency):
            jv.multi_currency = 1

        jv.set_amounts_in_company_currency()
        jv.set_total_debit_credit()

        return jv.as_dict()
コード例 #3
0
ファイル: payment_tool.py プロジェクト: dublado/erpnext
    def make_journal_entry(self):
        from erpnext.accounts.utils import get_balance_on

        total_payment_amount = 0.00

        jv = frappe.new_doc("Journal Entry")
        jv.voucher_type = "Journal Entry"
        jv.company = self.company
        jv.cheque_no = self.reference_no
        jv.cheque_date = self.reference_date

        party_account_currency, party_account_type = frappe.db.get_value(
            "Account", self.party_account, ["account_currency", "account_type"]
        )

        bank_account_currency, bank_account_type = None, None
        if self.payment_account:
            bank_account_currency, bank_account_type = frappe.db.get_value(
                "Account", self.payment_account, ["account_currency", "account_type"]
            )

        if not self.total_payment_amount:
            frappe.throw(_("Please enter Payment Amount in atleast one row"))

        for v in self.get("vouchers"):
            if not frappe.db.get_value(v.against_voucher_type, {"name": v.against_voucher_no}):
                frappe.throw(
                    _("Row {0}: {1} is not a valid {2}").format(v.idx, v.against_voucher_no, v.against_voucher_type)
                )

            if v.payment_amount:
                exchange_rate = get_exchange_rate(
                    self.party_account,
                    party_account_currency,
                    self.company,
                    v.against_voucher_type,
                    v.against_voucher_no,
                )

                d1 = jv.append("accounts")
                d1.account = self.party_account
                d1.party_type = self.party_type
                d1.party = self.party
                d1.account_currency = party_account_currency
                d1.account_type = party_account_type
                d1.balance = get_balance_on(self.party_account)
                d1.party_balance = get_balance_on(party=self.party, party_type=self.party_type)
                d1.exchange_rate = exchange_rate
                d1.set(
                    "debit_in_account_currency" if self.received_or_paid == "Paid" else "credit_in_account_currency",
                    flt(v.payment_amount),
                )
                d1.reference_type = v.against_voucher_type
                d1.reference_name = v.against_voucher_no
                d1.is_advance = "Yes" if v.against_voucher_type in ["Sales Order", "Purchase Order"] else "No"

                amount = flt(d1.debit_in_account_currency) - flt(d1.credit_in_account_currency)
                if bank_account_currency == party_account_currency:
                    total_payment_amount += amount
                else:
                    total_payment_amount += amount * exchange_rate

        d2 = jv.append("accounts")
        if self.payment_account:
            bank_account_currency, bank_account_type = frappe.db.get_value(
                "Account", self.payment_account, ["account_currency", "account_type"]
            )

            d2.account = self.payment_account
            d2.account_currency = bank_account_currency
            d2.account_type = bank_account_type
            d2.exchange_rate = get_exchange_rate(
                self.payment_account,
                bank_account_currency,
                self.company,
                debit=(abs(total_payment_amount) if total_payment_amount < 0 else 0),
                credit=(total_payment_amount if total_payment_amount > 0 else 0),
            )
            d2.account_balance = get_balance_on(self.payment_account)

        amount_field_bank = "debit_in_account_currency" if total_payment_amount < 0 else "credit_in_account_currency"

        d2.set(amount_field_bank, abs(total_payment_amount))

        company_currency = frappe.db.get_value("Company", self.company, "default_currency")
        if party_account_currency != company_currency or (
            bank_account_currency and bank_account_currency != company_currency
        ):
            jv.multi_currency = 1

        jv.set_amounts_in_company_currency()
        jv.set_total_debit_credit()

        return jv.as_dict()