Created Eway Bill Report (#14926)

* Created Eway Bill Report

* Field value changes

* Changed module from Stock to Regional

* Added comments and minor fix

* minor fix
This commit is contained in:
FinByz Tech Pvt. Ltd 2018-07-27 11:21:42 +05:30 committed by Nabin Hait
parent cc56ff5c37
commit f5cc1bd44c
5 changed files with 633 additions and 31 deletions

View File

@ -0,0 +1,33 @@
// Copyright (c) 2016, FinByz Tech Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */
frappe.query_reports["Eway Bill"] = {
"filters": [
{
'fieldname': 'delivery_note',
'label': __("Delivery Note"),
'fieldtype': 'Link',
'options': 'Delivery Note'
},
{
'fieldname': 'posting_date',
'label': __("Date"),
'fieldtype': 'DateRange',
'default': [frappe.datetime.nowdate(), frappe.datetime.nowdate()]
},
{
'fieldname': 'customer',
'label': __("Customer"),
'fieldtype': 'Link',
'options': 'Customer'
},
{
"fieldname":"company",
"label": __("Company"),
"fieldtype": "Link",
"options": "Company",
"default": frappe.defaults.get_user_default("Company")
},
]
}

View File

@ -0,0 +1,32 @@
{
"add_total_row": 0,
"apply_user_permissions": 1,
"creation": "2018-07-13 19:59:18.922829",
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"modified": "2018-07-19 12:08:07.400295",
"modified_by": "Administrator",
"module": "Regional",
"name": "Eway Bill",
"owner": "Administrator",
"ref_doctype": "Delivery Note",
"report_name": "Eway Bill",
"report_type": "Script Report",
"roles": [
{
"role": "Stock User"
},
{
"role": "Stock Manager"
},
{
"role": "Sales User"
},
{
"role": "Accounts User"
}
]
}

View File

@ -0,0 +1,385 @@
# Copyright (c) 2013, FinByz Tech Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
import json
import re
from frappe import _
from frappe.utils import nowdate
def execute(filters=None):
if not filters: filters.setdefault('posting_date', [nowdate(), nowdate()])
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
conditions = get_conditions(filters)
data = frappe.db.sql("""
SELECT
dn.name as dn_id, dn.posting_date, dn.company, dn.company_gstin, dn.customer, dn.customer_gstin, dni.item_code, dni.item_name, dni.description, dni.gst_hsn_code, dni.uom, dni.qty, dni.amount, dn.transport_mode, dn.distance, dn.transporter_name, dn.transporter, dn.lr_no, dn.lr_date, dn.vehicle_no, dn.vehicle_type, dn.company_address, dn.shipping_address_name
FROM
`tabDelivery Note` AS dn join `tabDelivery Note Item` AS dni on (dni.parent = dn.name)
WHERE
dn.docstatus < 2
%s """ % conditions, as_dict=1)
unit = {
'Bag': "BAGS",
'Bottle': "BOTTLES",
'Kg': "KILOGRAMS",
'Liter': "LITERS",
'Meter': "METERS",
'Nos': "NUMBERS",
'PKT': "PACKS",
'Roll': "ROLLS",
'Set': "SETS"
}
# Regular expression set to remove all the special characters
special_characters = "[$%^*()+\\[\]{};':\"\\|<>.?]"
for row in data:
set_defaults(row)
set_taxes(row, filters)
set_address_details(row, special_characters)
# Eway Bill accepts date as dd/mm/yyyy and not dd-mm-yyyy
row.posting_date = '/'.join(str(row.posting_date).replace("-", "/").split('/')[::-1])
row.lr_date = '/'.join(str(row.lr_date).replace("-", "/").split('/')[::-1])
row.item_name = re.sub(special_characters, " ", row.item_name)
row.description = row.item_name
row.uom = unit.get(row.uom, row.uom)
# For removing special charactes and numbers from customer.
row.customer = re.sub(special_characters[:-1] + "&0-9" + "]", "", row.customer)
return data
def get_conditions(filters):
conditions = ""
conditions += filters.get('company') and " AND dn.company = '%s' " % filters.get('company') or ""
conditions += filters.get('posting_date') and " AND dn.posting_date >= '%s' AND dn.posting_date <= '%s' " % (filters.get('posting_date')[0], filters.get('posting_date')[1]) or ""
conditions += filters.get('delivery_note') and " AND dn.name = '%s' " % filters.get('delivery_note') or ""
conditions += filters.get('customer') and " AND dn.customer = '%s' " % filters.get('customer').replace("'", "\'") or ""
return conditions
def set_defaults(row):
row.setdefault(u'supply_type', "Outward")
row.setdefault(u'sub_type', "Supply")
row.setdefault(u'doc_type', "Delivery Challan")
def set_address_details(row, special_characters):
if row.get('company_address'):
address_line1, address_line2, city, pincode, state = frappe.db.get_value("Address", row.get('company_address'), ['address_line1', 'address_line2', 'city', 'pincode', 'state'])
row.update({'from_address_1': re.sub(special_characters, "", address_line1 or '')})
row.update({'from_address_2': re.sub(special_characters, "", address_line2 or '')})
row.update({'from_place': city and city.upper() or ''})
row.update({'from_pin_code': pincode and pincode.replace(" ", "") or ''})
row.update({'from_state': state and state.upper() or ''})
row.update({'dispatch_state': row.from_state})
if row.get('shipping_address_name'):
address_line1, address_line2, city, pincode, state = frappe.db.get_value("Address", row.get('shipping_address_name'), ['address_line1', 'address_line2', 'city', 'pincode', 'state'])
row.update({'to_address_1': re.sub(special_characters, "", address_line1 or '')})
row.update({'to_address_2': re.sub(special_characters, "", address_line2 or '')})
row.update({'to_place': city and city.upper() or ''})
row.update({'to_pin_code': pincode and pincode.replace(" ", "") or ''})
row.update({'to_state': state and state.upper() or ''})
row.update({'ship_to_state': row.to_state})
def set_taxes(row, filters):
taxes = frappe.get_list("Sales Taxes and Charges",
filters={
'parent': row.dn_id
},
fields=('item_wise_tax_detail', 'account_head'))
account_list = ["cgst_account", "sgst_account", "igst_account", "cess_account"]
taxes_list = frappe.get_list("GST Account",
filters={
"parent": "GST Settings",
"company": filters.company
},
fields=account_list)
item_tax_rate = {}
for tax in taxes:
item_wise_tax = json.loads(tax.item_wise_tax_detail)
item_tax_rate[tax.account_head] = item_wise_tax.get(row.item_code)
tax_rate = []
tax = taxes_list[0]
for key in account_list:
if tax[key] not in item_tax_rate.keys():
item_tax_rate[tax[key]] = [0.0, 0.0]
tax_rate.append(str(item_tax_rate[tax[key]][0]))
row.update({key[:5] + "amount": round(item_tax_rate.get(tax[key], 0.0)[1], 2)})
item_tax_rate.pop(tax[key])
row.amount = float(row.amount) + sum(i[1] for i in item_tax_rate.values())
row.update({'tax_rate': '+'.join(tax_rate)})
def get_columns():
columns = [
{
"fieldname": "supply_type",
"label": _("Supply Type"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "sub_type",
"label": _("Sub Type"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "doc_type",
"label": _("Doc Type"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "dn_id",
"label": _("Doc Name"),
"fieldtype": "Link",
"options": "Delivery Note",
"width": 140
},
{
"fieldname": "posting_date",
"label": _("Doc Date"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "company",
"label": _("From Party Name"),
"fieldtype": "Link",
"options": "Company",
"width": 120
},
{
"fieldname": "company_gstin",
"label": _("From GSTIN"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "from_address_1",
"label": _("From Address 1"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "from_address_2",
"label": _("From Address 2"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "from_place",
"label": _("From Place"),
"fieldtype": "Data",
"width": 80
},
{
"fieldname": "from_pin_code",
"label": _("From Pin Code"),
"fieldtype": "Data",
"width": 80
},
{
"fieldname": "from_state",
"label": _("From State"),
"fieldtype": "Data",
"width": 80
},
{
"fieldname": "dispatch_state",
"label": _("Dispatch State"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "customer",
"label": _("To Party Name"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "customer_gstin",
"label": _("To GSTIN"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "to_address_1",
"label": _("To Address 1"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "to_address_2",
"label": _("To Address 2"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "to_place",
"label": _("To Place"),
"fieldtype": "Data",
"width": 80
},
{
"fieldname": "to_pin_code",
"label": _("To Pin Code"),
"fieldtype": "Data",
"width": 80
},
{
"fieldname": "to_state",
"label": _("To State"),
"fieldtype": "Data",
"width": 80
},
{
"fieldname": "ship_to_state",
"label": _("Ship To State"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "item_name",
"label": _("Product"),
"fieldtype": "Link",
"options": "Item",
"width": 120
},
{
"fieldname": "description",
"label": _("Description"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "gst_hsn_code",
"label": _("HSN"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "uom",
"label": _("Unit"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "qty",
"label": _("Qty"),
"fieldtype": "Float",
"width": 100
},
{
"fieldname": "amount",
"label": _("Accessable Value"),
"fieldtype": "Float",
"width": 120
},
{
"fieldname": "tax_rate",
"label": _("Tax Rate"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "cgst_amount",
"label": _("CGST Amount"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "sgst_amount",
"label": _("SGST Amount"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "igst_amount",
"label": _("IGST Amount"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "cess_amount",
"label": _("CESS Amount"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "transport_mode",
"label": _("Transport Mode"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "distance",
"label": _("Distance"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "transporter_name",
"label": _("Transporter Name"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "transporter_id",
"label": _("Transporter ID"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "lr_no",
"label": _("Transporter Doc No"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "lr_date",
"label": _("Transporter Date"),
"fieldtype": "Data",
"width": 120
},
{
"fieldname": "vehicle_no",
"label": _("Vehicle No"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "vehicle_type",
"label": _("Vehicle Type"),
"fieldtype": "Data",
"width": 100
},
]
return columns

View File

@ -2587,6 +2587,36 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "transporter",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Transporter ID",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2620,6 +2650,67 @@
"unique": 0,
"width": "150px"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "transport_mode",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Transport Mode",
"length": 0,
"no_copy": 0,
"options": "\nRoad\nAir\nRail\nShip",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "distance",
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Distance (KM)",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2650,6 +2741,67 @@
"unique": 0,
"width": "50%"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "vehicle_no",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Vehicle No",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "vehicle_type",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Vehicle Type",
"length": 0,
"no_copy": 0,
"options": "\nRegular\nODC",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2666,7 +2818,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Vehicle No",
"label": "Transporter Doc No",
"length": 0,
"no_copy": 0,
"oldfieldname": "lr_no",
@ -2701,7 +2853,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Vehicle Dispatch Date",
"label": "Transporter Date",
"length": 0,
"no_copy": 0,
"oldfieldname": "lr_date",
@ -3157,36 +3309,36 @@
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "group_same_items",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Group same items",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "group_same_items",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Group same items",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
},
{
"allow_bulk_edit": 0,
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
@ -3731,7 +3883,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2018-07-06 03:03:35.035396",
"modified": "2018-07-19 11:53:03.807829",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note",