fix: Add tests
This commit is contained in:
parent
5ba3b28d69
commit
f07f010962
@ -25,8 +25,7 @@
|
|||||||
"allocated_amount",
|
"allocated_amount",
|
||||||
"column_break_13",
|
"column_break_13",
|
||||||
"base_tax_amount",
|
"base_tax_amount",
|
||||||
"base_total",
|
"base_total"
|
||||||
"base_allocated_amount"
|
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -168,12 +167,6 @@
|
|||||||
"label": "Allocated Amount",
|
"label": "Allocated Amount",
|
||||||
"options": "currency"
|
"options": "currency"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "base_allocated_amount",
|
|
||||||
"fieldtype": "Currency",
|
|
||||||
"label": "Allocated Amount (Company Currency)",
|
|
||||||
"options": "Company:company:default_currency"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fetch_from": "account_head.account_currency",
|
"fetch_from": "account_head.account_currency",
|
||||||
"fieldname": "currency",
|
"fieldname": "currency",
|
||||||
@ -186,7 +179,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-06-09 11:46:58.373170",
|
"modified": "2021-11-25 11:10:10.945027",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Advance Taxes and Charges",
|
"name": "Advance Taxes and Charges",
|
||||||
|
@ -435,24 +435,16 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
net_total = self.paid_amount
|
net_total = self.paid_amount
|
||||||
|
|
||||||
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({
|
||||||
'company': self.company,
|
'company': self.company,
|
||||||
'doctype': 'Purchase Invoice',
|
'doctype': 'Payment Entry',
|
||||||
'supplier': self.party,
|
'supplier': self.party,
|
||||||
'posting_date': self.posting_date,
|
'posting_date': self.posting_date,
|
||||||
'net_total': net_total
|
'net_total': net_total
|
||||||
})
|
})
|
||||||
|
|
||||||
tax_withholding_details, tax_deducted_on_advances = get_party_tax_withholding_details(args, self.tax_withholding_category)
|
tax_withholding_details = get_party_tax_withholding_details(args, self.tax_withholding_category)
|
||||||
|
|
||||||
if not tax_withholding_details:
|
if not tax_withholding_details:
|
||||||
return
|
return
|
||||||
@ -1593,10 +1585,6 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
|
|||||||
})
|
})
|
||||||
pe.set_difference_amount()
|
pe.set_difference_amount()
|
||||||
|
|
||||||
if doc.doctype == 'Purchase Order' and doc.apply_tds:
|
|
||||||
pe.apply_tax_withholding_amount = 1
|
|
||||||
pe.tax_withholding_category = doc.tax_withholding_category
|
|
||||||
|
|
||||||
return pe
|
return pe
|
||||||
|
|
||||||
def get_bank_cash_account(doc, bank_account):
|
def get_bank_cash_account(doc, bank_account):
|
||||||
|
@ -1160,25 +1160,21 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
# Create Purchase Order with TDS applied
|
# Create Purchase Order with TDS applied
|
||||||
po = create_purchase_order(do_not_save=1, supplier=supplier.name, rate=3000, item='_Test Non Stock Item',
|
po = create_purchase_order(do_not_save=1, supplier=supplier.name, rate=3000, item='_Test Non Stock Item',
|
||||||
posting_date='2021-09-15')
|
posting_date='2021-09-15')
|
||||||
po.apply_tds = 1
|
|
||||||
po.tax_withholding_category = 'TDS - 194 - Dividends - Individual'
|
|
||||||
po.save()
|
po.save()
|
||||||
po.submit()
|
po.submit()
|
||||||
|
|
||||||
# Update Unrealized Profit / Loss Account which is used as default advance tax account
|
|
||||||
frappe.db.set_value('Company', '_Test Company', 'unrealized_profit_loss_account', '_Test Account Excise Duty - _TC')
|
|
||||||
|
|
||||||
# Create Payment Entry Against the order
|
# Create Payment Entry Against the order
|
||||||
payment_entry = get_payment_entry(dt='Purchase Order', dn=po.name)
|
payment_entry = get_payment_entry(dt='Purchase Order', dn=po.name)
|
||||||
payment_entry.paid_from = 'Cash - _TC'
|
payment_entry.paid_from = 'Cash - _TC'
|
||||||
|
payment_entry.apply_tax_withholding_amount = 1
|
||||||
|
payment_entry.tax_withholding_category = 'TDS - 194 - Dividends - Individual'
|
||||||
payment_entry.save()
|
payment_entry.save()
|
||||||
payment_entry.submit()
|
payment_entry.submit()
|
||||||
|
|
||||||
# Check GLE for Payment Entry
|
# Check GLE for Payment Entry
|
||||||
expected_gle = [
|
expected_gle = [
|
||||||
['_Test Account Excise Duty - _TC', 3000, 0],
|
|
||||||
['Cash - _TC', 0, 27000],
|
['Cash - _TC', 0, 27000],
|
||||||
['Creditors - _TC', 27000, 0],
|
['Creditors - _TC', 30000, 0],
|
||||||
['TDS Payable - _TC', 0, 3000],
|
['TDS Payable - _TC', 0, 3000],
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1204,9 +1200,7 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
# Zero net effect on final TDS Payable on invoice
|
# Zero net effect on final TDS Payable on invoice
|
||||||
expected_gle = [
|
expected_gle = [
|
||||||
['_Test Account Cost for Goods Sold - _TC', 30000],
|
['_Test Account Cost for Goods Sold - _TC', 30000],
|
||||||
['_Test Account Excise Duty - _TC', -3000],
|
['Creditors - _TC', -30000]
|
||||||
['Creditors - _TC', -27000],
|
|
||||||
['TDS Payable - _TC', 0]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
gl_entries = frappe.db.sql("""select account, sum(debit - credit) as amount
|
gl_entries = frappe.db.sql("""select account, sum(debit - credit) as amount
|
||||||
@ -1219,6 +1213,14 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
self.assertEqual(expected_gle[i][0], gle.account)
|
self.assertEqual(expected_gle[i][0], gle.account)
|
||||||
self.assertEqual(expected_gle[i][1], gle.amount)
|
self.assertEqual(expected_gle[i][1], gle.amount)
|
||||||
|
|
||||||
|
payment_entry.load_from_db()
|
||||||
|
self.assertEqual(payment_entry.taxes[0].allocated_amount, 3000)
|
||||||
|
|
||||||
|
purchase_invoice.cancel()
|
||||||
|
|
||||||
|
payment_entry.load_from_db()
|
||||||
|
self.assertEqual(payment_entry.taxes[0].allocated_amount, 0)
|
||||||
|
|
||||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
||||||
gl_entries = frappe.db.sql("""select account, debit, credit, posting_date
|
gl_entries = frappe.db.sql("""select account, debit, credit, posting_date
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
|
@ -197,7 +197,10 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N
|
|||||||
advance_vouchers = get_advance_vouchers(parties, company=inv.company, from_date=tax_details.from_date,
|
advance_vouchers = get_advance_vouchers(parties, company=inv.company, from_date=tax_details.from_date,
|
||||||
to_date=tax_details.to_date, party_type=party_type)
|
to_date=tax_details.to_date, party_type=party_type)
|
||||||
taxable_vouchers = vouchers + advance_vouchers
|
taxable_vouchers = vouchers + advance_vouchers
|
||||||
tax_deducted_on_advances = get_taxes_deducted_on_advances_allocated(inv, tax_details)
|
tax_deducted_on_advances = 0
|
||||||
|
|
||||||
|
if inv.doctype == 'Purchase Invoice':
|
||||||
|
tax_deducted_on_advances = get_taxes_deducted_on_advances_allocated(inv, tax_details)
|
||||||
|
|
||||||
tax_deducted = 0
|
tax_deducted = 0
|
||||||
if taxable_vouchers:
|
if taxable_vouchers:
|
||||||
|
@ -145,15 +145,16 @@ class AccountsController(TransactionBase):
|
|||||||
self.validate_party()
|
self.validate_party()
|
||||||
self.validate_currency()
|
self.validate_currency()
|
||||||
|
|
||||||
|
if self.doctype in ['Purchase Invoice', 'Sales Invoice']:
|
||||||
|
pos_check_field = "is_pos" if self.doctype=="Sales Invoice" else "is_paid"
|
||||||
|
if cint(self.allocate_advances_automatically) and not cint(self.get(pos_check_field)):
|
||||||
|
self.set_advances()
|
||||||
|
|
||||||
if self.doctype == 'Purchase Invoice':
|
if self.doctype == 'Purchase Invoice':
|
||||||
self.calculate_paid_amount()
|
self.calculate_paid_amount()
|
||||||
# apply tax withholding only if checked and applicable
|
# apply tax withholding only if checked and applicable
|
||||||
self.set_tax_withholding()
|
self.set_tax_withholding()
|
||||||
|
|
||||||
if self.doctype in ['Purchase Invoice', 'Sales Invoice']:
|
|
||||||
pos_check_field = "is_pos" if self.doctype=="Sales Invoice" else "is_paid"
|
|
||||||
if cint(self.allocate_advances_automatically) and not cint(self.get(pos_check_field)):
|
|
||||||
self.set_advances()
|
|
||||||
|
|
||||||
self.set_advance_gain_or_loss()
|
self.set_advance_gain_or_loss()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user