mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +00:00
fix: Missing commits from hotfix branch (#17997)
* fix: merge conflict * fix: restored missing set_gst_state_and_state_number function * fix: style linting as per codacy * fix: Fixes related to customer/lead merging * fix: merge conflict * fix: Fixes related to customer/lead merging * fix: Assign isue/opportunity to user * fix: Assign isue/opportunity to user * fix: Replaced Invoice type by GST Category * fix: merge conflict * fix: merge conflict * fix: test cases * fix: test cases
This commit is contained in:
@@ -209,9 +209,10 @@ def make_custom_fields(update=True):
|
||||
'fieldname': 'gst_transporter_id',
|
||||
'label': 'GST Transporter ID',
|
||||
'fieldtype': 'Data',
|
||||
'insert_after': 'transporter_name',
|
||||
'insert_after': 'transporter',
|
||||
'fetch_from': 'transporter.gst_transporter_id',
|
||||
'print_hide': 1
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'mode_of_transport',
|
||||
@@ -219,18 +220,142 @@ def make_custom_fields(update=True):
|
||||
'fieldtype': 'Select',
|
||||
'options': '\nRoad\nAir\nRail\nShip',
|
||||
'default': 'Road',
|
||||
'insert_after': 'transporter_name',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'gst_vehicle_type',
|
||||
'label': 'GST Vehicle Type',
|
||||
'fieldtype': 'Select',
|
||||
'options': 'Regular\nOver Dimensional Cargo (ODC)',
|
||||
'depends_on': 'eval:(doc.mode_of_transport === "Road")',
|
||||
'default': 'Regular',
|
||||
'insert_after': 'lr_date',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
}
|
||||
]
|
||||
|
||||
si_ewaybill_fields = [
|
||||
{
|
||||
'fieldname': 'transporter_info',
|
||||
'label': 'Transporter Info',
|
||||
'fieldtype': 'Section Break',
|
||||
'insert_after': 'terms',
|
||||
'collapsible': 1,
|
||||
'collapsible_depends_on': 'transporter',
|
||||
'print_hide': 1
|
||||
},
|
||||
{
|
||||
'fieldname': 'transporter',
|
||||
'label': 'Transporter',
|
||||
'fieldtype': 'Link',
|
||||
'insert_after': 'transporter_info',
|
||||
'options': 'Supplier',
|
||||
'print_hide': 1
|
||||
},
|
||||
{
|
||||
'fieldname': 'gst_transporter_id',
|
||||
'label': 'GST Transporter ID',
|
||||
'fieldtype': 'Data',
|
||||
'insert_after': 'transporter',
|
||||
'fetch_from': 'transporter.gst_transporter_id',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'driver',
|
||||
'label': 'Driver',
|
||||
'fieldtype': 'Link',
|
||||
'insert_after': 'gst_transporter_id',
|
||||
'options': 'Driver',
|
||||
'print_hide': 1
|
||||
},
|
||||
{
|
||||
'fieldname': 'lr_no',
|
||||
'label': 'Transport Receipt No',
|
||||
'fieldtype': 'Data',
|
||||
'insert_after': 'driver',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'vehicle_no',
|
||||
'label': 'Vehicle No',
|
||||
'fieldtype': 'Data',
|
||||
'insert_after': 'lr_no',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'distance',
|
||||
'label': 'Distance (in km)',
|
||||
'fieldtype': 'Float',
|
||||
'insert_after': 'vehicle_no',
|
||||
'print_hide': 1
|
||||
},
|
||||
{
|
||||
'fieldname': 'transporter_col_break',
|
||||
'fieldtype': 'Column Break',
|
||||
'insert_after': 'distance'
|
||||
},
|
||||
{
|
||||
'fieldname': 'transporter_name',
|
||||
'label': 'Transporter Name',
|
||||
'fieldtype': 'Data',
|
||||
'insert_after': 'transporter_col_break',
|
||||
'fetch_from': 'transporter.name',
|
||||
'read_only': 1,
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'mode_of_transport',
|
||||
'label': 'Mode of Transport',
|
||||
'fieldtype': 'Select',
|
||||
'options': '\nRoad\nAir\nRail\nShip',
|
||||
'default': 'Road',
|
||||
'insert_after': 'transporter_name',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'driver_name',
|
||||
'label': 'Driver Name',
|
||||
'fieldtype': 'Data',
|
||||
'insert_after': 'mode_of_transport',
|
||||
'fetch_from': 'driver.full_name',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'lr_date',
|
||||
'label': 'Transport Receipt Date',
|
||||
'fieldtype': 'Date',
|
||||
'insert_after': 'driver_name',
|
||||
'default': 'Today',
|
||||
'print_hide': 1
|
||||
},
|
||||
{
|
||||
'fieldname': 'gst_vehicle_type',
|
||||
'label': 'GST Vehicle Type',
|
||||
'fieldtype': 'Select',
|
||||
'options': '\nRegular\nOver Dimensional Cargo (ODC)',
|
||||
'default': 'Regular',
|
||||
'options': 'Regular\nOver Dimensional Cargo (ODC)',
|
||||
'depends_on': 'eval:(doc.mode_of_transport === "Road")',
|
||||
'insert_after': 'mode_of_transport',
|
||||
'print_hide': 1
|
||||
'default': 'Regular',
|
||||
'insert_after': 'lr_date',
|
||||
'print_hide': 1,
|
||||
'translatable': 0
|
||||
},
|
||||
{
|
||||
'fieldname': 'ewaybill',
|
||||
'label': 'e-Way Bill No.',
|
||||
'fieldtype': 'Data',
|
||||
'depends_on': 'eval:(doc.docstatus === 1)',
|
||||
'allow_on_submit': 1,
|
||||
'insert_after': 'project',
|
||||
'translatable': 0
|
||||
}
|
||||
]
|
||||
|
||||
@@ -246,8 +371,8 @@ def make_custom_fields(update=True):
|
||||
'Purchase Invoice': purchase_invoice_gst_category + invoice_gst_fields + purchase_invoice_itc_fields + purchase_invoice_gst_fields,
|
||||
'Purchase Order': purchase_invoice_gst_fields,
|
||||
'Purchase Receipt': purchase_invoice_gst_fields,
|
||||
'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields,
|
||||
'Delivery Note': sales_invoice_gst_fields + ewaybill_fields,
|
||||
'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields + si_ewaybill_fields,
|
||||
'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields,
|
||||
'Sales Order': sales_invoice_gst_fields,
|
||||
'Sales Taxes and Charges Template': inter_state_gst_field,
|
||||
'Purchase Taxes and Charges Template': inter_state_gst_field,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe, re
|
||||
import frappe, re, json
|
||||
from frappe import _
|
||||
from frappe.utils import cstr, flt, date_diff, nowdate
|
||||
from erpnext.regional.india import states, state_numbers
|
||||
@@ -40,23 +40,26 @@ def validate_gstin_for_india(doc, method):
|
||||
frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the format of GSTIN."))
|
||||
|
||||
validate_gstin_check_digit(doc.gstin)
|
||||
set_gst_state_and_state_number(doc)
|
||||
|
||||
if not doc.gst_state:
|
||||
if not doc.state:
|
||||
return
|
||||
state = doc.state.lower()
|
||||
states_lowercase = {s.lower():s for s in states}
|
||||
if state in states_lowercase:
|
||||
doc.gst_state = states_lowercase[state]
|
||||
else:
|
||||
return
|
||||
|
||||
doc.gst_state_number = state_numbers[doc.gst_state]
|
||||
if doc.gst_state_number != doc.gstin[:2]:
|
||||
frappe.throw(_("Invalid GSTIN! First 2 digits of GSTIN should match with State number {0}.")
|
||||
.format(doc.gst_state_number))
|
||||
|
||||
def validate_gstin_check_digit(gstin):
|
||||
def set_gst_state_and_state_number(doc):
|
||||
if not doc.gst_state:
|
||||
if not doc.state:
|
||||
return
|
||||
state = doc.state.lower()
|
||||
states_lowercase = {s.lower():s for s in states}
|
||||
if state in states_lowercase:
|
||||
doc.gst_state = states_lowercase[state]
|
||||
else:
|
||||
return
|
||||
|
||||
doc.gst_state_number = state_numbers[doc.gst_state]
|
||||
|
||||
def validate_gstin_check_digit(gstin, label='GSTIN'):
|
||||
''' Function to validate the check digit of the GSTIN.'''
|
||||
factor = 1
|
||||
total = 0
|
||||
@@ -69,8 +72,8 @@ def validate_gstin_check_digit(gstin):
|
||||
total += digit
|
||||
factor = 2 if factor == 1 else 1
|
||||
if gstin[-1] != code_point_chars[((mod - (total % mod)) % mod)]:
|
||||
frappe.throw(_("Invalid GSTIN! The check digit validation has failed. " +
|
||||
"Please ensure you've typed the GSTIN correctly."))
|
||||
frappe.throw(_("Invalid {0}! The check digit validation has failed. " +
|
||||
"Please ensure you've typed the {0} correctly.".format(label)))
|
||||
|
||||
def get_itemised_tax_breakup_header(item_doctype, tax_accounts):
|
||||
if frappe.get_meta(item_doctype).has_field('gst_hsn_code'):
|
||||
@@ -78,8 +81,8 @@ def get_itemised_tax_breakup_header(item_doctype, tax_accounts):
|
||||
else:
|
||||
return [_("Item"), _("Taxable Amount")] + tax_accounts
|
||||
|
||||
def get_itemised_tax_breakup_data(doc):
|
||||
itemised_tax = get_itemised_tax(doc.taxes)
|
||||
def get_itemised_tax_breakup_data(doc, account_wise=False):
|
||||
itemised_tax = get_itemised_tax(doc.taxes, with_tax_account=account_wise)
|
||||
|
||||
itemised_taxable_amount = get_itemised_taxable_amount(doc.items)
|
||||
|
||||
@@ -94,14 +97,17 @@ def get_itemised_tax_breakup_data(doc):
|
||||
for item, taxes in itemised_tax.items():
|
||||
hsn_code = item_hsn_map.get(item)
|
||||
hsn_tax.setdefault(hsn_code, frappe._dict())
|
||||
for tax_account, tax_detail in taxes.items():
|
||||
hsn_tax[hsn_code].setdefault(tax_account, {"tax_rate": 0, "tax_amount": 0})
|
||||
hsn_tax[hsn_code][tax_account]["tax_rate"] = tax_detail.get("tax_rate")
|
||||
hsn_tax[hsn_code][tax_account]["tax_amount"] += tax_detail.get("tax_amount")
|
||||
for tax_desc, tax_detail in taxes.items():
|
||||
key = tax_desc
|
||||
if account_wise:
|
||||
key = tax_detail.get('tax_account')
|
||||
hsn_tax[hsn_code].setdefault(key, {"tax_rate": 0, "tax_amount": 0})
|
||||
hsn_tax[hsn_code][key]["tax_rate"] = tax_detail.get("tax_rate")
|
||||
hsn_tax[hsn_code][key]["tax_amount"] += tax_detail.get("tax_amount")
|
||||
|
||||
# set taxable amount
|
||||
hsn_taxable_amount = frappe._dict()
|
||||
for item, taxable_amount in itemised_taxable_amount.items():
|
||||
for item in itemised_taxable_amount:
|
||||
hsn_code = item_hsn_map.get(item)
|
||||
hsn_taxable_amount.setdefault(hsn_code, 0)
|
||||
hsn_taxable_amount[hsn_code] += itemised_taxable_amount.get(item)
|
||||
@@ -276,6 +282,102 @@ def calculate_hra_exemption_for_period(doc):
|
||||
exemptions["total_eligible_hra_exemption"] = eligible_hra
|
||||
return exemptions
|
||||
|
||||
def get_ewb_data(dt, dn):
|
||||
if dt != 'Sales Invoice':
|
||||
frappe.throw(_('e-Way Bill JSON can only be generated from Sales Invoice'))
|
||||
|
||||
dn = dn.split(',')
|
||||
|
||||
ewaybills = []
|
||||
for doc_name in dn:
|
||||
doc = frappe.get_doc(dt, doc_name)
|
||||
|
||||
validate_sales_invoice(doc)
|
||||
|
||||
data = frappe._dict({
|
||||
"transporterId": "",
|
||||
"TotNonAdvolVal": 0,
|
||||
})
|
||||
|
||||
data.userGstin = data.fromGstin = doc.company_gstin
|
||||
data.supplyType = 'O'
|
||||
|
||||
if doc.gst_category in ['Registered Regular', 'SEZ']:
|
||||
data.subSupplyType = 1
|
||||
elif doc.gst_category in ['Overseas', 'Deemed Export']:
|
||||
data.subSupplyType = 3
|
||||
else:
|
||||
frappe.throw(_('Unsupported GST Category for e-Way Bill JSON generation'))
|
||||
|
||||
data.docType = 'INV'
|
||||
data.docDate = frappe.utils.formatdate(doc.posting_date, 'dd/mm/yyyy')
|
||||
|
||||
company_address = frappe.get_doc('Address', doc.company_address)
|
||||
billing_address = frappe.get_doc('Address', doc.customer_address)
|
||||
|
||||
shipping_address = frappe.get_doc('Address', doc.shipping_address_name)
|
||||
|
||||
data = get_address_details(data, doc, company_address, billing_address)
|
||||
|
||||
data.itemList = []
|
||||
data.totalValue = doc.total
|
||||
|
||||
data = get_item_list(data, doc)
|
||||
|
||||
disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total')
|
||||
data.totInvValue = doc.grand_total if disable_rounded else doc.rounded_total
|
||||
|
||||
data = get_transport_details(data, doc)
|
||||
|
||||
fields = {
|
||||
"/. -": {
|
||||
'docNo': doc.name,
|
||||
'fromTrdName': doc.company,
|
||||
'toTrdName': doc.customer_name,
|
||||
'transDocNo': doc.lr_no,
|
||||
},
|
||||
"@#/,&. -": {
|
||||
'fromAddr1': company_address.address_line1,
|
||||
'fromAddr2': company_address.address_line2,
|
||||
'fromPlace': company_address.city,
|
||||
'toAddr1': shipping_address.address_line1,
|
||||
'toAddr2': shipping_address.address_line2,
|
||||
'toPlace': shipping_address.city,
|
||||
'transporterName': doc.transporter_name
|
||||
}
|
||||
}
|
||||
|
||||
for allowed_chars, field_map in fields.items():
|
||||
for key, value in field_map.items():
|
||||
if not value:
|
||||
data[key] = ''
|
||||
else:
|
||||
data[key] = re.sub(r'[^\w' + allowed_chars + ']', '', value)
|
||||
|
||||
ewaybills.append(data)
|
||||
|
||||
data = {
|
||||
'version': '1.0.1118',
|
||||
'billLists': ewaybills
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
@frappe.whitelist()
|
||||
def generate_ewb_json(dt, dn):
|
||||
|
||||
data = get_ewb_data(dt, dn)
|
||||
|
||||
frappe.local.response.filecontent = json.dumps(data, indent=4, sort_keys=True)
|
||||
frappe.local.response.type = 'download'
|
||||
|
||||
if len(data['billLists']) > 1:
|
||||
doc_name = 'Bulk'
|
||||
else:
|
||||
doc_name = dn
|
||||
|
||||
frappe.local.response.filename = '{0}_e-WayBill_Data_{1}.json'.format(doc_name, frappe.utils.random_string(5))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_gstins_for_company(company):
|
||||
company_gstins =[]
|
||||
@@ -291,3 +393,177 @@ def get_gstins_for_company(company):
|
||||
`tabDynamic Link`.link_name = '{0}'""".format(company))
|
||||
return company_gstins
|
||||
|
||||
def get_address_details(data, doc, company_address, billing_address):
|
||||
data.fromPincode = validate_pincode(company_address.pincode, 'Company Address')
|
||||
data.fromStateCode = data.actualFromStateCode = validate_state_code(
|
||||
company_address.gst_state_number, 'Company Address')
|
||||
|
||||
if not doc.billing_address_gstin or len(doc.billing_address_gstin) < 15:
|
||||
data.toGstin = 'URP'
|
||||
set_gst_state_and_state_number(billing_address)
|
||||
else:
|
||||
data.toGstin = doc.billing_address_gstin
|
||||
|
||||
data.toPincode = validate_pincode(billing_address.pincode, 'Customer Address')
|
||||
data.toStateCode = validate_state_code(billing_address.gst_state_number, 'Customer Address')
|
||||
|
||||
if doc.customer_address != doc.shipping_address_name:
|
||||
data.transType = 2
|
||||
shipping_address = frappe.get_doc('Address', doc.shipping_address_name)
|
||||
set_gst_state_and_state_number(shipping_address)
|
||||
data.toPincode = validate_pincode(shipping_address.pincode, 'Shipping Address')
|
||||
data.actualToStateCode = validate_state_code(shipping_address.gst_state_number, 'Shipping Address')
|
||||
else:
|
||||
data.transType = 1
|
||||
data.actualToStateCode = data.toStateCode
|
||||
shipping_address = billing_address
|
||||
|
||||
return data
|
||||
|
||||
def get_item_list(data, doc):
|
||||
for attr in ['cgstValue', 'sgstValue', 'igstValue', 'cessValue', 'OthValue']:
|
||||
data[attr] = 0
|
||||
|
||||
gst_accounts = get_gst_accounts(doc.company, account_wise=True)
|
||||
tax_map = {
|
||||
'sgst_account': ['sgstRate', 'sgstValue'],
|
||||
'cgst_account': ['cgstRate', 'cgstValue'],
|
||||
'igst_account': ['igstRate', 'igstValue'],
|
||||
'cess_account': ['cessRate', 'cessValue']
|
||||
}
|
||||
item_data_attrs = ['sgstRate', 'cgstRate', 'igstRate', 'cessRate', 'cessNonAdvol']
|
||||
hsn_wise_charges, hsn_taxable_amount = get_itemised_tax_breakup_data(doc, account_wise=True)
|
||||
for hsn_code, taxable_amount in hsn_taxable_amount.items():
|
||||
item_data = frappe._dict()
|
||||
if not hsn_code:
|
||||
frappe.throw(_('GST HSN Code does not exist for one or more items'))
|
||||
item_data.hsnCode = int(hsn_code)
|
||||
item_data.taxableAmount = taxable_amount
|
||||
item_data.qtyUnit = ""
|
||||
for attr in item_data_attrs:
|
||||
item_data[attr] = 0
|
||||
|
||||
for account, tax_detail in hsn_wise_charges.get(hsn_code, {}).items():
|
||||
account_type = gst_accounts.get(account, '')
|
||||
for tax_acc, attrs in tax_map.items():
|
||||
if account_type == tax_acc:
|
||||
item_data[attrs[0]] = tax_detail.get('tax_rate')
|
||||
data[attrs[1]] += tax_detail.get('tax_amount')
|
||||
break
|
||||
else:
|
||||
data.OthValue += tax_detail.get('tax_amount')
|
||||
|
||||
data.itemList.append(item_data)
|
||||
|
||||
# Tax amounts rounded to 2 decimals to avoid exceeding max character limit
|
||||
for attr in ['sgstValue', 'cgstValue', 'igstValue', 'cessValue']:
|
||||
data[attr] = flt(data[attr], 2)
|
||||
|
||||
return data
|
||||
|
||||
def validate_sales_invoice(doc):
|
||||
if doc.docstatus != 1:
|
||||
frappe.throw(_('e-Way Bill JSON can only be generated from submitted document'))
|
||||
|
||||
if doc.is_return:
|
||||
frappe.throw(_('e-Way Bill JSON cannot be generated for Sales Return as of now'))
|
||||
|
||||
if doc.ewaybill:
|
||||
frappe.throw(_('e-Way Bill already exists for this document'))
|
||||
|
||||
reqd_fields = ['company_gstin', 'company_address', 'customer_address',
|
||||
'shipping_address_name', 'mode_of_transport', 'distance']
|
||||
|
||||
for fieldname in reqd_fields:
|
||||
if not doc.get(fieldname):
|
||||
frappe.throw(_('{} is required to generate e-Way Bill JSON'.format(
|
||||
doc.meta.get_label(fieldname)
|
||||
)))
|
||||
|
||||
if len(doc.company_gstin) < 15:
|
||||
frappe.throw(_('You must be a registered supplier to generate e-Way Bill'))
|
||||
|
||||
def get_transport_details(data, doc):
|
||||
if doc.distance > 4000:
|
||||
frappe.throw(_('Distance cannot be greater than 4000 kms'))
|
||||
|
||||
data.transDistance = int(round(doc.distance))
|
||||
|
||||
transport_modes = {
|
||||
'Road': 1,
|
||||
'Rail': 2,
|
||||
'Air': 3,
|
||||
'Ship': 4
|
||||
}
|
||||
|
||||
vehicle_types = {
|
||||
'Regular': 'R',
|
||||
'Over Dimensional Cargo (ODC)': 'O'
|
||||
}
|
||||
|
||||
data.transMode = transport_modes.get(doc.mode_of_transport)
|
||||
|
||||
if doc.mode_of_transport == 'Road':
|
||||
if not doc.gst_transporter_id and not doc.vehicle_no:
|
||||
frappe.throw(_('Either GST Transporter ID or Vehicle No is required if Mode of Transport is Road'))
|
||||
if doc.vehicle_no:
|
||||
data.vehicleNo = doc.vehicle_no.replace(' ', '')
|
||||
if not doc.gst_vehicle_type:
|
||||
frappe.throw(_('Vehicle Type is required if Mode of Transport is Road'))
|
||||
else:
|
||||
data.vehicleType = vehicle_types.get(doc.gst_vehicle_type)
|
||||
else:
|
||||
if not doc.lr_no or not doc.lr_date:
|
||||
frappe.throw(_('Transport Receipt No and Date are mandatory for your chosen Mode of Transport'))
|
||||
|
||||
if doc.lr_no:
|
||||
data.transDocNo = doc.lr_no
|
||||
|
||||
if doc.lr_date:
|
||||
data.transDocDate = frappe.utils.formatdate(doc.lr_date, 'dd/mm/yyyy')
|
||||
|
||||
if doc.gst_transporter_id:
|
||||
validate_gstin_check_digit(doc.gst_transporter_id, label='GST Transporter ID')
|
||||
data.transporterId = doc.gst_transporter_id
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def validate_pincode(pincode, address):
|
||||
pin_not_found = "Pin Code doesn't exist for {}"
|
||||
incorrect_pin = "Pin Code for {} is incorrecty formatted. It must be 6 digits (without spaces)"
|
||||
|
||||
if not pincode:
|
||||
frappe.throw(_(pin_not_found.format(address)))
|
||||
|
||||
pincode = pincode.replace(' ', '')
|
||||
if not pincode.isdigit() or len(pincode) != 6:
|
||||
frappe.throw(_(incorrect_pin.format(address)))
|
||||
else:
|
||||
return int(pincode)
|
||||
|
||||
def validate_state_code(state_code, address):
|
||||
no_state_code = "GST State Code not found for {0}. Please set GST State in {0}"
|
||||
if not state_code:
|
||||
frappe.throw(_(no_state_code.format(address)))
|
||||
else:
|
||||
return int(state_code)
|
||||
|
||||
def get_gst_accounts(company, account_wise=False):
|
||||
gst_accounts = frappe._dict()
|
||||
gst_settings_accounts = frappe.get_all("GST Account",
|
||||
filters={"parent": "GST Settings", "company": company},
|
||||
fields=["cgst_account", "sgst_account", "igst_account", "cess_account"])
|
||||
|
||||
if not gst_settings_accounts:
|
||||
frappe.throw(_("Please set GST Accounts in GST Settings"))
|
||||
|
||||
for d in gst_settings_accounts:
|
||||
for acc, val in d.items():
|
||||
if not account_wise:
|
||||
gst_accounts.setdefault(acc, []).append(val)
|
||||
elif val:
|
||||
gst_accounts[val] = acc
|
||||
|
||||
|
||||
return gst_accounts
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
<DatiGenerali>
|
||||
<DatiGeneraliDocumento>
|
||||
<TipoDocumento>{{ doc.type_of_document }}</TipoDocumento>
|
||||
<Divisa>EUR</Divisa>
|
||||
<Divisa>{{ doc.currency }}</Divisa>
|
||||
<Data>{{ doc.posting_date }}</Data>
|
||||
<Numero>{{ doc.unamended_name }}</Numero>
|
||||
{%- if doc.stamp_duty %}
|
||||
|
||||
@@ -80,7 +80,7 @@ def prepare_invoice(invoice, progressive_number):
|
||||
invoice.stamp_duty = stamp_duty_charge_row.tax_amount
|
||||
|
||||
for item in invoice.e_invoice_items:
|
||||
if item.tax_rate == 0.0 and item.tax_amount == 0.0:
|
||||
if item.tax_rate == 0.0 and item.tax_amount == 0.0 and tax_data.get("0.0"):
|
||||
item.tax_exemption_reason = tax_data["0.0"]["tax_exemption_reason"]
|
||||
|
||||
customer_po_data = {}
|
||||
|
||||
@@ -80,7 +80,10 @@ def get_gl_entries(filters):
|
||||
jnl.cheque_no as JnlRef, jnl.posting_date as JnlPostDate, jnl.title as JnlTitle,
|
||||
pay.name as PayName, pay.posting_date as PayPostDate, pay.title as PayTitle,
|
||||
cus.customer_name, cus.name as cusName,
|
||||
sup.supplier_name, sup.name as supName
|
||||
sup.supplier_name, sup.name as supName,
|
||||
emp.employee_name, emp.name as empName,
|
||||
stu.title as student_name, stu.name as stuName,
|
||||
member_name, mem.name as memName
|
||||
|
||||
from `tabGL Entry` gl
|
||||
left join `tabSales Invoice` inv on gl.voucher_no = inv.name
|
||||
@@ -89,6 +92,9 @@ def get_gl_entries(filters):
|
||||
left join `tabPayment Entry` pay on gl.voucher_no = pay.name
|
||||
left join `tabCustomer` cus on gl.party = cus.name
|
||||
left join `tabSupplier` sup on gl.party = sup.name
|
||||
left join `tabEmployee` emp on gl.party = emp.name
|
||||
left join `tabStudent` stu on gl.party = stu.name
|
||||
left join `tabMember` mem on gl.party = mem.name
|
||||
where gl.company=%(company)s and gl.fiscal_year=%(fiscal_year)s
|
||||
{group_by_condition}
|
||||
order by GlPostDate, voucher_no"""\
|
||||
@@ -128,6 +134,18 @@ def get_result_as_list(data, filters):
|
||||
CompAuxNum = d.get("supName")
|
||||
CompAuxLib = d.get("supplier_name")
|
||||
|
||||
elif d.get("party_type") == "Employee":
|
||||
CompAuxNum = d.get("empName")
|
||||
CompAuxLib = d.get("employee_name")
|
||||
|
||||
elif d.get("party_type") == "Student":
|
||||
CompAuxNum = d.get("stuName")
|
||||
CompAuxLib = d.get("student_name")
|
||||
|
||||
elif d.get("party_type") == "Member":
|
||||
CompAuxNum = d.get("memName")
|
||||
CompAuxLib = d.get("member_name")
|
||||
|
||||
else:
|
||||
CompAuxNum = ""
|
||||
CompAuxLib = ""
|
||||
|
||||
@@ -8,6 +8,7 @@ from frappe.utils import flt, formatdate, now_datetime, getdate
|
||||
from datetime import date
|
||||
from six import iteritems
|
||||
from erpnext.regional.doctype.gstr_3b_report.gstr_3b_report import get_period
|
||||
from erpnext.regional.india.utils import get_gst_accounts
|
||||
|
||||
def execute(filters=None):
|
||||
return Gstr1Report(filters).run()
|
||||
@@ -29,10 +30,9 @@ class Gstr1Report(object):
|
||||
place_of_supply,
|
||||
ecommerce_gstin,
|
||||
reverse_charge,
|
||||
invoice_type,
|
||||
return_against,
|
||||
is_return,
|
||||
invoice_type,
|
||||
gst_category,
|
||||
export_type,
|
||||
port_code,
|
||||
shipping_bill_number,
|
||||
@@ -42,7 +42,7 @@ class Gstr1Report(object):
|
||||
|
||||
def run(self):
|
||||
self.get_columns()
|
||||
self.get_gst_accounts()
|
||||
self.gst_accounts = get_gst_accounts(self.filters.company)
|
||||
self.get_invoice_data()
|
||||
|
||||
if self.invoices:
|
||||
@@ -54,7 +54,6 @@ class Gstr1Report(object):
|
||||
return self.columns, self.data
|
||||
|
||||
def get_data(self):
|
||||
|
||||
if self.filters.get("type_of_business") == "B2C Small":
|
||||
self.get_b2cs_data()
|
||||
else:
|
||||
@@ -266,19 +265,6 @@ class Gstr1Report(object):
|
||||
and frappe.db.get_value(self.doctype, invoice, "export_type") == "Without Payment of Tax":
|
||||
self.items_based_on_tax_rate.setdefault(invoice, {}).setdefault(0, items.keys())
|
||||
|
||||
def get_gst_accounts(self):
|
||||
self.gst_accounts = frappe._dict()
|
||||
gst_settings_accounts = frappe.get_all("GST Account",
|
||||
filters={"parent": "GST Settings", "company": self.filters.company},
|
||||
fields=["cgst_account", "sgst_account", "igst_account", "cess_account"])
|
||||
|
||||
if not gst_settings_accounts:
|
||||
frappe.throw(_("Please set GST Accounts in GST Settings"))
|
||||
|
||||
for d in gst_settings_accounts:
|
||||
for acc, val in d.items():
|
||||
self.gst_accounts.setdefault(acc, []).append(val)
|
||||
|
||||
def get_columns(self):
|
||||
self.tax_columns = [
|
||||
{
|
||||
@@ -594,7 +580,7 @@ def get_json():
|
||||
download_json_file(report_name, filters["type_of_business"], gst_json)
|
||||
|
||||
def get_b2b_json(res, gstin):
|
||||
inv_type, out = {"Regular": "R", "Deemed Export": "DE", "URD": "URD", "SEZ": "SEZ"}, []
|
||||
inv_type, out = {"Registered Regular": "R", "Deemed Export": "DE", "URD": "URD", "SEZ": "SEZ"}, []
|
||||
for gst_in in res:
|
||||
b2b_item, inv = {"ctin": gst_in, "inv": []}, []
|
||||
if not gst_in: continue
|
||||
@@ -603,7 +589,7 @@ def get_b2b_json(res, gstin):
|
||||
inv_item = get_basic_invoice_detail(invoice[0])
|
||||
inv_item["pos"] = "%02d" % int(invoice[0]["place_of_supply"].split('-')[0])
|
||||
inv_item["rchrg"] = invoice[0]["reverse_charge"]
|
||||
inv_item["inv_typ"] = inv_type.get(invoice[0].get("invoice_type", ""),"")
|
||||
inv_item["inv_typ"] = inv_type.get(invoice[0].get("gst_category", ""),"")
|
||||
|
||||
if inv_item["pos"]=="00": continue
|
||||
inv_item["itms"] = []
|
||||
|
||||
Reference in New Issue
Block a user