fix: Allocate advance taxes only for payment entry
This commit is contained in:
parent
e2f83ffaa4
commit
a23aaf43f4
@ -903,42 +903,43 @@ class PurchaseInvoice(BuyingController):
|
|||||||
def allocate_advance_taxes(self, gl_entries):
|
def allocate_advance_taxes(self, gl_entries):
|
||||||
tax_map = self.get_tax_map()
|
tax_map = self.get_tax_map()
|
||||||
for pe in self.get('advances'):
|
for pe in self.get('advances'):
|
||||||
pe = frappe.get_doc('Payment Entry', pe.reference_name)
|
if pe.reference_type == 'Payment Entry':
|
||||||
for tax in pe.get('taxes'):
|
pe = frappe.get_doc('Payment Entry', pe.reference_name)
|
||||||
account_currency = get_account_currency(tax.account_head)
|
for tax in pe.get('taxes'):
|
||||||
dr_or_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
|
account_currency = get_account_currency(tax.account_head)
|
||||||
rev_dr_cr = "debit" if tax.add_deduct_tax == "Add" else "credit"
|
dr_or_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
|
||||||
|
rev_dr_cr = "debit" if tax.add_deduct_tax == "Add" else "credit"
|
||||||
|
|
||||||
unallocated_amount = tax.tax_amount - tax.allocated_amount
|
unallocated_amount = tax.tax_amount - tax.allocated_amount
|
||||||
if tax_map.get(tax.account_head):
|
if tax_map.get(tax.account_head):
|
||||||
amount = tax_map.get(tax.account_head)
|
amount = tax_map.get(tax.account_head)
|
||||||
if amount < unallocated_amount:
|
if amount < unallocated_amount:
|
||||||
unallocated_amount = amount
|
unallocated_amount = amount
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": tax.account_head,
|
"account": tax.account_head,
|
||||||
"against": self.supplier,
|
"against": self.supplier,
|
||||||
dr_or_cr: unallocated_amount,
|
dr_or_cr: unallocated_amount,
|
||||||
dr_or_cr + "_in_account_currency": unallocated_amount
|
dr_or_cr + "_in_account_currency": unallocated_amount
|
||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
else unallocated_amount,
|
else unallocated_amount,
|
||||||
'cost_center': tax.cost_center
|
'cost_center': tax.cost_center
|
||||||
}, account_currency, item=tax))
|
}, account_currency, item=tax))
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": pe.advance_tax_account,
|
"account": pe.advance_tax_account,
|
||||||
"against": self.supplier,
|
"against": self.supplier,
|
||||||
rev_dr_cr: unallocated_amount,
|
rev_dr_cr: unallocated_amount,
|
||||||
rev_dr_cr + "_in_account_currency": unallocated_amount
|
rev_dr_cr + "_in_account_currency": unallocated_amount
|
||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
else unallocated_amount,
|
else unallocated_amount,
|
||||||
'cost_center': tax.cost_center or self.cost_center
|
'cost_center': tax.cost_center or self.cost_center
|
||||||
}, account_currency, item=tax))
|
}, account_currency, item=tax))
|
||||||
|
|
||||||
frappe.db.set_value('Advance Taxes and Charges', tax.name, 'allocated_amount', tax.allocated_amount + unallocated_amount)
|
frappe.db.set_value('Advance Taxes and Charges', tax.name, 'allocated_amount', tax.allocated_amount + unallocated_amount)
|
||||||
tax_map[tax.account_head] -= unallocated_amount
|
tax_map[tax.account_head] -= unallocated_amount
|
||||||
|
|
||||||
def make_payment_gl_entries(self, gl_entries):
|
def make_payment_gl_entries(self, gl_entries):
|
||||||
# Make Cash GL Entries
|
# Make Cash GL Entries
|
||||||
|
|||||||
@ -916,42 +916,43 @@ class SalesInvoice(SellingController):
|
|||||||
def allocate_advance_taxes(self, gl_entries):
|
def allocate_advance_taxes(self, gl_entries):
|
||||||
tax_map = self.get_tax_map()
|
tax_map = self.get_tax_map()
|
||||||
for pe in self.get('advances'):
|
for pe in self.get('advances'):
|
||||||
pe = frappe.get_doc('Payment Entry', pe.reference_name)
|
if pe.reference_type == 'Payment Entry':
|
||||||
for tax in pe.get('taxes'):
|
pe = frappe.get_doc('Payment Entry', pe.reference_name)
|
||||||
account_currency = get_account_currency(tax.account_head)
|
for tax in pe.get('taxes'):
|
||||||
dr_or_cr = "debit" if tax.add_deduct_tax == "Add" else "credit"
|
account_currency = get_account_currency(tax.account_head)
|
||||||
rev_dr_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
|
dr_or_cr = "debit" if tax.add_deduct_tax == "Add" else "credit"
|
||||||
|
rev_dr_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
|
||||||
|
|
||||||
unallocated_amount = tax.tax_amount - tax.allocated_amount
|
unallocated_amount = tax.tax_amount - tax.allocated_amount
|
||||||
if tax_map.get(tax.account_head):
|
if tax_map.get(tax.account_head):
|
||||||
amount = tax_map.get(tax.account_head)
|
amount = tax_map.get(tax.account_head)
|
||||||
if amount < unallocated_amount:
|
if amount < unallocated_amount:
|
||||||
unallocated_amount = amount
|
unallocated_amount = amount
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": tax.account_head,
|
"account": tax.account_head,
|
||||||
"against": self.customer,
|
"against": self.customer,
|
||||||
dr_or_cr: unallocated_amount,
|
dr_or_cr: unallocated_amount,
|
||||||
dr_or_cr + "_in_account_currency": unallocated_amount
|
dr_or_cr + "_in_account_currency": unallocated_amount
|
||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
else unallocated_amount,
|
else unallocated_amount,
|
||||||
'cost_center': tax.cost_center
|
'cost_center': tax.cost_center
|
||||||
}, account_currency, item=tax))
|
}, account_currency, item=tax))
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": pe.advance_tax_account,
|
"account": pe.advance_tax_account,
|
||||||
"against": self.customer,
|
"against": self.customer,
|
||||||
rev_dr_cr: unallocated_amount,
|
rev_dr_cr: unallocated_amount,
|
||||||
rev_dr_cr + "_in_account_currency": unallocated_amount
|
rev_dr_cr + "_in_account_currency": unallocated_amount
|
||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
else unallocated_amount,
|
else unallocated_amount,
|
||||||
'cost_center': tax.cost_center
|
'cost_center': tax.cost_center
|
||||||
}, account_currency, item=tax))
|
}, account_currency, item=tax))
|
||||||
|
|
||||||
frappe.db.set_value('Advance Taxes and Charges', tax.name, 'allocated_amount', tax.allocated_amount + unallocated_amount)
|
frappe.db.set_value('Advance Taxes and Charges', tax.name, 'allocated_amount', tax.allocated_amount + unallocated_amount)
|
||||||
tax_map[tax.account_head] -= unallocated_amount
|
tax_map[tax.account_head] -= unallocated_amount
|
||||||
|
|
||||||
def make_item_gl_entries(self, gl_entries):
|
def make_item_gl_entries(self, gl_entries):
|
||||||
# income account gl entries
|
# income account gl entries
|
||||||
|
|||||||
@ -726,16 +726,17 @@ class AccountsController(TransactionBase):
|
|||||||
tax_map = self.get_tax_map()
|
tax_map = self.get_tax_map()
|
||||||
|
|
||||||
for pe in self.get('advances'):
|
for pe in self.get('advances'):
|
||||||
pe = frappe.get_doc('Payment Entry', pe.reference_name)
|
if pe.reference_type == 'Payment Entry':
|
||||||
for tax in pe.get('taxes'):
|
pe = frappe.get_doc('Payment Entry', pe.reference_name)
|
||||||
allocated_amount = tax_map.get(tax.account_head) - allocated_tax_map.get(tax.account_head)
|
for tax in pe.get('taxes'):
|
||||||
if allocated_amount > tax.tax_amount:
|
allocated_amount = tax_map.get(tax.account_head) - allocated_tax_map.get(tax.account_head)
|
||||||
allocated_amount = tax.tax_amount
|
if allocated_amount > tax.tax_amount:
|
||||||
|
allocated_amount = tax.tax_amount
|
||||||
|
|
||||||
if allocated_amount:
|
if allocated_amount:
|
||||||
frappe.db.set_value('Advance Taxes and Charges', tax.name, 'allocated_amount', tax.allocated_amount - allocated_amount)
|
frappe.db.set_value('Advance Taxes and Charges', tax.name, 'allocated_amount', tax.allocated_amount - allocated_amount)
|
||||||
tax_map[tax.account_head] -= allocated_amount
|
tax_map[tax.account_head] -= allocated_amount
|
||||||
allocated_tax_map[tax.account_head] -= allocated_amount
|
allocated_tax_map[tax.account_head] -= allocated_amount
|
||||||
|
|
||||||
def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
|
def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
|
||||||
from erpnext.controllers.status_updater import get_allowance_for
|
from erpnext.controllers.status_updater import get_allowance_for
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user