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:
@@ -438,6 +438,8 @@ class PurchaseInvoice(BuyingController):
|
|||||||
|
|
||||||
self.make_tax_gl_entries(gl_entries)
|
self.make_tax_gl_entries(gl_entries)
|
||||||
|
|
||||||
|
gl_entries = make_regional_gl_entries(gl_entries, self)
|
||||||
|
|
||||||
gl_entries = merge_similar_entries(gl_entries)
|
gl_entries = merge_similar_entries(gl_entries)
|
||||||
|
|
||||||
self.make_payment_gl_entries(gl_entries)
|
self.make_payment_gl_entries(gl_entries)
|
||||||
@@ -1108,6 +1110,10 @@ def get_list_context(context=None):
|
|||||||
})
|
})
|
||||||
return list_context
|
return list_context
|
||||||
|
|
||||||
|
@erpnext.allow_regional
|
||||||
|
def make_regional_gl_entries(gl_entries, doc):
|
||||||
|
return gl_entries
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_debit_note(source_name, target_doc=None):
|
def make_debit_note(source_name, target_doc=None):
|
||||||
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ doc_events = {
|
|||||||
"on_trash": "erpnext.regional.check_deletion_permission"
|
"on_trash": "erpnext.regional.check_deletion_permission"
|
||||||
},
|
},
|
||||||
"Purchase Invoice": {
|
"Purchase Invoice": {
|
||||||
"on_submit": "erpnext.regional.india.utils.make_reverse_charge_entries"
|
"validate": "erpnext.regional.india.utils.update_grand_total_for_rcm"
|
||||||
},
|
},
|
||||||
"Payment Entry": {
|
"Payment Entry": {
|
||||||
"on_submit": ["erpnext.regional.create_transaction_log", "erpnext.accounts.doctype.payment_request.payment_request.update_payment_req_status"],
|
"on_submit": ["erpnext.regional.create_transaction_log", "erpnext.accounts.doctype.payment_request.payment_request.update_payment_req_status"],
|
||||||
@@ -374,7 +374,8 @@ regional_overrides = {
|
|||||||
'erpnext.controllers.taxes_and_totals.get_itemised_tax_breakup_data': 'erpnext.regional.india.utils.get_itemised_tax_breakup_data',
|
'erpnext.controllers.taxes_and_totals.get_itemised_tax_breakup_data': 'erpnext.regional.india.utils.get_itemised_tax_breakup_data',
|
||||||
'erpnext.accounts.party.get_regional_address_details': 'erpnext.regional.india.utils.get_regional_address_details',
|
'erpnext.accounts.party.get_regional_address_details': 'erpnext.regional.india.utils.get_regional_address_details',
|
||||||
'erpnext.hr.utils.calculate_annual_eligible_hra_exemption': 'erpnext.regional.india.utils.calculate_annual_eligible_hra_exemption',
|
'erpnext.hr.utils.calculate_annual_eligible_hra_exemption': 'erpnext.regional.india.utils.calculate_annual_eligible_hra_exemption',
|
||||||
'erpnext.hr.utils.calculate_hra_exemption_for_period': 'erpnext.regional.india.utils.calculate_hra_exemption_for_period'
|
'erpnext.hr.utils.calculate_hra_exemption_for_period': 'erpnext.regional.india.utils.calculate_hra_exemption_for_period',
|
||||||
|
'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_regional_gl_entries': 'erpnext.regional.india.utils.make_regional_gl_entries'
|
||||||
},
|
},
|
||||||
'United Arab Emirates': {
|
'United Arab Emirates': {
|
||||||
'erpnext.controllers.taxes_and_totals.update_itemised_tax_data': 'erpnext.regional.united_arab_emirates.utils.update_itemised_tax_data'
|
'erpnext.controllers.taxes_and_totals.update_itemised_tax_data': 'erpnext.regional.united_arab_emirates.utils.update_itemised_tax_data'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, re, json
|
import frappe, re, json
|
||||||
from frappe import _
|
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.regional.india import states, state_numbers
|
||||||
from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount
|
from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount
|
||||||
from erpnext.controllers.accounts_controller import get_taxes_and_charges
|
from erpnext.controllers.accounts_controller import get_taxes_and_charges
|
||||||
@@ -648,6 +648,7 @@ def validate_state_code(state_code, address):
|
|||||||
else:
|
else:
|
||||||
return int(state_code)
|
return int(state_code)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
def get_gst_accounts(company, account_wise=False):
|
def get_gst_accounts(company, account_wise=False):
|
||||||
gst_accounts = frappe._dict()
|
gst_accounts = frappe._dict()
|
||||||
gst_settings_accounts = frappe.get_all("GST Account",
|
gst_settings_accounts = frappe.get_all("GST Account",
|
||||||
@@ -666,14 +667,49 @@ def get_gst_accounts(company, account_wise=False):
|
|||||||
|
|
||||||
return gst_accounts
|
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')
|
country = frappe.get_cached_value('Company', doc.company, 'country')
|
||||||
|
|
||||||
if country != 'India':
|
if country != 'India':
|
||||||
return
|
return
|
||||||
|
|
||||||
if doc.reverse_charge == 'Y':
|
if doc.reverse_charge == 'Y':
|
||||||
gl_entries = []
|
|
||||||
gst_accounts = get_gst_accounts(doc.company)
|
gst_accounts = get_gst_accounts(doc.company)
|
||||||
gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
|
gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
|
||||||
+ gst_accounts.get('igst_account')
|
+ gst_accounts.get('igst_account')
|
||||||
@@ -698,19 +734,4 @@ def make_reverse_charge_entries(doc, method):
|
|||||||
}, account_currency, item=tax)
|
}, account_currency, item=tax)
|
||||||
)
|
)
|
||||||
|
|
||||||
gl_entries.append(doc.get_gl_dict(
|
return gl_entries
|
||||||
{
|
|
||||||
"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)
|
|
||||||
Reference in New Issue
Block a user