Merge pull request #23127 from marination/quoted-item-report-v2
feat: Quoted Item Comparison Report Enhancements v2
This commit is contained in:
commit
37cb44e109
@ -12,7 +12,22 @@ frappe.query_reports["Quoted Item Comparison"] = {
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reqd: 1,
|
"fieldname":"from_date",
|
||||||
|
"label": __("From Date"),
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"width": "80",
|
||||||
|
"reqd": 1,
|
||||||
|
"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"to_date",
|
||||||
|
"label": __("To Date"),
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"width": "80",
|
||||||
|
"reqd": 1,
|
||||||
|
"default": frappe.datetime.get_today()
|
||||||
|
},
|
||||||
|
{
|
||||||
default: "",
|
default: "",
|
||||||
options: "Item",
|
options: "Item",
|
||||||
label: __("Item"),
|
label: __("Item"),
|
||||||
@ -45,13 +60,12 @@ frappe.query_reports["Quoted Item Comparison"] = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldtype: "Link",
|
fieldtype: "MultiSelectList",
|
||||||
label: __("Supplier Quotation"),
|
label: __("Supplier Quotation"),
|
||||||
options: "Supplier Quotation",
|
|
||||||
fieldname: "supplier_quotation",
|
fieldname: "supplier_quotation",
|
||||||
default: "",
|
default: "",
|
||||||
get_query: () => {
|
get_data: function(txt) {
|
||||||
return { filters: { "docstatus": ["<", 2] } }
|
return frappe.db.get_link_options('Supplier Quotation', txt, {'docstatus': ["<", 2]});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -63,9 +77,30 @@ frappe.query_reports["Quoted Item Comparison"] = {
|
|||||||
get_query: () => {
|
get_query: () => {
|
||||||
return { filters: { "docstatus": ["<", 2] } }
|
return { filters: { "docstatus": ["<", 2] } }
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldtype: "Check",
|
||||||
|
label: __("Include Expired"),
|
||||||
|
fieldname: "include_expired",
|
||||||
|
default: 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
formatter: (value, row, column, data, default_formatter) => {
|
||||||
|
value = default_formatter(value, row, column, data);
|
||||||
|
|
||||||
|
if(column.fieldname === "valid_till" && data.valid_till){
|
||||||
|
if(frappe.datetime.get_diff(data.valid_till, frappe.datetime.nowdate()) <= 1){
|
||||||
|
value = `<div style="color:red">${value}</div>`;
|
||||||
|
}
|
||||||
|
else if (frappe.datetime.get_diff(data.valid_till, frappe.datetime.nowdate()) <= 7){
|
||||||
|
value = `<div style="color:darkorange">${value}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
onload: (report) => {
|
onload: (report) => {
|
||||||
// Create a button for setting the default supplier
|
// Create a button for setting the default supplier
|
||||||
report.page.add_inner_button(__("Select Default Supplier"), () => {
|
report.page.add_inner_button(__("Select Default Supplier"), () => {
|
||||||
|
|||||||
@ -16,44 +16,49 @@ def execute(filters=None):
|
|||||||
supplier_quotation_data = get_data(filters, conditions)
|
supplier_quotation_data = get_data(filters, conditions)
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
|
|
||||||
data, chart_data = prepare_data(supplier_quotation_data)
|
data, chart_data = prepare_data(supplier_quotation_data, filters)
|
||||||
|
message = get_message()
|
||||||
|
|
||||||
return columns, data, None, chart_data
|
return columns, data, message, chart_data
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_conditions(filters):
|
||||||
conditions = ""
|
conditions = ""
|
||||||
|
if filters.get("item_code"):
|
||||||
|
conditions += " AND sqi.item_code = %(item_code)s"
|
||||||
|
|
||||||
if filters.get("supplier_quotation"):
|
if filters.get("supplier_quotation"):
|
||||||
conditions += " AND sqi.parent = %(supplier_quotation)s"
|
conditions += " AND sqi.parent in %(supplier_quotation)s"
|
||||||
|
|
||||||
if filters.get("request_for_quotation"):
|
if filters.get("request_for_quotation"):
|
||||||
conditions += " AND sqi.request_for_quotation = %(request_for_quotation)s"
|
conditions += " AND sqi.request_for_quotation = %(request_for_quotation)s"
|
||||||
|
|
||||||
if filters.get("supplier"):
|
if filters.get("supplier"):
|
||||||
conditions += " AND sq.supplier in %(supplier)s"
|
conditions += " AND sq.supplier in %(supplier)s"
|
||||||
|
|
||||||
|
if not filters.get("include_expired"):
|
||||||
|
conditions += " AND sq.status != 'Expired'"
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
def get_data(filters, conditions):
|
def get_data(filters, conditions):
|
||||||
if not filters.get("item_code"):
|
|
||||||
return []
|
|
||||||
|
|
||||||
supplier_quotation_data = frappe.db.sql("""SELECT
|
supplier_quotation_data = frappe.db.sql("""SELECT
|
||||||
sqi.parent, sqi.qty, sqi.rate, sqi.uom, sqi.request_for_quotation,
|
sqi.parent, sqi.item_code, sqi.qty, sqi.rate, sqi.uom, sqi.request_for_quotation,
|
||||||
sq.supplier
|
sqi.lead_time_days, sq.supplier, sq.valid_till
|
||||||
FROM
|
FROM
|
||||||
`tabSupplier Quotation Item` sqi,
|
`tabSupplier Quotation Item` sqi,
|
||||||
`tabSupplier Quotation` sq
|
`tabSupplier Quotation` sq
|
||||||
WHERE
|
WHERE
|
||||||
sqi.item_code = %(item_code)s
|
sqi.parent = sq.name
|
||||||
AND sqi.parent = sq.name
|
|
||||||
AND sqi.docstatus < 2
|
AND sqi.docstatus < 2
|
||||||
AND sq.company = %(company)s
|
AND sq.company = %(company)s
|
||||||
AND sq.status != 'Expired'
|
AND sq.transaction_date between %(from_date)s and %(to_date)s
|
||||||
{0}""".format(conditions), filters, as_dict=1)
|
{0}
|
||||||
|
order by sq.transaction_date, sqi.item_code""".format(conditions), filters, as_dict=1)
|
||||||
|
|
||||||
return supplier_quotation_data
|
return supplier_quotation_data
|
||||||
|
|
||||||
def prepare_data(supplier_quotation_data):
|
def prepare_data(supplier_quotation_data, filters):
|
||||||
out, suppliers, qty_list = [], [], []
|
out, suppliers, qty_list, chart_data = [], [], [], []
|
||||||
supplier_wise_map = defaultdict(list)
|
supplier_wise_map = defaultdict(list)
|
||||||
supplier_qty_price_map = {}
|
supplier_qty_price_map = {}
|
||||||
|
|
||||||
@ -70,20 +75,24 @@ def prepare_data(supplier_quotation_data):
|
|||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
|
|
||||||
row = {
|
row = {
|
||||||
|
"item_code": data.get('item_code'),
|
||||||
"quotation": data.get("parent"),
|
"quotation": data.get("parent"),
|
||||||
"qty": data.get("qty"),
|
"qty": data.get("qty"),
|
||||||
"price": flt(data.get("rate") * exchange_rate, float_precision),
|
"price": flt(data.get("rate") * exchange_rate, float_precision),
|
||||||
"uom": data.get("uom"),
|
"uom": data.get("uom"),
|
||||||
"request_for_quotation": data.get("request_for_quotation"),
|
"request_for_quotation": data.get("request_for_quotation"),
|
||||||
|
"valid_till": data.get('valid_till'),
|
||||||
|
"lead_time_days": data.get('lead_time_days')
|
||||||
}
|
}
|
||||||
|
|
||||||
# map for report view of form {'supplier1':[{},{},...]}
|
# map for report view of form {'supplier1':[{},{},...]}
|
||||||
supplier_wise_map[supplier].append(row)
|
supplier_wise_map[supplier].append(row)
|
||||||
|
|
||||||
# map for chart preparation of the form {'supplier1': {'qty': 'price'}}
|
# map for chart preparation of the form {'supplier1': {'qty': 'price'}}
|
||||||
if not supplier in supplier_qty_price_map:
|
if filters.get("item_code"):
|
||||||
supplier_qty_price_map[supplier] = {}
|
if not supplier in supplier_qty_price_map:
|
||||||
supplier_qty_price_map[supplier][row["qty"]] = row["price"]
|
supplier_qty_price_map[supplier] = {}
|
||||||
|
supplier_qty_price_map[supplier][row["qty"]] = row["price"]
|
||||||
|
|
||||||
suppliers.append(supplier)
|
suppliers.append(supplier)
|
||||||
qty_list.append(data.get("qty"))
|
qty_list.append(data.get("qty"))
|
||||||
@ -97,7 +106,8 @@ def prepare_data(supplier_quotation_data):
|
|||||||
for entry in supplier_wise_map[supplier]:
|
for entry in supplier_wise_map[supplier]:
|
||||||
out.append(entry)
|
out.append(entry)
|
||||||
|
|
||||||
chart_data = prepare_chart_data(suppliers, qty_list, supplier_qty_price_map)
|
if filters.get("item_code"):
|
||||||
|
chart_data = prepare_chart_data(suppliers, qty_list, supplier_qty_price_map)
|
||||||
|
|
||||||
return out, chart_data
|
return out, chart_data
|
||||||
|
|
||||||
@ -117,9 +127,10 @@ def prepare_chart_data(suppliers, qty_list, supplier_qty_price_map):
|
|||||||
data_points_map[qty].append(None)
|
data_points_map[qty].append(None)
|
||||||
|
|
||||||
dataset = []
|
dataset = []
|
||||||
|
currency_symbol = frappe.db.get_value("Currency", frappe.db.get_default("currency"), "symbol")
|
||||||
for qty in qty_list:
|
for qty in qty_list:
|
||||||
datapoints = {
|
datapoints = {
|
||||||
"name": _("Price for Qty ") + str(qty),
|
"name": currency_symbol + " (Qty " + str(qty) + " )",
|
||||||
"values": data_points_map[qty]
|
"values": data_points_map[qty]
|
||||||
}
|
}
|
||||||
dataset.append(datapoints)
|
dataset.append(datapoints)
|
||||||
@ -140,14 +151,21 @@ def get_columns():
|
|||||||
"label": _("Supplier"),
|
"label": _("Supplier"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Supplier",
|
"options": "Supplier",
|
||||||
|
"width": 150
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "item_code",
|
||||||
|
"label": _("Item"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Item",
|
||||||
"width": 200
|
"width": 200
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "quotation",
|
"fieldname": "uom",
|
||||||
"label": _("Supplier Quotation"),
|
"label": _("UOM"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Supplier Quotation",
|
"options": "UOM",
|
||||||
"width": 200
|
"width": 90
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "qty",
|
"fieldname": "qty",
|
||||||
@ -163,19 +181,43 @@ def get_columns():
|
|||||||
"width": 110
|
"width": 110
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "uom",
|
"fieldname": "quotation",
|
||||||
"label": _("UOM"),
|
"label": _("Supplier Quotation"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "UOM",
|
"options": "Supplier Quotation",
|
||||||
"width": 90
|
"width": 200
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "valid_till",
|
||||||
|
"label": _("Valid Till"),
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"width": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "lead_time_days",
|
||||||
|
"label": _("Lead Time (Days)"),
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"width": 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "request_for_quotation",
|
"fieldname": "request_for_quotation",
|
||||||
"label": _("Request for Quotation"),
|
"label": _("Request for Quotation"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Request for Quotation",
|
"options": "Request for Quotation",
|
||||||
"width": 200
|
"width": 150
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
|
def get_message():
|
||||||
|
return """<span class="indicator">
|
||||||
|
Valid till :
|
||||||
|
</span>
|
||||||
|
<span class="indicator orange">
|
||||||
|
Expires in a week or less
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span class="indicator red">
|
||||||
|
Expires today / Already Expired
|
||||||
|
</span>"""
|
||||||
Loading…
x
Reference in New Issue
Block a user