mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-23 06:59:20 +00:00
fix: Unallocated amount in Payment Entry after taxes
This commit is contained in:
@@ -400,9 +400,15 @@ class PaymentEntry(AccountsController):
|
|||||||
if not self.advance_tax_account:
|
if not self.advance_tax_account:
|
||||||
frappe.throw(_("Advance TDS account is mandatory for advance TDS deduction"))
|
frappe.throw(_("Advance TDS account is mandatory for advance TDS deduction"))
|
||||||
|
|
||||||
reference_doclist = []
|
|
||||||
net_total = self.paid_amount
|
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
|
# Adding args as purchase invoice to get TDS amount
|
||||||
args = frappe._dict({
|
args = frappe._dict({
|
||||||
@@ -419,7 +425,6 @@ class PaymentEntry(AccountsController):
|
|||||||
return
|
return
|
||||||
|
|
||||||
tax_withholding_details.update({
|
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)
|
'cost_center': self.cost_center or erpnext.get_default_cost_center(self.company)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -505,18 +510,17 @@ class PaymentEntry(AccountsController):
|
|||||||
self.base_total_allocated_amount = abs(base_total_allocated_amount)
|
self.base_total_allocated_amount = abs(base_total_allocated_amount)
|
||||||
|
|
||||||
def set_unallocated_amount(self):
|
def set_unallocated_amount(self):
|
||||||
self.unallocated_amount = 0
|
|
||||||
if self.party:
|
if self.party:
|
||||||
total_deductions = sum([flt(d.amount) for d in self.get("deductions")])
|
total_deductions = sum([flt(d.amount) for d in self.get("deductions")])
|
||||||
if self.payment_type == "Receive" \
|
if self.payment_type == "Receive" \
|
||||||
and self.base_total_allocated_amount < self.base_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_after_tax + (total_deductions / self.source_exchange_rate):
|
and self.total_allocated_amount < self.paid_amount + (total_deductions / self.source_exchange_rate):
|
||||||
self.unallocated_amount = (self.received_amount_after_tax + total_deductions -
|
self.unallocated_amount = (self.received_amount + total_deductions -
|
||||||
self.base_total_allocated_amount) / self.source_exchange_rate
|
self.base_total_allocated_amount) / self.source_exchange_rate
|
||||||
elif self.payment_type == "Pay" \
|
elif self.payment_type == "Pay" \
|
||||||
and self.base_total_allocated_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_after_tax + (total_deductions / self.target_exchange_rate):
|
and self.total_allocated_amount < self.received_amount + (total_deductions / self.target_exchange_rate):
|
||||||
self.unallocated_amount = (self.base_paid_amount_after_tax - (total_deductions +
|
self.unallocated_amount = (self.base_paid_amount - (total_deductions +
|
||||||
self.base_total_allocated_amount)) / self.target_exchange_rate
|
self.base_total_allocated_amount)) / self.target_exchange_rate
|
||||||
|
|
||||||
def set_difference_amount(self):
|
def set_difference_amount(self):
|
||||||
@@ -526,11 +530,11 @@ class PaymentEntry(AccountsController):
|
|||||||
base_party_amount = flt(self.base_total_allocated_amount) + flt(base_unallocated_amount)
|
base_party_amount = flt(self.base_total_allocated_amount) + flt(base_unallocated_amount)
|
||||||
|
|
||||||
if self.payment_type == "Receive":
|
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":
|
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:
|
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")])
|
total_deductions = sum([flt(d.amount) for d in self.get("deductions")])
|
||||||
|
|
||||||
@@ -679,8 +683,8 @@ class PaymentEntry(AccountsController):
|
|||||||
"account": self.paid_from,
|
"account": self.paid_from,
|
||||||
"account_currency": self.paid_from_account_currency,
|
"account_currency": self.paid_from_account_currency,
|
||||||
"against": self.party if self.payment_type=="Pay" else self.paid_to,
|
"against": self.party if self.payment_type=="Pay" else self.paid_to,
|
||||||
"credit_in_account_currency": self.paid_amount_after_tax,
|
"credit_in_account_currency": self.paid_amount,
|
||||||
"credit": self.base_paid_amount_after_tax,
|
"credit": self.base_paid_amount,
|
||||||
"cost_center": self.cost_center
|
"cost_center": self.cost_center
|
||||||
}, item=self)
|
}, item=self)
|
||||||
)
|
)
|
||||||
@@ -690,8 +694,8 @@ class PaymentEntry(AccountsController):
|
|||||||
"account": self.paid_to,
|
"account": self.paid_to,
|
||||||
"account_currency": self.paid_to_account_currency,
|
"account_currency": self.paid_to_account_currency,
|
||||||
"against": self.party if self.payment_type=="Receive" else self.paid_from,
|
"against": self.party if self.payment_type=="Receive" else self.paid_from,
|
||||||
"debit_in_account_currency": self.received_amount_after_tax,
|
"debit_in_account_currency": self.received_amount,
|
||||||
"debit": self.base_received_amount_after_tax,
|
"debit": self.base_received_amount,
|
||||||
"cost_center": self.cost_center
|
"cost_center": self.cost_center
|
||||||
}, item=self)
|
}, item=self)
|
||||||
)
|
)
|
||||||
@@ -704,15 +708,17 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
if self.payment_type == 'Pay':
|
if self.payment_type == 'Pay':
|
||||||
dr_or_cr = "debit" if d.add_deduct_tax == "Add" else "credit"
|
dr_or_cr = "debit" if d.add_deduct_tax == "Add" else "credit"
|
||||||
|
against = self.party or self.paid_from
|
||||||
elif self.payment_type == 'Receive':
|
elif self.payment_type == 'Receive':
|
||||||
dr_or_cr = "credit" if d.add_deduct_tax == "Add" else "debit"
|
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()
|
payment_or_advance_account = self.get_party_account_for_taxes()
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": d.account_head,
|
"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: d.base_tax_amount,
|
||||||
dr_or_cr + "_in_account_currency": d.base_tax_amount
|
dr_or_cr + "_in_account_currency": d.base_tax_amount
|
||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
@@ -724,14 +730,12 @@ class PaymentEntry(AccountsController):
|
|||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": payment_or_advance_account,
|
"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: -1 * d.base_tax_amount,
|
||||||
dr_or_cr + "_in_account_currency": -1*d.base_tax_amount
|
dr_or_cr + "_in_account_currency": -1*d.base_tax_amount
|
||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
else d.tax_amount,
|
else d.tax_amount,
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"party_type": self.party_type,
|
|
||||||
"party": self.party
|
|
||||||
}, account_currency, item=d))
|
}, account_currency, item=d))
|
||||||
|
|
||||||
def add_deductions_gl_entries(self, gl_entries):
|
def add_deductions_gl_entries(self, gl_entries):
|
||||||
@@ -756,9 +760,9 @@ class PaymentEntry(AccountsController):
|
|||||||
if self.advance_tax_account:
|
if self.advance_tax_account:
|
||||||
return self.advance_tax_account
|
return self.advance_tax_account
|
||||||
elif self.payment_type == 'Receive':
|
elif self.payment_type == 'Receive':
|
||||||
return self.paid_from
|
|
||||||
elif self.payment_type == 'Pay':
|
|
||||||
return self.paid_to
|
return self.paid_to
|
||||||
|
elif self.payment_type in ('Pay', 'Internal Transfer'):
|
||||||
|
return self.paid_from
|
||||||
|
|
||||||
def update_advance_paid(self):
|
def update_advance_paid(self):
|
||||||
if self.payment_type in ("Receive", "Pay") and self.party:
|
if self.payment_type in ("Receive", "Pay") and self.party:
|
||||||
@@ -1610,12 +1614,6 @@ def set_paid_amount_and_received_amount(dt, party_account_currency, bank, outsta
|
|||||||
if dt == "Employee Advance":
|
if dt == "Employee Advance":
|
||||||
paid_amount = received_amount * doc.get('exchange_rate', 1)
|
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
|
return paid_amount, received_amount
|
||||||
|
|
||||||
def apply_early_payment_discount(paid_amount, received_amount, doc):
|
def apply_early_payment_discount(paid_amount, received_amount, doc):
|
||||||
|
|||||||
Reference in New Issue
Block a user