Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Modified manufacturing request doctype #414

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"fieldname": "design",
"fieldtype": "Attach",
"in_list_view": 1,
"label": "Design"
"label": "Design",
"reqd": 1
},
{
"fieldname": "purity",
Expand Down Expand Up @@ -136,7 +137,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-05-27 09:55:08.735772",
"modified": "2024-07-03 15:06:17.196932",
"modified_by": "Administrator",
"module": "AuMMS Manufacturing",
"name": "Customer Jewellery Order Detail",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
// Copyright (c) 2024, efeone and contributors
// For license information, please see license.txt

frappe.ui.form.on("Jewellery Job Card", {
refresh: function(frm){
refresh: function(frm) {
create_custom_buttons(frm);
calculate_total_weight(frm);

// Remove 'Start' button if the document is submitted
if (frm.doc.docstatus === 1) {
frm.remove_custom_button('Start');
}
}
frm.set_df_property("duration", "read_only", 1);
frm.set_df_property("job_time", "read_only",frm.doc.__islocal ? 0 : 1);
},
frm.set_df_property("job_time", "read_only", frm.doc.__islocal ? 0 : 1);

// if (frm.doc.status === ["Open", "Processing", "Hold"]) {
// frm.page.clear_primary_action();
// }
// },
if (["Open", "Processing", "Hold"].includes(frm.doc.status)) {
frm.disable_save();
}
},
onload: function(frm) {
frm.get_field('item_details').grid.cannot_add_rows = true;
}
});

