Skip to content

Commit

Permalink
feat: wip pick list tool
Browse files Browse the repository at this point in the history
  • Loading branch information
fproldan committed Oct 13, 2023
1 parent 836c70d commit 484fbf6
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) 2023, AgriTheory and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.query_reports['Pick List Tool'] = {
filters: [
{
fieldname: 'company',
label: __('Company'),
fieldtype: 'Link',
options: 'Company',
default: frappe.defaults.get_user_default('Company'),
reqd: 1,
},
{
fieldname: 'status',
label: __('Status'),
fieldtype: 'Select',
options: ['', 'Already Picked', 'Not Picked', 'Unshipped'],
},
{
fieldname: 'delivery_date_start',
label: __('Delivery Date (start)'),
fieldtype: 'Date',
},
{
fieldname: 'delivery_date_end',
label: __('Delivery Date (end)'),
fieldtype: 'Date',
},
{
fieldname: 'warehouse',
label: __('Warehouse'),
fieldtype: 'MultiSelectList',
options: 'Warehouse',
get_data: function (txt) {
return frappe.db.get_link_options('Warehouse', txt, {
company: frappe.query_report.get_filter_value('company'),
})
},
},
{
fieldname: 'customer',
label: __('Customer'),
fieldtype: 'Link',
options: 'Customer',
},
],
formatter: function (value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data)
if (column.fieldname == 'sales_order' && data && data.sales_order) {
value = value.bold()
} else if (column.fieldname == 'picked_percentage' && data && data.picked_percentage) {
if (data.picked_percentage == 100) {
value = "<span style='color:green'>" + value + '</span>'
} else {
value = "<span style='color:red'>" + value + '</span>'
}
}
return value
},
onload: report => {
report.page.add_button('Check Stock', () => {
check_stock()
})
report.page.add_button('Print Pick', () => {
print_pick()
})
report.page.add_inner_button(__('Pick List'), function () {}, __('Create'))
report.page.add_inner_button(__('Pick List & Delivery Note'), function () {}, __('Create'))
},
}

function check_stock() {}
function print_pick() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"add_total_row": 0,
"columns": [],
"creation": "2023-10-13 08:52:27.178388",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"modified": "2023-10-13 08:52:27.178388",
"modified_by": "Administrator",
"module": "Inventory Tools",
"name": "Pick List Tool",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Pick List",
"report_name": "Pick List Tool",
"report_type": "Script Report",
"roles": [
{
"role": "Stock Manager"
},
{
"role": "Stock User"
},
{
"role": "Manufacturing Manager"
},
{
"role": "Manufacturing User"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright (c) 2023, AgriTheory and contributors
# For license information, please see license.txt
from itertools import groupby

import frappe
from frappe.query_builder import DocType


def execute(filters=None):
SalesOrder = DocType("Sales Order")
SalesOrderItem = DocType("Sales Order Item")
query = (
frappe.qb.from_(SalesOrder)
.join(SalesOrderItem)
.on(SalesOrder.name == SalesOrderItem.parent)
.select(
SalesOrder.name.as_("sales_order"),
SalesOrderItem.item_code,
SalesOrderItem.warehouse,
SalesOrderItem.delivery_date,
SalesOrderItem.qty.as_("so_qty"),
)
.where(SalesOrder.docstatus == 1)
.where(SalesOrder.company == filters.company)
)

if filters.customer:
query = query.where(SalesOrder.customer == filters.customer)
if filters.delivery_date_start:
query = query.where(SalesOrderItem.delivery_date >= filters.delivery_date_start)
if filters.delivery_date_end:
query = query.where(SalesOrderItem.delivery_date <= filters.delivery_date_end)
if filters.warehouse:
query = query.where(SalesOrderItem.warehouse.isin(filters.warehouse))

data = query.run(as_dict=1)

output = []

for sales_order, _rows in groupby(data, lambda x: x.get("sales_order")):
output.append({"sales_order": sales_order, "indent": 0, "picked_percentage": "100"})
for row in _rows:
del row["sales_order"]
output.append({**row, "indent": 1})

return get_columns(), output


def get_columns():
return [
{
"fieldname": "sales_order",
"fieldtype": "Link",
"options": "Sales Order",
"label": "Sales Order",
"width": "200px",
},
{
"fieldname": "item_code",
"fieldtype": "Link",
"options": "Item",
"label": "Item",
"width": "250px",
},
{
"fieldname": "warehouse",
"fieldtype": "Link",
"options": "Warehouse",
"label": "Warehouse",
"width": "250px",
},
{
"fieldname": "so_qty",
"label": "SO Qty",
"fieldtype": "Data",
},
{
"fieldname": "delivery_date",
"label": "Delivery Date",
"fieldtype": "Date",
"width": "120px",
},
{
"fieldname": "picked_percentage",
"label": "% Picked",
"fieldtype": "Data",
"width": "100px",
},
{
"fieldname": "total_stock",
"fieldtype": "Data",
"label": "Total Stock",
"width": "120px",
},
]

0 comments on commit 484fbf6

Please sign in to comment.