Basic functionality

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

No files matched your search

+19 -20
View File
@@ -14,7 +14,7 @@ app_license = "MIT"
# include js, css files in header of desk.html
# 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
# web_include_css = "/assets/manufacturing_overview/css/manufacturing_overview.css"
@@ -152,24 +152,24 @@ app_license = "MIT"
# --------------------
user_data_fields = [
{
"doctype": "{doctype_1}",
"filter_by": "{filter_by}",
"redact_fields": ["{field_1}", "{field_2}"],
"partial": 1,
},
{
"doctype": "{doctype_2}",
"filter_by": "{filter_by}",
"partial": 1,
},
{
"doctype": "{doctype_3}",
"strict": False,
},
{
"doctype": "{doctype_4}"
}
{
"doctype": "{doctype_1}",
"filter_by": "{filter_by}",
"redact_fields": ["{field_1}", "{field_2}"],
"partial": 1,
},
{
"doctype": "{doctype_2}",
"filter_by": "{filter_by}",
"partial": 1,
},
{
"doctype": "{doctype_3}",
"strict": False,
},
{
"doctype": "{doctype_4}"
}
]
# Authentication and authorization
@@ -178,4 +178,3 @@ user_data_fields = [
# auth_hooks = [
# "manufacturing_overview.auth.validate"
# ]
@@ -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
Whitespace-only changes.
Whitespace-only changes.
@@ -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) {
// }
});
@@ -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"
}
@@ -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
@@ -0,0 +1,8 @@
# Copyright (c) 2022, CAnetzberger Design and Contributors
# See license.txt
# import frappe
import unittest
class TestDummy(unittest.TestCase):
pass
@@ -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": []
}
+5
View File
@@ -0,0 +1,5 @@
{
"manufacturing_overview/js/manufacturing_overview.min.js": [
"public/js/manufacturing_overview_page.js"
]
}
@@ -0,0 +1,2 @@
!function(){"use strict";var e={name:"ManufacturingOverviewRow",props:["qty","item_name","item_code","customer","delivery_date","status","link","reference","due_in"],methods:{}},n=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("a",{staticClass:"link-item",attrs:{href:e.link}},[t("div",{staticClass:"container-fluid"},[t("div",{staticClass:"row no-gutter"},[t("div",{staticClass:"col col-xs-8"},[t("span",{staticClass:"indicator-pill no-margin",class:{red:"No Work Order"===e.status,blue:"Fully Delivered"===e.status,"light-blue":"Partially Delivered"===e.status,green:"In Warehouse"===e.status,orange:"To Produce"===e.status,grey:"Unknown"===e.status}}),e._v(" "),t("span",{staticClass:"widget-subtitle"},[e._v(e._s(e.qty))]),e._v(" -\n "),t("span",{staticClass:"widget-title"},[e._v(e._s(e.item_name))]),e._v(" "),t("div",[e.customer&&e.item_code?t("small",{staticClass:"color-secondary"},[e._v(e._s(e.customer)+" -\n "),t("a",{attrs:{href:"/desk#Form/Item/"+e.item_code}},[e._v(e._s(e.item_code))])]):e.customer?t("small",{staticClass:"color-secondary"},[e._v(e._s(e.customer))]):e.item_code?t("small",{staticClass:"color-secondary"},[e._v(e._s(e.item_code))]):e._e()]),e._v(" "),t("div",[t("small",{staticClass:"color-secondary"},[e._v(e._s(e.reference))])])]),e._v(" "),e.due_in<0?t("div",{staticClass:"text-muted ellipsis color-secondary col col-xs-4 text-right"},[t("b",{staticStyle:{color:"red"}},[e._v(e._s(e.delivery_date))])]):0===e.due_in?t("div",{staticClass:"text-muted ellipsis color-secondary col col-xs-4 text-right"},[t("b",{staticStyle:{color:"black"}},[e._v(e._s(e.delivery_date))])]):t("div",{staticClass:"text-muted ellipsis color-secondary col col-xs-4 text-right"},[e._v("\n "+e._s(e.delivery_date)+"\n ")])])])])};n._withStripped=!0;var t={components:{ManufacturingOverviewRow:function(e,n,t,i,a,s,r,o){var d,l=("function"==typeof t?t.options:t)||{};if(l.__file="/Volumes/development/frappe/frappe-bench/apps/manufacturing_overview/manufacturing_overview/public/js/manufacturing_overview_row.vue",l.render||(l.render=e.render,l.staticRenderFns=e.staticRenderFns,l._compiled=!0,a&&(l.functional=!0)),l._scopeId=i,n&&(d=function(e){n.call(this,r(e))}),void 0!==d)if(l.functional){var c=l.render;l.render=function(e,n){return d.call(n),c(e,n)}}else{var u=l.beforeCreate;l.beforeCreate=u?[].concat(u,d):[d]}return l}({render:n,staticRenderFns:[]},function(e){e&&e("data-v-2d7a0cce_0",{source:"\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",map:{version:3,sources:[],names:[],mappings:"",file:"manufacturing_overview_row.vue"},media:void 0})},e,void 0,!1,0,function e(){var n=document.head||document.getElementsByTagName("head")[0],t=e.styles||(e.styles={}),i="undefined"!=typeof navigator&&/msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());return function(e,a){if(!document.querySelector('style[data-vue-ssr-id~="'+e+'"]')){var s=i?a.media||"default":e,r=t[s]||(t[s]={ids:[],parts:[],element:void 0});if(!r.ids.includes(e)){var o=a.source,d=r.ids.length;if(r.ids.push(e),i&&(r.element=r.element||document.querySelector("style[data-group="+s+"]")),!r.element){var l=r.element=document.createElement("style");l.type="text/css",a.media&&l.setAttribute("media",a.media),i&&(l.setAttribute("data-group",s),l.setAttribute("data-next-index","0")),n.appendChild(l)}if(i&&(d=parseInt(r.element.getAttribute("data-next-index")),r.element.setAttribute("data-next-index",d+1)),r.element.styleSheet)r.parts.push(o),r.element.styleSheet.cssText=r.parts.filter(Boolean).join("\n");else{var c=document.createTextNode(o),u=r.element.childNodes;u[d]&&r.element.removeChild(u[d]),u.length?r.element.insertBefore(c,u[d]):r.element.appendChild(c)}}}}})},data:function(){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:function(){this.fetchEventsList(),this.timer=setInterval(this.fetchEventsList,3e4)},methods:{fetchEventsList:function(){var e=this;frappe.call({method:"manufacturing_overview.manufacturing_overview.api.getSalesorderOverviewList",async:!0,args:{},callback:function(n){n.message&&(e.salesorderData=n.message)}})},cancelAutoUpdate:function(){clearInterval(this.timer)},beforeDestroy:function(){clearInterval(this.timer)}}},i=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("div",{staticClass:"col-4 layout-main-section-wrapper"},[t("div",{staticClass:"widget-group"},[e._m(0),e._v(" "),t("div",{staticClass:"widget-group-body"},[t("div",{staticClass:"widget links-widget-box"},e._l(e.salesorderData,function(n){return t("manufacturing-overview-row",{key:n.name,attrs:{qty:n.qty,item_name:n.item_name,item_code:n.item_code,customer:n.customer,delivery_date:n.delivery_date,status:n.status,link:n.link,reference:n.parent,due_Line truncated
//# sourceMappingURL=manufacturing_overview.min.js.map
@@ -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"}
@@ -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>
@@ -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, {});
}
});
});
@@ -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>