Merge pull request #22589 from deepeshgarg007/rcm_fix

fix: Do not add GST tax amount in grand total for reverse charge invoices
This commit is contained in:
rohitwaghchaure
2020-07-14 13:42:48 +05:30
committed by GitHub
3 changed files with 49 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
from __future__ import unicode_literals
import frappe, re, json
from frappe import _
from frappe.utils import cstr, flt, date_diff, nowdate
from frappe.utils import cstr, flt, date_diff, nowdate, round_based_on_smallest_currency_fraction, money_in_words
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
@@ -648,6 +648,7 @@ def validate_state_code(state_code, address):
else:
return int(state_code)
@frappe.whitelist()
def get_gst_accounts(company, account_wise=False):
gst_accounts = frappe._dict()
gst_settings_accounts = frappe.get_all("GST Account",
@@ -666,14 +667,49 @@ def get_gst_accounts(company, account_wise=False):
return gst_accounts
def make_reverse_charge_entries(doc, method):
def update_grand_total_for_rcm(doc, method):
if doc.reverse_charge == 'Y':
gst_accounts = get_gst_accounts(doc.company)
gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
+ gst_accounts.get('igst_account')
gst_tax = 0
for tax in doc.get('taxes'):
if tax.category not in ("Total", "Valuation and Total"):
continue
if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in gst_account_list:
gst_tax += tax.base_tax_amount_after_discount_amount
doc.taxes_and_charges_added -= gst_tax
doc.total_taxes_and_charges -= gst_tax
update_totals(gst_tax, doc)
def update_totals(gst_tax, doc):
doc.grand_total -= gst_tax
if doc.meta.get_field("rounded_total"):
if doc.is_rounded_total_disabled():
doc.outstanding_amount = doc.grand_total
else:
doc.rounded_total = round_based_on_smallest_currency_fraction(doc.grand_total,
doc.currency, doc.precision("rounded_total"))
doc.rounding_adjustment += flt(doc.rounded_total - doc.grand_total,
doc.precision("rounding_adjustment"))
doc.outstanding_amount = doc.base_rounded_total
doc.in_words = money_in_words(doc.grand_total, doc.currency)
def make_regional_gl_entries(gl_entries, doc):
country = frappe.get_cached_value('Company', doc.company, 'country')
if country != 'India':
return
if doc.reverse_charge == 'Y':
gl_entries = []
gst_accounts = get_gst_accounts(doc.company)
gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
+ gst_accounts.get('igst_account')
@@ -698,19 +734,4 @@ def make_reverse_charge_entries(doc, method):
}, account_currency, item=tax)
)
gl_entries.append(doc.get_gl_dict(
{
"account": doc.credit_to if doc.doctype == 'Purchase Invoice' else doc.debit_to,
"cost_center": doc.cost_center,
"posting_date": doc.posting_date,
"party_type": 'Supplier',
"party": doc.supplier,
"against": tax.account_head,
"debit": tax.base_tax_amount_after_discount_amount,
"debit_in_account_currency": tax.base_tax_amount_after_discount_amount \
if account_currency==doc.company_currency \
else tax.tax_amount_after_discount_amount
}, account_currency, item=doc)
)
make_gl_entries(gl_entries)
return gl_entries