fix: GST on freight charge in e-invoicing (#25000)

* fix: GST on freight charge in e-invocing

* fix: Add patch for taxable value field

* fix: Handle discounts on net total

* fix: Handle all types of discounts for e-invoicing

* fix: Absolute taxable values

* fix: Use correct tax amount
This commit is contained in:
Deepesh Garg
2021-04-12 10:55:43 +05:30
committed by GitHub
parent 9f73bd8040
commit c36e48a869
6 changed files with 108 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import unicode_literals
import frappe, re, json
from frappe import _
import erpnext
from frappe.utils import cstr, flt, date_diff, nowdate, round_based_on_smallest_currency_fraction, money_in_words, getdate
from frappe.utils import cstr, flt, cint, date_diff, nowdate, round_based_on_smallest_currency_fraction, money_in_words, getdate
from erpnext.regional.india import states, state_numbers
from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount
from erpnext.controllers.accounts_controller import get_taxes_and_charges
@@ -832,3 +832,48 @@ def get_regional_round_off_accounts(company, account_list):
account_list.extend(gst_account_list)
return account_list
def update_taxable_values(doc, method):
country = frappe.get_cached_value('Company', doc.company, 'country')
if country != 'India':
return
gst_accounts = get_gst_accounts(doc.company)
# Only considering sgst account to avoid inflating taxable value
gst_account_list = gst_accounts.get('sgst_account', []) + gst_accounts.get('sgst_account', []) \
+ gst_accounts.get('igst_account', [])
additional_taxes = 0
total_charges = 0
item_count = 0
considered_rows = []
for tax in doc.get('taxes'):
prev_row_id = cint(tax.row_id) - 1
if tax.account_head in gst_account_list and prev_row_id not in considered_rows:
if tax.charge_type == 'On Previous Row Amount':
additional_taxes += doc.get('taxes')[prev_row_id].tax_amount_after_discount_amount
considered_rows.append(prev_row_id)
if tax.charge_type == 'On Previous Row Total':
additional_taxes += doc.get('taxes')[prev_row_id].base_total - doc.base_net_total
considered_rows.append(prev_row_id)
for item in doc.get('items'):
if doc.apply_discount_on == 'Grand Total' and doc.discount_amount:
proportionate_value = item.base_amount if doc.base_total else item.qty
total_value = doc.base_total if doc.base_total else doc.total_qty
else:
proportionate_value = item.base_net_amount if doc.base_net_total else item.qty
total_value = doc.base_net_total if doc.base_net_total else doc.total_qty
applicable_charges = flt(flt(proportionate_value * (flt(additional_taxes) / flt(total_value)),
item.precision('taxable_value')))
item.taxable_value = applicable_charges + proportionate_value
total_charges += applicable_charges
item_count += 1
if total_charges != additional_taxes:
diff = additional_taxes - total_charges
doc.get('items')[item_count - 1].taxable_value += diff