mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
[fix] Mapping from Payment Tool
This commit is contained in:
@@ -28,7 +28,7 @@ class JournalEntry(AccountsController):
|
|||||||
self.validate_entries_for_advance()
|
self.validate_entries_for_advance()
|
||||||
self.validate_multi_currency()
|
self.validate_multi_currency()
|
||||||
self.set_amounts_in_company_currency()
|
self.set_amounts_in_company_currency()
|
||||||
self.validate_debit_and_credit()
|
self.validate_total_debit_and_credit()
|
||||||
self.validate_against_jv()
|
self.validate_against_jv()
|
||||||
self.validate_reference_doc()
|
self.validate_reference_doc()
|
||||||
self.set_against_account()
|
self.set_against_account()
|
||||||
@@ -252,7 +252,13 @@ class JournalEntry(AccountsController):
|
|||||||
if flt(d.debit > 0): d.against_account = ", ".join(list(set(accounts_credited)))
|
if flt(d.debit > 0): d.against_account = ", ".join(list(set(accounts_credited)))
|
||||||
if flt(d.credit > 0): d.against_account = ", ".join(list(set(accounts_debited)))
|
if flt(d.credit > 0): d.against_account = ", ".join(list(set(accounts_debited)))
|
||||||
|
|
||||||
def validate_debit_and_credit(self):
|
def validate_total_debit_and_credit(self):
|
||||||
|
self.set_total_debit_credit()
|
||||||
|
if self.difference:
|
||||||
|
frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
|
||||||
|
.format(self.difference))
|
||||||
|
|
||||||
|
def set_total_debit_credit(self):
|
||||||
self.total_debit, self.total_credit, self.difference = 0, 0, 0
|
self.total_debit, self.total_credit, self.difference = 0, 0, 0
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
if d.debit and d.credit:
|
if d.debit and d.credit:
|
||||||
@@ -264,10 +270,6 @@ class JournalEntry(AccountsController):
|
|||||||
self.difference = flt(self.total_debit, self.precision("total_debit")) - \
|
self.difference = flt(self.total_debit, self.precision("total_debit")) - \
|
||||||
flt(self.total_credit, self.precision("total_credit"))
|
flt(self.total_credit, self.precision("total_credit"))
|
||||||
|
|
||||||
if self.difference:
|
|
||||||
frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
|
|
||||||
.format(self.difference))
|
|
||||||
|
|
||||||
def validate_multi_currency(self):
|
def validate_multi_currency(self):
|
||||||
alternate_currency = []
|
alternate_currency = []
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
@@ -404,7 +406,7 @@ class JournalEntry(AccountsController):
|
|||||||
blank_row.debit_in_account_currency = abs(diff)
|
blank_row.debit_in_account_currency = abs(diff)
|
||||||
blank_row.debit = abs(diff)
|
blank_row.debit = abs(diff)
|
||||||
|
|
||||||
self.validate_debit_and_credit()
|
self.validate_total_debit_and_credit()
|
||||||
|
|
||||||
def get_outstanding_invoices(self):
|
def get_outstanding_invoices(self):
|
||||||
self.set('accounts', [])
|
self.set('accounts', [])
|
||||||
@@ -432,7 +434,7 @@ class JournalEntry(AccountsController):
|
|||||||
elif self.write_off_based_on == 'Accounts Payable':
|
elif self.write_off_based_on == 'Accounts Payable':
|
||||||
jd2.credit = total
|
jd2.credit = total
|
||||||
|
|
||||||
self.validate_debit_and_credit()
|
self.validate_total_debit_and_credit()
|
||||||
|
|
||||||
|
|
||||||
def get_values(self):
|
def get_values(self):
|
||||||
@@ -601,7 +603,7 @@ def get_payment_entry(ref_doc, args):
|
|||||||
"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
|
"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
|
||||||
"account_currency": args.get("party_account_currency") or \
|
"account_currency": args.get("party_account_currency") or \
|
||||||
get_account_currency(args.get("party_account")),
|
get_account_currency(args.get("party_account")),
|
||||||
"account_balance": get_balance_on(args.get("party_account")),
|
"balance": get_balance_on(args.get("party_account")),
|
||||||
"party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
|
"party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
|
||||||
"exchange_rate": exchange_rate,
|
"exchange_rate": exchange_rate,
|
||||||
args.get("amount_field_party"): args.get("amount"),
|
args.get("amount_field_party"): args.get("amount"),
|
||||||
@@ -630,6 +632,7 @@ def get_payment_entry(ref_doc, args):
|
|||||||
jv.multi_currency = 1
|
jv.multi_currency = 1
|
||||||
|
|
||||||
jv.set_amounts_in_company_currency()
|
jv.set_amounts_in_company_currency()
|
||||||
|
jv.set_total_debit_credit()
|
||||||
|
|
||||||
return jv.as_dict()
|
return jv.as_dict()
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from frappe.utils import flt
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
import json
|
import json
|
||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
|
from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate
|
||||||
|
|
||||||
class PaymentTool(Document):
|
class PaymentTool(Document):
|
||||||
def make_journal_entry(self):
|
def make_journal_entry(self):
|
||||||
@@ -20,6 +21,14 @@ class PaymentTool(Document):
|
|||||||
jv.cheque_no = self.reference_no
|
jv.cheque_no = self.reference_no
|
||||||
jv.cheque_date = self.reference_date
|
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:
|
if not self.total_payment_amount:
|
||||||
frappe.throw(_("Please enter Payment Amount in atleast one row"))
|
frappe.throw(_("Please enter Payment Amount in atleast one row"))
|
||||||
|
|
||||||
@@ -29,25 +38,54 @@ class PaymentTool(Document):
|
|||||||
v.against_voucher_type))
|
v.against_voucher_type))
|
||||||
|
|
||||||
if v.payment_amount:
|
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 = jv.append("accounts")
|
||||||
d1.account = self.party_account
|
d1.account = self.party_account
|
||||||
d1.party_type = self.party_type
|
d1.party_type = self.party_type
|
||||||
d1.party = self.party
|
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.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" \
|
d1.set("debit_in_account_currency" if self.received_or_paid=="Paid" \
|
||||||
else "credit_in_account_currency", flt(v.payment_amount))
|
else "credit_in_account_currency", flt(v.payment_amount))
|
||||||
d1.set("reference_type", v.against_voucher_type)
|
d1.reference_type = v.against_voucher_type
|
||||||
d1.set("reference_name", v.against_voucher_no)
|
d1.reference_name = v.against_voucher_no
|
||||||
d1.set('is_advance', 'Yes' if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No')
|
d1.is_advance = 'Yes' \
|
||||||
total_payment_amount = flt(total_payment_amount) + \
|
if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No'
|
||||||
flt(d1.debit_in_account_currency) - flt(d1.credit_in_account_currency)
|
|
||||||
|
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")
|
d2 = jv.append("accounts")
|
||||||
d2.account = self.payment_account
|
|
||||||
d2.set('debit_in_account_currency' if total_payment_amount < 0 \
|
|
||||||
else 'credit_in_account_currency', abs(total_payment_amount))
|
|
||||||
if self.payment_account:
|
if self.payment_account:
|
||||||
d2.balance = get_balance_on(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()
|
return jv.as_dict()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user