let create_custom_buttons = function(frm){
if (frm.doc.status == "Open") {
let create_custom_buttons = function(frm) {
// Clear existing custom buttons to avoid duplicates
frm.clear_custom_buttons();

// Add buttons based on the status of the document
if (frm.doc.status === "Open") {
frm.add_custom_button('Start', () => {
frm.set_value("status", "Processing");
updateStartTime(frm);
frm.save();
frm.page.set_primary_action(__("Pause"), () => {
frm.save().then(() => {
create_custom_buttons(frm);
}, "btn-primary");
});
}).addClass("btn-primary");
} else if (frm.doc.status == "Processing") {
frm.add_custom_button(__("Pause"), () => {
} else if (frm.doc.status === "Processing") {
frm.add_custom_button('Pause', () => {
frm.set_value("status", "Hold");
updateEndTime(frm);
calculateDuration(frm);
frm.save();
create_custom_buttons(frm);
frm.save().then(() => {
create_custom_buttons(frm);
});
}).addClass("btn-primary");

frm.add_custom_button(__("Done"), () => {
frm.add_custom_button('Done', () => {
frm.set_value("status", "Complete");
updateEndTime(frm);
calculateDuration(frm);
frm.save();
create_custom_buttons(frm);
frm.save().then(() => {
create_custom_buttons(frm);
});
}).addClass("btn-primary");
} else if (frm.doc.status == "Hold") {
} else if (frm.doc.status === "Hold") {
frm.add_custom_button('Start', () => {
frm.set_value("status", "Processing");
updateStartTime(frm);
frm.save();
create_custom_buttons(frm);
frm.save().then(() => {
create_custom_buttons(frm);
});
}).addClass("btn-primary");
}
}


function updateStartTime(frm) {
const currentTime = frappe.datetime.now_datetime();
let row = frappe.model.add_child(frm.doc, 'Job Time', 'job_time');
Expand Down Expand Up @@ -81,46 +93,45 @@ function calculateDuration(frm) {
}

frappe.ui.form.on("Job Time", {
duration : function(frm, cdt, cdn){
let total_duration = 0
if(frm.doc.job_time){
frm.doc.job_time.forEach(function(d){
if(d.duration){
total_duration += d.duration || 0
duration: function(frm, cdt, cdn) {
let total_duration = 0;
if (frm.doc.job_time) {
frm.doc.job_time.forEach(function(d) {
if (d.duration) {
total_duration += d.duration || 0;
}
});
}
frm.set_value('duration',total_duration);
frm.set_value('duration', total_duration);
},
job_time_remove : function(frm, cdt, cdn){
let total_duration = 0
if(frm.doc.job_time){
frm.doc.job_time.forEach(function(d){
if(d.duration){
total_duration += d.duration || 0
job_time_remove: function(frm, cdt, cdn) {
let total_duration = 0;
if (frm.doc.job_time) {
frm.doc.job_time.forEach(function(d) {
if (d.duration) {
total_duration += d.duration || 0;
}
});
}
frm.set_value('duration',total_duration);
frm.set_value('duration', total_duration);
}
});

frappe.ui.form.on('Raw Materiel Item',{
item_details_add : function(frm, cdt, cdn){
frappe.ui.form.on('Raw Materiel Item', {
item_details_add: function(frm, cdt, cdn) {
calculate_total_weight(frm);
},
item_details_remove : function(frm, cdt, cdn){
item_details_remove: function(frm, cdt, cdn) {
calculate_total_weight(frm);
}

});

function calculate_total_weight(frm, cdt, cdn){
let total_weight = 0
if(frm.doc.item_details){
frm.doc.item_details.forEach(function(d){
function calculate_total_weight(frm) {
let total_weight = 0;
if (frm.doc.item_details) {
frm.doc.item_details.forEach(function(d) {
total_weight += d.weight || 0;
});
}
frm.set_value('weight', total_weight);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def update_item_table(self):
for item in raw_material_doc.items:
self.append('item_details', {
'item': item.item,
'quantity': item.required_quantity,
'weight':item.required_weight
'quantity': item.quantity,
})

def mark_as_completed(self, completed):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,92 +1,82 @@
// Copyright (c) 2024, efeone and contributors
// For license information, please see license.txt

frappe.ui.form.on("Manufacturing Request", {
refresh: function(frm) {
if(!frm.is_new){
hide_add_row_button(frm);
}
frm.set_query('uom',()=>{
return {
filters: {
"is_purity_uom": 1
}
}
});
frm.set_query('smith', 'manufacturing_stages', () =>{
return{
filters :{
"designation" : "Smith"
frm.set_query('uom', () => {
return {
filters: {
"is_purity_uom": 1
}
}
});
frm.set_query('smith', 'manufacturing_stages', () => {
return {
filters: {
"designation": "Smith"
}
}
});
marked_as_previous_stage_completed(frm)
if(!frm.doc.product)
{
frm.toggle_display("product",false);
marked_as_previous_stage_completed(frm);
if (!frm.doc.product) {
frm.toggle_display("product", false);
}
if(!frm.doc.weight && frm.doc.weight <= 0)
{
frm.toggle_display("weight",false);
if (!frm.doc.weight && frm.doc.weight <= 0) {
frm.toggle_display("weight", false);
}
},
setup: function(frm) {
marked_as_previous_stage_completed(frm)
},
onload: function(frm) {
hide_add_row_button(frm);
},
});

function marked_as_previous_stage_completed(frm) {
if (frm.doc.manufacturing_stages && frm.doc.manufacturing_stages.length > 0) {
frm.doc.manufacturing_stages[0].previous_stage_completed = 1;
frm.doc.manufacturing_stages[0].is_first_stage = 1;
const last_index = frm.doc.manufacturing_stages.length - 1;
frm.doc.manufacturing_stages[last_index].is_last_stage = 1;
refresh_field('manufacturing_stages');
}
}

function hide_add_row_button(frm) {
if (frm.doc.manufacturing_stages && frm.fields_dict.manufacturing_stages.grid) {
setTimeout(() => {
frm.fields_dict.manufacturing_stages.grid.wrapper.find('.grid-add-row').hide();
frm.fields_dict.manufacturing_stages.grid.wrapper.find('.grid-add-multiple-rows').hide();
}, 1000);
}
}

});

frappe.ui.form.on("Manufacturing Request Stage", {
create_raw_material_bundle: function(frm, cdt , cdn) {
create_raw_material_bundle: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
frappe.new_doc('Raw Material Bundle', {
'manufacturing_request': frm.doc.name,
'stage' : row.manufacturing_stage,
'manufacturing_stage' : row.name,
'expected_execution_time' : row.required_time
})
'stage': row.manufacturing_stage,
'manufacturing_stage': row.name,
'expected_execution_time': row.required_time
});
},

create_job_card: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
frm.call('create_jewellery_job_card', { 'stage_row_id': cdn }).then(r => {
frm.refresh_fields();
if (r.message && r.message.job_card_created) {
frappe.model.set_value(cdt, cdn, 'job_card_created', 1);
frappe.model.set_value(cdt, cdn, 'job_card', r.message.job_card);
frm.refresh_field(cdt);
// Hide the create job card button for this row
frm.fields_dict[`${cdn}-create_job_card`].df.hidden = 1;
}
});
},

view_job_card: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.job_card_created) {
frappe.set_route("Form", "Jewellery Job Card", row.job_card);
}
},

previous_stage_completed: function(frm, cdt, cdn) {
let row = locals[cdt][cdn]
let row = locals[cdt][cdn];
if (row.previous_stage_completed) {
update_previous_stage(frm, row.idx).then(previousStage => {
row.previous_stage = previousStage;
frm.refresh_field('manufacturing_stages');
frm.call('update_previous_stage', { 'idx': row.idx }).then(r => {
if (r.message) {
row.previous_stage = r.message;
frm.refresh_field('manufacturing_stages');
}
});

update_previous_stage_weight(frm, row.idx).then(previousStageWeight => {
row.previous_stage_weight = previousStageWeight;
frm.refresh_field('manufacturing_stages');
frm.call('update_previous_stage_weight', { 'idx': row.idx }).then(r => {
if (r.message) {
row.previous_stage_weight = r.message;
frm.refresh_field('manufacturing_stages');
}
});
}
},

raw_material_available: function(frm, cdt, cdn) {
let d = frm.doc.manufacturing_stages;
let current_index = -1;
Expand All @@ -103,17 +93,5 @@ frappe.ui.form.on("Manufacturing Request Stage", {
frm.refresh_field('manufacturing_stages');
}
}
},
}
});

function update_previous_stage(frm, idx) {
return frm.call('update_previous_stage', { idx: idx }).then(r => {
return r.message;
});
}

function update_previous_stage_weight(frm, idx) {
return frm.call('update_previous_stage_weight', { idx: idx }).then(r => {
return r.message;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@
"depends_on": "eval:doc.request_from == \"Jewellery Order\"",
"fieldname": "finished",
"fieldtype": "Check",
"label": "Finished",
"read_only": 1
"label": "Finished"
},
{
"fieldname": "column_break_1l2l",
Expand Down Expand Up @@ -235,7 +234,7 @@
"link_fieldname": "manufacturing_request"
}
],
"modified": "2024-05-27 10:44:47.602828",
"modified": "2024-07-05 17:06:53.887977",
"modified_by": "Administrator",
"module": "AuMMS Manufacturing",
"name": "Manufacturing Request",
Expand Down
Loading
Loading