mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
fix: Code cleanup and fixes
This commit is contained in:
@@ -32,7 +32,7 @@ frappe.ui.form.on("Sales Invoice", {
|
|||||||
if (!w) {
|
if (!w) {
|
||||||
frappe.msgprint(__("Please enable pop-ups")); return;
|
frappe.msgprint(__("Please enable pop-ups")); return;
|
||||||
}
|
}
|
||||||
});
|
}, __("Make"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ execute:frappe.delete_doc_if_exists("Page", "sales-analytics")
|
|||||||
execute:frappe.delete_doc_if_exists("Page", "purchase-analytics")
|
execute:frappe.delete_doc_if_exists("Page", "purchase-analytics")
|
||||||
execute:frappe.delete_doc_if_exists("Page", "stock-analytics")
|
execute:frappe.delete_doc_if_exists("Page", "stock-analytics")
|
||||||
execute:frappe.delete_doc_if_exists("Page", "production-analytics")
|
execute:frappe.delete_doc_if_exists("Page", "production-analytics")
|
||||||
erpnext.patches.v11_0.ewaybill_fields_gst_india #2018-11-13 #2019-01-09 #2019-04-01
|
erpnext.patches.v11_0.ewaybill_fields_gst_india #2018-11-13 #2019-01-09 #2019-04-01 #2019-05-03
|
||||||
erpnext.patches.v11_0.drop_column_max_days_allowed
|
erpnext.patches.v11_0.drop_column_max_days_allowed
|
||||||
erpnext.patches.v11_0.change_healthcare_desktop_icons
|
erpnext.patches.v11_0.change_healthcare_desktop_icons
|
||||||
erpnext.patches.v10_0.update_user_image_in_employee
|
erpnext.patches.v10_0.update_user_image_in_employee
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ def make_custom_fields(update=True):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
|
create_custom_fields(custom_fields, update=update)
|
||||||
|
|
||||||
def make_fixtures(company=None):
|
def make_fixtures(company=None):
|
||||||
docs = []
|
docs = []
|
||||||
|
|||||||
@@ -244,8 +244,7 @@ def calculate_hra_exemption_for_period(doc):
|
|||||||
return exemptions
|
return exemptions
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
def get_ewb_data(dt, dn):
|
||||||
def generate_ewb_json(dt, dn):
|
|
||||||
if dt != 'Sales Invoice':
|
if dt != 'Sales Invoice':
|
||||||
frappe.throw(_('e-Way Bill JSON can only be generated from Sales Invoice'))
|
frappe.throw(_('e-Way Bill JSON can only be generated from Sales Invoice'))
|
||||||
|
|
||||||
@@ -254,26 +253,8 @@ def generate_ewb_json(dt, dn):
|
|||||||
ewaybills = []
|
ewaybills = []
|
||||||
for doc_name in dn:
|
for doc_name in dn:
|
||||||
doc = frappe.get_doc(dt, doc_name)
|
doc = frappe.get_doc(dt, doc_name)
|
||||||
if doc.docstatus != 1:
|
|
||||||
frappe.throw(_('e-Way Bill JSON can only be generated from submitted document'))
|
|
||||||
|
|
||||||
if doc.is_return:
|
validate_sales_invoice(doc)
|
||||||
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'))
|
|
||||||
|
|
||||||
data = frappe._dict({
|
data = frappe._dict({
|
||||||
"transporterId": "",
|
"transporterId": "",
|
||||||
@@ -294,11 +275,77 @@ def generate_ewb_json(dt, dn):
|
|||||||
data.docDate = frappe.utils.formatdate(doc.posting_date, 'dd/mm/yyyy')
|
data.docDate = frappe.utils.formatdate(doc.posting_date, 'dd/mm/yyyy')
|
||||||
|
|
||||||
company_address = frappe.get_doc('Address', doc.company_address)
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
def get_address_details(data, doc, company_address, billing_address):
|
||||||
data.fromPincode = validate_pincode(company_address.pincode, 'Company Address')
|
data.fromPincode = validate_pincode(company_address.pincode, 'Company Address')
|
||||||
data.fromStateCode = data.actualFromStateCode = validate_state_code(
|
data.fromStateCode = data.actualFromStateCode = validate_state_code(
|
||||||
company_address.gst_state_number, 'Company Address')
|
company_address.gst_state_number, 'Company Address')
|
||||||
|
|
||||||
billing_address = frappe.get_doc('Address', doc.customer_address)
|
|
||||||
if not doc.billing_address_gstin or len(doc.billing_address_gstin) < 15:
|
if not doc.billing_address_gstin or len(doc.billing_address_gstin) < 15:
|
||||||
data.toGstin = 'URP'
|
data.toGstin = 'URP'
|
||||||
set_gst_state_and_state_number(billing_address)
|
set_gst_state_and_state_number(billing_address)
|
||||||
@@ -318,8 +365,9 @@ def generate_ewb_json(dt, dn):
|
|||||||
data.actualToStateCode = data.toStateCode
|
data.actualToStateCode = data.toStateCode
|
||||||
shipping_address = billing_address
|
shipping_address = billing_address
|
||||||
|
|
||||||
data.itemList = []
|
return data
|
||||||
data.totalValue = doc.total
|
|
||||||
|
def get_item_list(data, doc):
|
||||||
for attr in ['cgstValue', 'sgstValue', 'igstValue', 'cessValue', 'OthValue']:
|
for attr in ['cgstValue', 'sgstValue', 'igstValue', 'cessValue', 'OthValue']:
|
||||||
data[attr] = 0
|
data[attr] = 0
|
||||||
|
|
||||||
@@ -354,9 +402,31 @@ def generate_ewb_json(dt, dn):
|
|||||||
|
|
||||||
data.itemList.append(item_data)
|
data.itemList.append(item_data)
|
||||||
|
|
||||||
disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total')
|
return data
|
||||||
data.totInvValue = doc.grand_total if disable_rounded else doc.rounded_total
|
|
||||||
|
|
||||||
|
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:
|
if doc.distance > 4000:
|
||||||
frappe.throw(_('Distance cannot be greater than 4000 kms'))
|
frappe.throw(_('Distance cannot be greater than 4000 kms'))
|
||||||
|
|
||||||
@@ -399,45 +469,8 @@ def generate_ewb_json(dt, dn):
|
|||||||
validate_gstin_check_digit(doc.gst_transporter_id, label='GST Transporter ID')
|
validate_gstin_check_digit(doc.gst_transporter_id, label='GST Transporter ID')
|
||||||
data.transporterId = doc.gst_transporter_id
|
data.transporterId = doc.gst_transporter_id
|
||||||
|
|
||||||
fields = {
|
return data
|
||||||
"/. -": {
|
|
||||||
'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
|
|
||||||
}
|
|
||||||
|
|
||||||
frappe.local.response.filecontent = json.dumps(data, indent=4, sort_keys=True)
|
|
||||||
frappe.local.response.type = 'download'
|
|
||||||
|
|
||||||
if len(ewaybills) > 1:
|
|
||||||
doc_name = 'Bulk'
|
|
||||||
|
|
||||||
frappe.local.response.filename = '{0}_e-WayBill_Data_{1}.json'.format(doc_name, frappe.utils.random_string(5))
|
|
||||||
|
|
||||||
def validate_pincode(pincode, address):
|
def validate_pincode(pincode, address):
|
||||||
pin_not_found = "Pin Code doesn't exist for {}"
|
pin_not_found = "Pin Code doesn't exist for {}"
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class Gstr1Report(object):
|
|||||||
for inv, items_based_on_rate in self.items_based_on_tax_rate.items():
|
for inv, items_based_on_rate in self.items_based_on_tax_rate.items():
|
||||||
invoice_details = self.invoices.get(inv)
|
invoice_details = self.invoices.get(inv)
|
||||||
for rate, items in items_based_on_rate.items():
|
for rate, items in items_based_on_rate.items():
|
||||||
row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
|
row = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
|
||||||
|
|
||||||
if self.filters.get("type_of_business") == "CDNR":
|
if self.filters.get("type_of_business") == "CDNR":
|
||||||
row.append("Y" if invoice_details.posting_date <= date(2017, 7, 1) else "N")
|
row.append("Y" if invoice_details.posting_date <= date(2017, 7, 1) else "N")
|
||||||
|
|||||||
Reference in New Issue
Block a user