def test_item_wise_tax_breakup_outside_india(self): frappe.flags.country = "United States" si = self.create_si_to_test_tax_breakup() itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(si) expected_itemised_tax = { "_Test Item": { "Service Tax": { "tax_rate": 10.0, "tax_amount": 1000.0 } }, "_Test Item 2": { "Service Tax": { "tax_rate": 10.0, "tax_amount": 500.0 } } } expected_itemised_taxable_amount = { "_Test Item": 10000.0, "_Test Item 2": 5000.0 } self.assertEqual(itemised_tax, expected_itemised_tax) self.assertEqual(itemised_taxable_amount, expected_itemised_taxable_amount) frappe.flags.country = None
def breakup_taxes(doc): tax, amount = get_itemised_tax_breakup_data(doc) # signatures # tax {item_code: {tax_description: {"tax_rate": tax_rate, "tax_amount": tax_amount}}} # amount {item_code: taxable_amount} def get_amounts(item_code): taxable_amount = amount.get(item_code, 0) vat_amount = sum( [x.get("tax_amount") for x in tax.get(item_code, {}).values()]) return { "taxable_amount": taxable_amount, "vat_amount": vat_amount, "total_amount": taxable_amount + vat_amount, } def get_item_name(item_code): return compose( excepts(StopIteration, first, lambda _: item_code), partial(map, lambda x: x.item_name), lambda: filter(lambda x: x.item_code == item_code, doc.items), )() return [ merge( { "invoice": doc.name, "date": doc.posting_date, "vat_account_no": doc.tax_id, "party_name": doc.get(clauses.get("party_name")), "description": get_item_name(x), }, get_amounts(x), ) for x in amount ]
def test_item_wise_tax_breakup_outside_india(self): frappe.flags.country = "United States" si = self.create_si_to_test_tax_breakup() itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(si) expected_itemised_tax = { "_Test Item": { "Service Tax": { "tax_rate": 10.0, "tax_amount": 1000.0 } }, "_Test Item 2": { "Service Tax": { "tax_rate": 10.0, "tax_amount": 500.0 } } } expected_itemised_taxable_amount = { "_Test Item": 10000.0, "_Test Item 2": 5000.0 } self.assertEqual(itemised_tax, expected_itemised_tax) self.assertEqual(itemised_taxable_amount, expected_itemised_taxable_amount) frappe.flags.country = None
def get_tax_details(invoice_list): tax_breakup = [] tax_details = defaultdict(int) for invoice in invoice_list: doc = frappe.get_doc("Sales Invoice", invoice.name) itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc) if itemised_tax: for a in itemised_tax: for b in itemised_tax[a]: for c in itemised_tax[a][b]: if c == 'tax_rate': tax_details[itemised_tax[a][b][c]] += itemised_tax[a][b]['tax_amount'] for t in tax_details: tax_breakup.append({'rate': t, 'amount': tax_details[t]}) return tax_breakup
def get_tax_details(invoice_list): tax_breakup = [] tax_details = defaultdict(int) for invoice in invoice_list: doc = frappe.get_doc("Sales Invoice", invoice.name) itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc) if itemised_tax: for a in itemised_tax: for b in itemised_tax[a]: for c in itemised_tax[a][b]: if c == 'tax_rate': tax_details[itemised_tax[a][b][c]] += itemised_tax[a][b]['tax_amount'] for t in tax_details: tax_breakup.append({'rate': t, 'amount': tax_details[t]}) return tax_breakup
def test_item_wise_tax_breakup_india(self): frappe.flags.country = "India" si = self.create_si_to_test_tax_breakup() itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(si) expected_itemised_tax = { "999800": { "Service Tax": { "tax_rate": 10.0, "tax_amount": 1500.0 } } } expected_itemised_taxable_amount = { "999800": 15000.0 } self.assertEqual(itemised_tax, expected_itemised_tax) self.assertEqual(itemised_taxable_amount, expected_itemised_taxable_amount) frappe.flags.country = None
def test_item_wise_tax_breakup_india(self): frappe.flags.country = "India" si = self.create_si_to_test_tax_breakup() itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(si) expected_itemised_tax = { "999800": { "Service Tax": { "tax_rate": 10.0, "tax_amount": 1500.0 } } } expected_itemised_taxable_amount = { "999800": 15000.0 } self.assertEqual(itemised_tax, expected_itemised_tax) self.assertEqual(itemised_taxable_amount, expected_itemised_taxable_amount) frappe.flags.country = None
def get_item_wise_tax(self, method): frappe.flags.country = "UAE" tax_breakup = get_itemised_tax_breakup_data(self) import json self.tax_breakup = json.dumps(tax_breakup[0])