-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Alternative workstation in job card and operation (#56)
* feat: New field and link filters to select alternative workstation * fix: add alternativ workstation in fixture * fix:change alternative workstation in fixture * change to error key function * fix: set validation on workstation if not operation * changes field name in testcase * fix: change a class base function to saperate function * added a searchfield in query * added a searchfield in query * added a searchfield in query * added a searchfield in query * added a searchfield in query * feat: validation to not allow default workstation in alternative * added comment on function
- Loading branch information
1 parent
d1e126b
commit 0788d3c
Showing
11 changed files
with
269 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"custom_fields": [ | ||
{ | ||
"_assign": null, | ||
"_comments": null, | ||
"_liked_by": null, | ||
"_user_tags": null, | ||
"allow_in_quick_entry": 0, | ||
"allow_on_submit": 0, | ||
"bold": 0, | ||
"collapsible": 0, | ||
"collapsible_depends_on": null, | ||
"columns": 0, | ||
"creation": "2024-02-16 05:04:42.422068", | ||
"default": null, | ||
"depends_on": null, | ||
"description": null, | ||
"docstatus": 0, | ||
"dt": "Operation", | ||
"fetch_from": null, | ||
"fetch_if_empty": 0, | ||
"fieldname": "alternative_workstations", | ||
"fieldtype": "Table MultiSelect", | ||
"hidden": 0, | ||
"hide_border": 0, | ||
"hide_days": 0, | ||
"hide_seconds": 0, | ||
"idx": 1, | ||
"ignore_user_permissions": 0, | ||
"ignore_xss_filter": 0, | ||
"in_global_search": 0, | ||
"in_list_view": 0, | ||
"in_preview": 0, | ||
"in_standard_filter": 0, | ||
"insert_after": "workstation", | ||
"is_system_generated": 0, | ||
"is_virtual": 0, | ||
"label": "Alternative Workstations", | ||
"length": 0, | ||
"mandatory_depends_on": null, | ||
"modified": "2024-02-16 05:04:42.422068", | ||
"modified_by": "Administrator", | ||
"module": "Inventory Tools", | ||
"name": "Operation-alternative_workstations", | ||
"no_copy": 0, | ||
"non_negative": 0, | ||
"options": "Alternative Workstations", | ||
"owner": "Administrator", | ||
"permlevel": 0, | ||
"precision": "", | ||
"print_hide": 0, | ||
"print_hide_if_no_value": 0, | ||
"print_width": null, | ||
"read_only": 0, | ||
"read_only_depends_on": null, | ||
"report_hide": 0, | ||
"reqd": 0, | ||
"search_index": 0, | ||
"sort_options": 0, | ||
"translatable": 0, | ||
"unique": 0, | ||
"width": null | ||
} | ||
], | ||
"custom_perms": [], | ||
"doctype": "Operation", | ||
"links": [], | ||
"property_setters": [], | ||
"sync_on_migrate": 1 | ||
} |
32 changes: 32 additions & 0 deletions
32
...tory_tools/inventory_tools/doctype/alternative_workstations/alternative_workstations.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"creation": "2024-02-01 04:03:58.033322", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"workstation" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "workstation", | ||
"fieldtype": "Link", | ||
"in_list_view": 1, | ||
"label": "Workstation", | ||
"options": "Workstation" | ||
} | ||
], | ||
"index_web_pages_for_search": 1, | ||
"istable": 1, | ||
"links": [], | ||
"modified": "2024-02-01 07:04:30.059469", | ||
"modified_by": "Administrator", | ||
"module": "Inventory Tools", | ||
"name": "Alternative Workstations", | ||
"owner": "Administrator", | ||
"permissions": [], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
9 changes: 9 additions & 0 deletions
9
inventory_tools/inventory_tools/doctype/alternative_workstations/alternative_workstations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024, AgriTheory and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
|
||
class AlternativeWorkstations(Document): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import frappe | ||
|
||
|
||
def validate_alternative_workstation(self, method): | ||
if self.workstation: | ||
for row in self.alternative_workstations: | ||
if row.workstation == self.workstation: | ||
frappe.throw("Default Workstation should not be selected as alternative workstation") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import json | ||
|
||
import frappe | ||
|
||
""" | ||
This function fetch workstation of the document operation. | ||
In Operation you can select multiple workstations in Alternative Workstation field. | ||
In the Work Order, Operation table, and Jobcard, there exists an operation field. | ||
When selecting an operation, this function is responsible for fetching the workstations | ||
both from the Alternative Workstation and the default workstation. | ||
Example : Operation : Cool Pie Op | ||
Default Workstation: Cooling Racks Station | ||
Alternative Workstation: | ||
````````````````````````````````````````````````````` | ||
: Cooling Station , Refrigerator Station , : | ||
: : | ||
: : | ||
`````````````````````````````````````````````````````` | ||
In work order and job card when you select operation Cool Pie Op then you find below workstation in workstation field | ||
: Cooling Station : | ||
: Refrigerator Station : | ||
: Cooling Racks Station : | ||
""" | ||
|
||
|
||
@frappe.whitelist() | ||
@frappe.validate_and_sanitize_search_inputs | ||
def get_alternative_workstations(doctype, txt, searchfield, start, page_len, filters): | ||
operation = filters.get("operation") | ||
if not operation: | ||
frappe.throw("Please select a Operation first.") | ||
|
||
if txt: | ||
searchfields = frappe.get_meta(doctype).get_search_fields() | ||
searchfields = " or ".join(["ws." + field + f" LIKE '%{txt}%'" for field in searchfields]) | ||
|
||
conditions = "" | ||
if txt and searchfields: | ||
conditions = f"and ({searchfields})" | ||
|
||
workstation = frappe.db.sql( | ||
""" | ||
Select aw.workstation, ws.workstation_type, ws.description | ||
From `tabOperation` as op | ||
Left Join `tabAlternative Workstations` as aw ON aw.parent = op.name | ||
Left Join `tabWorkstation` as ws ON ws.name = aw.workstation | ||
Where op.name = '{operation}' {conditions} | ||
""".format( | ||
conditions=conditions, operation=operation | ||
) | ||
) | ||
|
||
default_workstation = frappe.db.get_value("Operation", operation, "workstation") | ||
flag = True | ||
for row in workstation: | ||
if row[0] == None: | ||
workstation = ((default_workstation,),) | ||
flag = False | ||
if flag: | ||
workstation += ((default_workstation,),) | ||
return workstation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
frappe.ui.form.on('Job Card', { | ||
refresh: frm => { | ||
if (frm.doc.operation) { | ||
set_workstation_query(frm) | ||
} | ||
}, | ||
operation: frm => { | ||
set_workstation_query(frm) | ||
}, | ||
}) | ||
|
||
function set_workstation_query(frm) { | ||
frm.set_query('workstation', doc => { | ||
return { | ||
query: 'inventory_tools.inventory_tools.overrides.workstation.get_alternative_workstations', | ||
filters: { | ||
operation: doc.operation, | ||
}, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
frappe.ui.form.on('Operation', { | ||
refresh: frm => { | ||
get_filter_workstations(frm) | ||
}, | ||
workstation: frm => { | ||
get_filter_workstations(frm) | ||
}, | ||
}) | ||
|
||
function get_filter_workstations(frm) { | ||
cur_frm.fields_dict.alternative_workstations.get_query = function (doc) { | ||
return { | ||
filters: { | ||
workstation_name: ['!=', frm.doc.workstation], | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters