Skip to content

Commit

Permalink
feat: item wise tds calculation for purchase order.
Browse files Browse the repository at this point in the history
(cherry picked from commit 46e8cdf)
  • Loading branch information
niralisatapara authored and mergify[bot] committed Nov 23, 2022
1 parent ba36435 commit 2bd8bd2
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Expand Up @@ -226,6 +226,42 @@ def test_tds_calculation_on_net_total_partial_tds(self):
for d in reversed(invoices):
d.cancel()

orders = []

po = create_purchase_order(supplier="Test TDS Supplier4", rate=20000, do_not_save=True)
po.extend(
"items",
[
{
"doctype": "Purchase Order Item",
"item_code": frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name"),
"qty": 1,
"rate": 20000,
"cost_center": "Main - _TC",
"expense_account": "Stock Received But Not Billed - _TC",
"apply_tds": 0,
},
{
"doctype": "Purchase Order Item",
"item_code": frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name"),
"qty": 1,
"rate": 35000,
"cost_center": "Main - _TC",
"expense_account": "Stock Received But Not Billed - _TC",
"apply_tds": 1,
},
],
)
po.save()
po.submit()
orders.append(po)

self.assertEqual(po.taxes[0].tax_amount, 5500)

# cancel orders to avoid clashing
for d in reversed(orders):
d.cancel()

def test_multi_category_single_supplier(self):
frappe.db.set_value(
"Supplier", "Test TDS Supplier5", "tax_withholding_category", "Test Service Category"
Expand Down Expand Up @@ -348,6 +384,39 @@ def create_purchase_invoice(**args):
return pi


def create_purchase_order(**args):
# return purchase order doc object
item = frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name")

args = frappe._dict(args)
po = frappe.get_doc(
{
"doctype": "Purchase Order",
"transaction_date": today(),
"schedule_date": today(),
"apply_tds": 0 if args.do_not_apply_tds else 1,
"supplier": args.supplier,
"company": "_Test Company",
"taxes_and_charges": "",
"currency": "INR",
"taxes": [],
"items": [
{
"doctype": "Purchase Order Item",
"item_code": item,
"qty": args.qty or 1,
"rate": args.rate or 10000,
"cost_center": "Main - _TC",
"expense_account": "Stock Received But Not Billed - _TC",
}
],
}
)

po.save()
return po


def create_sales_invoice(**args):
# return sales invoice doc object
item = frappe.db.get_value("Item", {"item_name": "TCS Item"}, "name")
Expand Down
Expand Up @@ -25,5 +25,21 @@ def execute():
).where(
purchase_invoice.docstatus == 1
).run()

purchase_order = frappe.qb.DocType("Purchase Order")

frappe.qb.update(purchase_order).set(
purchase_order.tax_withholding_net_total, purchase_order.net_total
).set(
purchase_order.base_tax_withholding_net_total, purchase_order.base_net_total
).where(
purchase_order.company == company.name
).where(
purchase_order.apply_tds == 1
).where(
purchase_order.transaction_date >= fiscal_year_details.year_start_date
).where(
purchase_order.docstatus == 1
).run()
except FiscalYearError:
pass

0 comments on commit 2bd8bd2

Please sign in to comment.