Basic functionality

This commit is contained in:
Christian Anetzberger
2022-01-12 17:24:52 +01:00
parent 0324fdce13
commit 808af357ab
15 changed files with 423 additions and 20 deletions

View File

@@ -14,7 +14,7 @@ app_license = "MIT"
# include js, css files in header of desk.html # include js, css files in header of desk.html
# app_include_css = "/assets/manufacturing_overview/css/manufacturing_overview.css" # app_include_css = "/assets/manufacturing_overview/css/manufacturing_overview.css"
# app_include_js = "/assets/manufacturing_overview/js/manufacturing_overview.js" app_include_js = "/assets/manufacturing_overview/js/manufacturing_overview.min.js"
# include js, css files in header of web template # include js, css files in header of web template
# web_include_css = "/assets/manufacturing_overview/css/manufacturing_overview.css" # web_include_css = "/assets/manufacturing_overview/css/manufacturing_overview.css"
@@ -152,24 +152,24 @@ app_license = "MIT"
# -------------------- # --------------------
user_data_fields = [ user_data_fields = [
{ {
"doctype": "{doctype_1}", "doctype": "{doctype_1}",
"filter_by": "{filter_by}", "filter_by": "{filter_by}",
"redact_fields": ["{field_1}", "{field_2}"], "redact_fields": ["{field_1}", "{field_2}"],
"partial": 1, "partial": 1,
}, },
{ {
"doctype": "{doctype_2}", "doctype": "{doctype_2}",
"filter_by": "{filter_by}", "filter_by": "{filter_by}",
"partial": 1, "partial": 1,
}, },
{ {
"doctype": "{doctype_3}", "doctype": "{doctype_3}",
"strict": False, "strict": False,
}, },
{ {
"doctype": "{doctype_4}" "doctype": "{doctype_4}"
} }
] ]
# Authentication and authorization # Authentication and authorization
@@ -178,4 +178,3 @@ user_data_fields = [
# auth_hooks = [ # auth_hooks = [
# "manufacturing_overview.auth.validate" # "manufacturing_overview.auth.validate"
# ] # ]

View File

@@ -0,0 +1,118 @@
import frappe
from functools import reduce
from datetime import date
def clearCache(doc, event):
frappe.cache().delete_value("production_overview")
@frappe.whitelist()
def getUserPermissions():
return frappe.get_doc('Production Overview User Mapping', frappe.session.user)
def formatDate(d):
return frappe.utils.formatdate(
d, 'dd.MM.yyyy')
def getDueInDays(d):
delta = d - date.today()
return delta.days
def getWorkOrders(soname):
return frappe.get_all("Work Order", filters={
'sales_order': soname}, fields=['name'])
def getAmountInWarehouses(item_code):
bins = frappe.get_all("Bin", fields=["actual_qty"], filters=[
["actual_qty", ">", 0], ["item_code", "=", item_code]])
return reduce(lambda x, y: x + y,
map(lambda b: b["actual_qty"], bins), 0)
def shortenCustomerName(customer):
shortName = frappe.get_value(
'Customer', customer, 'short_name')
if shortName is not None:
return shortName
else:
return customer
def calculateSalesOrderStatus(item, warehouseamount, workorders):
if item.delivered_qty >= item.qty:
return "Fully Delivered"
elif item.delivered_qty < item.qty and item.delivered_qty > 0:
return "Partially Delivered"
elif item.qty <= warehouseamount:
return "In Warehouse"
elif len(workorders) <= 0:
return "No Work Order"
elif len(workorders) > 0 and item.qty > warehouseamount:
return "To Produce"
else:
return "Unknown"
def generateProductionOverviewCache():
salesOrderItems = frappe.db.sql(
"""
SELECT
`tabSales Order Item`.name,
`tabSales Order Item`.item_name,
`tabSales Order Item`.item_group,
`tabSales Order Item`.qty,
`tabSales Order Item`.actual_qty,
`tabSales Order Item`.delivered_qty,
`tabSales Order Item`.delivery_date,
`tabSales Order Item`.item_code,
`tabSales Order Item`.parent,
`tabSales Order`.status as parentStatus
FROM
`tabSales Order Item`
INNER JOIN `tabSales Order`
ON
`tabSales Order Item`.parent = `tabSales Order`.name
WHERE
delivered_qty < qty and
status = 'To Deliver and Bill' and
item_group = "Produkte"
ORDER BY
delivery_date
""", as_dict=1)
for soItem in salesOrderItems:
soItem.due_in = getDueInDays(soItem.delivery_date)
soItem.customer = shortenCustomerName(frappe.get_value(
'Sales Order', soItem.parent, 'customer'))
soItem.wos = frappe.get_all('Work Order', filters=[
['sales_order', '=', soItem.parent], ['production_item', '=', soItem.item_code], ['status', '!=', "Cancelled"]])
soItem.delivery_date = formatDate(soItem.delivery_date)
soItem.warehouseamount = getAmountInWarehouses(soItem.item_code)
if soItem.warehouseamount >= soItem.qty:
soItem.status = 'In Warehouse'
elif len(soItem.wos) != 0:
soItem.status = 'To Produce'
else:
soItem.status = 'No Work Order'
soItem.qty = soItem.qty - soItem.delivered_qty
soItem.link = '/desk#Form/Sales%20Order/' + soItem.parent
frappe.cache().set_value("production_overview", salesOrderItems)
@frappe.whitelist()
def getSalesorderOverviewList():
salesOrderItems = frappe.cache().get_value(
"production_overview", generateProductionOverviewCache())
return salesOrderItems

View File

@@ -0,0 +1,8 @@
// Copyright (c) 2022, CAnetzberger Design and contributors
// For license information, please see license.txt
frappe.ui.form.on('Dummy', {
// refresh: function(frm) {
// }
});

View File

@@ -0,0 +1,40 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2022-01-12 12:55:48.605579",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"section_break_1"
],
"fields": [
{
"fieldname": "section_break_1",
"fieldtype": "Section Break"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-01-12 12:55:48.605579",
"modified_by": "Administrator",
"module": "Manufacturing Overview",
"name": "Dummy",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC"
}

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2022, CAnetzberger Design and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document
class Dummy(Document):
pass

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2022, CAnetzberger Design and Contributors
# See license.txt
# import frappe
import unittest
class TestDummy(unittest.TestCase):
pass

View File

@@ -0,0 +1,34 @@
{
"category": "Modules",
"charts": [],
"creation": "2022-01-12 12:54:01.312334",
"developer_mode_only": 0,
"disable_user_customization": 0,
"docstatus": 0,
"doctype": "Workspace",
"extends_another_page": 0,
"hide_custom": 0,
"idx": 0,
"is_default": 0,
"is_standard": 1,
"label": "Manufacturing Overview",
"links": [
{
"hidden": 0,
"is_query_report": 0,
"label": "Work Order",
"link_to": "Work Order",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
}
],
"modified": "2022-01-12 12:54:14.538048",
"modified_by": "Administrator",
"module": "Manufacturing Overview",
"name": "Manufacturing Overview",
"owner": "Administrator",
"pin_to_bottom": 0,
"pin_to_top": 0,
"shortcuts": []
}

View File

@@ -0,0 +1,5 @@
{
"manufacturing_overview/js/manufacturing_overview.min.js": [
"public/js/manufacturing_overview_page.js"
]
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"version":3,"file":"manufacturing_overview.min.js","sources":["../../../../apps/manufacturing_overview/manufacturing_overview/public/js/manufacturing_overview_row.vue?rollup-plugin-vue=script.js","../../../../apps/manufacturing_overview/manufacturing_overview/public/js/manufacturing_overview_desk.vue?rollup-plugin-vue=script.js","../../../../apps/manufacturing_overview/manufacturing_overview/public/js/manufacturing_overview_page.js"],"sourcesContent":["//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nexport default {\n name: \"ManufacturingOverviewRow\",\n props: [\n \"qty\",\n \"item_name\",\n \"item_code\",\n \"customer\",\n \"delivery_date\",\n \"status\",\n \"link\",\n \"reference\",\n \"due_in\",\n ],\n methods: {},\n};\n","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nimport ManufacturingOverviewRow from \"./manufacturing_overview_row.vue\";\n\nexport default {\n components: {\n ManufacturingOverviewRow,\n },\n data() {\n return {\n salesorderData: [\n {\n customer: \"\",\n delivery_date: \"\",\n link: \"\",\n name: \"\",\n item_name: \"Loading...\",\n item_code: \"\",\n qty: \"\",\n sales_order: \"\",\n status: \"Unknown\",\n due_in: 0,\n },\n ],\n timer: \"\",\n origin: window.location.origin,\n userPermissions: {},\n };\n },\n created() {\n this.fetchEventsList();\n this.timer = setInterval(this.fetchEventsList, 30000);\n },\n methods: {\n fetchEventsList() {\n let self = this;\n frappe.call({\n method:\n \"manufacturing_overview.manufacturing_overview.api.getSalesorderOverviewList\",\n async: true,\n args: {},\n callback: function (r) {\n if (r.message) {\n self.salesorderData = r.message;\n }\n },\n });\n },\n cancelAutoUpdate() {\n clearInterval(this.timer);\n },\n beforeDestroy() {\n clearInterval(this.timer);\n },\n },\n};\n","import ManufacturingOverviewDesk from \"./manufacturing_overview_desk.vue\";\n\n$(document).ready(function () {\n $(\".layout-main-section-wrapper\").after('<div class=\"col-4 layout-main-section-wrapper\" id=\"manufacturing-overview-body\"></div>');\n var pod = new Vue({\n el: \"#manufacturing-overview-body\",\n render(h) {\n return h(ManufacturingOverviewDesk, {});\n }\n });\n});"],"names":["name","props","methods","components","data","salesorderData","customer","delivery_date","link","item_name","item_code","qty","sales_order","status","due_in","timer","origin","window","location","userPermissions","created","this","fetchEventsList","setInterval","let","self","frappe","call","method","async","args","callback","r","message","cancelAutoUpdate","clearInterval","beforeDestroy","$","document","ready","after","Vue","el","render","h","ManufacturingOverviewDesk"],"mappings":"+BA6De,CACbA,KAAM,2BACNC,MAAO,CACL,MACA,YACA,YACA,WACA,gBACA,SACA,OACA,YACA,UAEFC,QAAS,umDCzCI,CACbC,WAAY,68DAGZC,gBACE,MAAO,CACLC,eAAgB,CACd,CACEC,SAAU,GACVC,cAAe,GACfC,KAAM,GACNR,KAAM,GACNS,UAAW,aACXC,UAAW,GACXC,IAAK,GACLC,YAAa,GACbC,OAAQ,UACRC,OAAQ,IAGZC,MAAO,GACPC,OAAQC,OAAOC,SAASF,OACxBG,gBAAiB,KAGrBC,mBACEC,KAAKC,kBACLD,KAAKN,MAAQQ,YAAYF,KAAKC,gBAAiB,MAEjDpB,QAAS,CACPoB,2BACEE,IAAIC,EAAOJ,KACXK,OAAOC,KAAK,CACVC,OACE,8EACFC,OAAO,EACPC,KAAM,GACNC,SAAU,SAAUC,GACdA,EAAEC,UACJR,EAAKpB,eAAiB2B,EAAEC,aAKhCC,4BACEC,cAAcd,KAAKN,QAErBqB,yBACED,cAAcd,KAAKN,myFC/EzBsB,EAAEC,UAAUC,MAAM,WACdF,EAAE,gCAAgCG,MAAM,0FAC9B,IAAIC,IAAI,CACdC,GAAI,+BACJC,gBAAOC,GACH,OAAOA,EAAEC,EAA2B"}

View File

@@ -0,0 +1,89 @@
<template>
<div class="col-4 layout-main-section-wrapper">
<div class="widget-group">
<div class="widget-group-head">
<div class="widget-group-title">Manufacturing Overview</div>
<div class="widget-group-control"></div>
</div>
<div class="widget-group-body">
<div class="widget links-widget-box">
<manufacturing-overview-row
v-for="so in salesorderData"
:key="so.name"
v-bind:qty="so.qty"
v-bind:item_name="so.item_name"
v-bind:item_code="so.item_code"
v-bind:customer="so.customer"
v-bind:delivery_date="so.delivery_date"
v-bind:status="so.status"
v-bind:link="so.link"
v-bind:reference="so.parent"
v-bind:due_in="so.due_in"
>
>
</manufacturing-overview-row>
</div>
</div>
</div>
</div>
</template>
<script>
import ManufacturingOverviewRow from "./manufacturing_overview_row.vue";
export default {
components: {
ManufacturingOverviewRow,
},
data() {
return {
salesorderData: [
{
customer: "",
delivery_date: "",
link: "",
name: "",
item_name: "Loading...",
item_code: "",
qty: "",
sales_order: "",
status: "Unknown",
due_in: 0,
},
],
timer: "",
origin: window.location.origin,
userPermissions: {},
};
},
created() {
this.fetchEventsList();
this.timer = setInterval(this.fetchEventsList, 30000);
},
methods: {
fetchEventsList() {
let self = this;
frappe.call({
method:
"manufacturing_overview.manufacturing_overview.api.getSalesorderOverviewList",
async: true,
args: {},
callback: function (r) {
if (r.message) {
self.salesorderData = r.message;
}
},
});
},
cancelAutoUpdate() {
clearInterval(this.timer);
},
beforeDestroy() {
clearInterval(this.timer);
},
},
};
</script>
<style>
</style>

View File

@@ -0,0 +1,11 @@
import ManufacturingOverviewDesk from "./manufacturing_overview_desk.vue";
$(document).ready(function () {
$(".layout-main-section-wrapper").after('<div class="col-4 layout-main-section-wrapper" id="manufacturing-overview-body"></div>');
var pod = new Vue({
el: "#manufacturing-overview-body",
render(h) {
return h(ManufacturingOverviewDesk, {});
}
});
});

View File

@@ -0,0 +1,80 @@
<template>
<a :href="link" class="link-item">
<div class="container-fluid">
<div class="row no-gutter">
<div class="col col-xs-8">
<span
class="indicator-pill no-margin"
v-bind:class="{
red: status === 'No Work Order',
blue: status === 'Fully Delivered',
'light-blue': status === 'Partially Delivered',
green: status === 'In Warehouse',
orange: status === 'To Produce',
grey: status === 'Unknown',
}"
></span>
<span class="widget-subtitle">{{ qty }}</span> -
<span class="widget-title">{{ item_name }}</span>
<div>
<small v-if="customer && item_code" class="color-secondary"
>{{ customer }} -
<a :href="'/desk#Form/Item/' + item_code">{{
item_code
}}</a></small
>
<small v-else-if="customer" class="color-secondary">{{
customer
}}</small>
<small v-else-if="item_code" class="color-secondary">{{
item_code
}}</small>
</div>
<div>
<small class="color-secondary">{{ reference }}</small>
</div>
</div>
<div
v-if="due_in < 0"
class="text-muted ellipsis color-secondary col col-xs-4 text-right"
>
<b style="color: red">{{ delivery_date }}</b>
</div>
<div
v-else-if="due_in === 0"
class="text-muted ellipsis color-secondary col col-xs-4 text-right"
>
<b style="color: black">{{ delivery_date }}</b>
</div>
<div
v-else
class="text-muted ellipsis color-secondary col col-xs-4 text-right"
>
{{ delivery_date }}
</div>
</div>
</div>
</a>
</template>
<script>
export default {
name: "ManufacturingOverviewRow",
props: [
"qty",
"item_name",
"item_code",
"customer",
"delivery_date",
"status",
"link",
"reference",
"due_in",
],
methods: {},
};
</script>
<style>
</style>