fix: Unallocated amount in Payment Entry after taxes

This commit is contained in:
Deepesh Garg 2021-07-09 18:04:24 +05:30
parent a5200d6a43
commit f661d82c00

View File

@ -411,9 +411,15 @@ class PaymentEntry(AccountsController):
if not self.advance_tax_account:
frappe.throw(_("Advance TDS account is mandatory for advance TDS deduction"))
reference_doclist = []
net_total = self.paid_amount
included_in_paid_amount = 0
for reference in self.get("references"):
net_total_for_tds = 0
if reference.reference_doctype == 'Purchase Order':
net_total_for_tds += flt(frappe.db.get_value('Purchase Order', reference.reference_name, 'net_total'))
if net_total_for_tds:
net_total = net_total_for_tds
# Adding args as purchase invoice to get TDS amount
args = frappe._dict({
@ -430,7 +436,6 @@ class PaymentEntry(AccountsController):
return
tax_withholding_details.update({
'included_in_paid_amount': included_in_paid_amount,
'cost_center': self.cost_center or erpnext.get_default_cost_center(self.company)
})
@ -516,18 +521,17 @@ class PaymentEntry(AccountsController):
self.base_total_allocated_amount = abs(base_total_allocated_amount)
def set_unallocated_amount(self):
self.unallocated_amount = 0
if self.party:
total_deductions = sum(flt(d.amount) for d in self.get("deductions"))
if self.payment_type == "Receive" \
and self.base_total_allocated_amount < self.base_received_amount_after_tax + total_deductions \
and self.total_allocated_amount < self.paid_amount_after_tax + (total_deductions / self.source_exchange_rate):
self.unallocated_amount = (self.received_amount_after_tax + total_deductions -
and self.base_total_allocated_amount < self.base_received_amount + total_deductions \
and self.total_allocated_amount < self.paid_amount + (total_deductions / self.source_exchange_rate):
self.unallocated_amount = (self.received_amount + total_deductions -
self.base_total_allocated_amount) / self.source_exchange_rate
elif self.payment_type == "Pay" \
and self.base_total_allocated_amount < (self.base_paid_amount_after_tax - total_deductions) \
and self.total_allocated_amount < self.received_amount_after_tax + (total_deductions / self.target_exchange_rate):
self.unallocated_amount = (self.base_paid_amount_after_tax - (total_deductions +
and self.base_total_allocated_amount < (self.base_paid_amount - total_deductions) \
and self.total_allocated_amount < self.received_amount + (total_deductions / self.target_exchange_rate):
self.unallocated_amount = (self.base_paid_amount - (total_deductions +
self.base_total_allocated_amount)) / self.target_exchange_rate
def set_difference_amount(self):
@ -537,11 +541,11 @@ class PaymentEntry(AccountsController):
base_party_amount = flt(self.base_total_allocated_amount) + flt(base_unallocated_amount)
if self.payment_type == "Receive":
self.difference_amount = base_party_amount - self.base_received_amount_after_tax
self.difference_amount = base_party_amount - self.base_received_amount
elif self.payment_type == "Pay":
self.difference_amount = self.base_paid_amount_after_tax - base_party_amount
self.difference_amount = self.base_paid_amount - base_party_amount
else:
self.difference_amount = self.base_paid_amount_after_tax - flt(self.base_received_amount_after_tax)
self.difference_amount = self.base_paid_amount - flt(self.base_received_amount)
total_deductions = sum(flt(d.amount) for d in self.get("deductions"))
@ -690,8 +694,8 @@ class PaymentEntry(AccountsController):
"account": self.paid_from,
"account_currency": self.paid_from_account_currency,
"against": self.party if self.payment_type=="Pay" else self.paid_to,
"credit_in_account_currency": self.paid_amount_after_tax,
"credit": self.base_paid_amount_after_tax,
"credit_in_account_currency": self.paid_amount,
"credit": self.base_paid_amount,
"cost_center": self.cost_center
}, item=self)
)
@ -701,8 +705,8 @@ class PaymentEntry(AccountsController):
"account": self.paid_to,
"account_currency": self.paid_to_account_currency,
"against": self.party if self.payment_type=="Receive" else self.paid_from,
"debit_in_account_currency": self.received_amount_after_tax,
"debit": self.base_received_amount_after_tax,
"debit_in_account_currency": self.received_amount,
"debit": self.base_received_amount,
"cost_center": self.cost_center
}, item=self)
)
@ -715,15 +719,17 @@ class PaymentEntry(AccountsController):
if self.payment_type in ('Pay', 'Internal Transfer'):
dr_or_cr = "debit" if d.add_deduct_tax == "Add" else "credit"
against = self.party or self.paid_from
elif self.payment_type == 'Receive':
dr_or_cr = "credit" if d.add_deduct_tax == "Add" else "debit"
against = self.party or self.paid_to
payment_or_advance_account = self.get_party_account_for_taxes()
gl_entries.append(
self.get_gl_dict({
"account": d.account_head,
"against": self.party if self.payment_type=="Receive" else self.paid_from,
"against": against,
dr_or_cr: d.base_tax_amount,
dr_or_cr + "_in_account_currency": d.base_tax_amount
if account_currency==self.company_currency
@ -735,14 +741,12 @@ class PaymentEntry(AccountsController):
gl_entries.append(
self.get_gl_dict({
"account": payment_or_advance_account,
"against": self.party if self.payment_type=="Receive" else self.paid_from,
"against": against,
dr_or_cr: -1 * d.base_tax_amount,
dr_or_cr + "_in_account_currency": -1*d.base_tax_amount
if account_currency==self.company_currency
else d.tax_amount,
"cost_center": self.cost_center,
"party_type": self.party_type,
"party": self.party
}, account_currency, item=d))
def add_deductions_gl_entries(self, gl_entries):
@ -767,9 +771,9 @@ class PaymentEntry(AccountsController):
if self.advance_tax_account:
return self.advance_tax_account
elif self.payment_type == 'Receive':
return self.paid_from
elif self.payment_type in ('Pay', 'Internal Transfer'):
return self.paid_to
elif self.payment_type in ('Pay', 'Internal Transfer'):
return self.paid_from
def update_advance_paid(self):
if self.payment_type in ("Receive", "Pay") and self.party:
@ -1648,12 +1652,6 @@ def set_paid_amount_and_received_amount(dt, party_account_currency, bank, outsta
if dt == "Employee Advance":
paid_amount = received_amount * doc.get('exchange_rate', 1)
if dt == "Purchase Order" and doc.apply_tds:
if party_account_currency == bank.account_currency:
paid_amount = received_amount = doc.base_net_total
else:
paid_amount = received_amount = doc.base_net_total * doc.get('exchange_rate', 1)
return paid_amount, received_amount
def apply_early_payment_discount(paid_amount, received_amount, doc):