mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 05:09:11 +00:00
fix(e-invoicing): validations & tax calculation fixes (#25315)
* fix: GST on freight charge in e-invoicing * fix: cannot fetch e invoice settings * fix: address validations & cancel eway bill dialog * fix: except einvoice loading error seperately * fix: sider * fix: import format_date * fix: imports * fix: test * fix: test * fix: test * fix: validate total condition * feat: add company link to e-invoice settings * fix: remove extra condition * fix: test Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com>
This commit is contained in:
@@ -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, calculate_outstanding_amount
|
||||
from erpnext.controllers.accounts_controller import get_taxes_and_charges
|
||||
@@ -827,3 +827,48 @@ def get_gst_tax_amount(doc):
|
||||
gst_tax -= tax.tax_amount_after_discount_amount
|
||||
|
||||
return gst_tax, base_gst_tax
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user