Merge pull request #4337 from nabinhait/payment_tool_fix
[fix] Mapping from Payment Tool
This commit is contained in:
commit
5f0b93ed71
@ -28,7 +28,7 @@ class JournalEntry(AccountsController):
|
||||
self.validate_entries_for_advance()
|
||||
self.validate_multi_currency()
|
||||
self.set_amounts_in_company_currency()
|
||||
self.validate_debit_and_credit()
|
||||
self.validate_total_debit_and_credit()
|
||||
self.validate_against_jv()
|
||||
self.validate_reference_doc()
|
||||
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.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
|
||||
for d in self.get("accounts"):
|
||||
if d.debit and d.credit:
|
||||
@ -264,10 +270,6 @@ class JournalEntry(AccountsController):
|
||||
self.difference = flt(self.total_debit, self.precision("total_debit")) - \
|
||||
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):
|
||||
alternate_currency = []
|
||||
for d in self.get("accounts"):
|
||||
@ -404,7 +406,7 @@ class JournalEntry(AccountsController):
|
||||
blank_row.debit_in_account_currency = abs(diff)
|
||||
blank_row.debit = abs(diff)
|
||||
|
||||
self.validate_debit_and_credit()
|
||||
self.validate_total_debit_and_credit()
|
||||
|
||||
def get_outstanding_invoices(self):
|
||||
self.set('accounts', [])
|
||||
@ -432,7 +434,7 @@ class JournalEntry(AccountsController):
|
||||
elif self.write_off_based_on == 'Accounts Payable':
|
||||
jd2.credit = total
|
||||
|
||||
self.validate_debit_and_credit()
|
||||
self.validate_total_debit_and_credit()
|
||||
|
||||
|
||||
def get_values(self):
|
||||
@ -562,11 +564,16 @@ def get_payment_entry_against_invoice(dt, dn):
|
||||
if dt == "Sales Invoice":
|
||||
party_type = "Customer"
|
||||
party_account = ref_doc.debit_to
|
||||
amount_field_party = "credit_in_account_currency"
|
||||
amount_field_bank = "debit_in_account_currency"
|
||||
else:
|
||||
party_type = "Supplier"
|
||||
party_account = ref_doc.credit_to
|
||||
|
||||
|
||||
if (dt=="Sales Invoice" and ref_doc.outstanding_amount > 0) \
|
||||
or (dt=="Purchase Invoice" and ref_doc.outstanding_amount < 0):
|
||||
amount_field_party = "credit_in_account_currency"
|
||||
amount_field_bank = "debit_in_account_currency"
|
||||
else:
|
||||
amount_field_party = "debit_in_account_currency"
|
||||
amount_field_bank = "credit_in_account_currency"
|
||||
|
||||
@ -576,7 +583,7 @@ def get_payment_entry_against_invoice(dt, dn):
|
||||
"party_account_currency": ref_doc.party_account_currency,
|
||||
"amount_field_party": amount_field_party,
|
||||
"amount_field_bank": amount_field_bank,
|
||||
"amount": ref_doc.outstanding_amount,
|
||||
"amount": abs(ref_doc.outstanding_amount),
|
||||
"remarks": 'Payment received against {0} {1}. {2}'.format(dt, dn, ref_doc.remarks),
|
||||
"is_advance": "No"
|
||||
})
|
||||
@ -601,7 +608,7 @@ def get_payment_entry(ref_doc, args):
|
||||
"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
|
||||
"account_currency": args.get("party_account_currency") or \
|
||||
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")),
|
||||
"exchange_rate": exchange_rate,
|
||||
args.get("amount_field_party"): args.get("amount"),
|
||||
@ -630,6 +637,7 @@ def get_payment_entry(ref_doc, args):
|
||||
jv.multi_currency = 1
|
||||
|
||||
jv.set_amounts_in_company_currency()
|
||||
jv.set_total_debit_credit()
|
||||
|
||||
return jv.as_dict()
|
||||
|
||||
|
@ -8,6 +8,7 @@ from frappe.utils import flt
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from erpnext.accounts.utils import get_account_currency
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate
|
||||
|
||||
class PaymentTool(Document):
|
||||
def make_journal_entry(self):
|
||||
@ -19,7 +20,15 @@ class PaymentTool(Document):
|
||||
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"))
|
||||
|
||||
@ -27,27 +36,56 @@ class PaymentTool(Document):
|
||||
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.set("reference_type", v.against_voucher_type)
|
||||
d1.set("reference_name", v.against_voucher_no)
|
||||
d1.set('is_advance', 'Yes' if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No')
|
||||
total_payment_amount = flt(total_payment_amount) + \
|
||||
flt(d1.debit_in_account_currency) - flt(d1.credit_in_account_currency)
|
||||
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")
|
||||
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:
|
||||
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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user