Skip to content

Commit

Permalink
fix : Created Fianl Product from Jewellery Job Card
Browse files Browse the repository at this point in the history
  • Loading branch information
Keerthana-ck committed May 9, 2024
1 parent fafc094 commit 220a8a6
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 47 deletions.
9 changes: 8 additions & 1 deletion aumms/aumms/doctype/aumms_settings/aumms_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"defaults_section",
"metal_ledger_uom",
"old_gold_item",
"item_group",
"column_break_2",
"metal_ledger_purity",
"default_warehouse"
Expand Down Expand Up @@ -47,12 +48,18 @@
"fieldtype": "Link",
"label": "Default Warehouse",
"options": "Warehouse"
},
{
"fieldname": "item_group",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-11-15 12:10:31.006443",
"modified": "2024-05-08 14:37:59.571631",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "AuMMS Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"type",
"category",
"purity",
"is_first_stage",
"column_break_8lq7",
"company",
"work_station",
"supervisor_warehouse",
"is_last_stage",
"column_break_tgsz",
"smith",
"smith_warehouse",
Expand All @@ -40,6 +42,7 @@
"raw_material_item_section",
"item_details",
"weight",
"final_product",
"scrap_item_details_tab",
"scrap_item_details_column",
"table_gzos",
Expand Down Expand Up @@ -261,12 +264,33 @@
"fieldname": "expected_execution_time",
"fieldtype": "Float",
"label": "Expected Execution Time",
"precision": "2"
"precision": "2",
"label": "Expected Execution Time"
},
{
"fieldname": "final_product",
"fieldtype": "Link",
"label": "Final Product",
"options": "Item"
},
{
"default": "0",
"fieldname": "is_first_stage",
"fieldtype": "Check",
"label": "Is First Stage",
"read_only": 1
},
{
"default": "0",
"fieldname": "is_last_stage",
"fieldtype": "Check",
"label": "Is Last Stage",
"read_only": 1
}
],
"is_submittable": 1,
"links": [],
"modified": "2024-05-08 09:41:41.588131",
"modified": "2024-05-08 16:50:35.853099",
"modified_by": "Administrator",
"module": "AuMMS Manufacturing",
"name": "Jewellery Job Card",
Expand All @@ -289,4 +313,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def on_submit(self):
self.create_metal_ledger()
self.create_stock_ledger()
self.update_product()
self.create_item()

def on_cancel(self):
self.mark_as_completed(completed=0)
Expand Down Expand Up @@ -66,7 +67,7 @@ def create_metal_ledger(self) :
new_metal_ledger.purity = self.purity
new_metal_ledger.out_qty = item.quantity
new_metal_ledger.balance_qty = 0
new_metal_ledger.insert(ignore_permissions=True)
new_metal_ledger.insert(ignore_permissions = True)
frappe.msgprint("Metal Ledger Created.", indicator="green", alert=1)

def create_stock_ledger(self):
Expand All @@ -78,11 +79,30 @@ def create_stock_ledger(self):
new_stock_ledger.voucher_type = self.doctype
new_stock_ledger.voucher_no = self.name
new_stock_ledger.item_code = item.item
# new_stock_ledger.item_name = item.item
new_stock_ledger.stock_uom = self.uom
new_stock_ledger.warehouse = self.smith_warehouse
new_stock_ledger.purity = self.purity
new_stock_ledger.actual_qty = item.quantity
new_stock_ledger.balance_qty = 0
new_stock_ledger.insert(ignore_permissions=True)
new_stock_ledger.insert(ignore_permissions = True)
frappe.msgprint("Stock Ledger Created.", indicator="green", alert=1)

def create_item(self):
warehouse = frappe.db.get_single_value('AuMMS Settings', 'item_group')
if not self.is_first_stage:
new_item = frappe.new_doc('AuMMS Item')
new_item.item_name = f"{self.purity} {self.type} {self.category} {self.expected_weight} {self.stage}"
new_item.item_type = self.type
new_item.item_group = warehouse
new_item.stock_uom = self.uom
new_item.item_category = self.category
new_item.purity = self.purity
new_item.is_stock_item = True
new_item.item_code = f"{self.purity} {self.type} {self.category} {self.stage} {self.expected_weight}"
if self.is_last_stage:
new_item.is_raw_material = False
else:
new_item.is_raw_material = True
frappe.db.set_value('Jewellery Job Card', self.name, 'final_product', new_item.item_name)
new_item.save(ignore_permissions=True)
frappe.msgprint("Item Created.", indicator="green", alert=1)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"in_list_view": 1,
"label": "Manufacturing Stage",
"options": "Manufacturing Stage",
"read_only": 1,
"reqd": 1
},
{
Expand Down Expand Up @@ -174,7 +175,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-05-06 12:08:56.131899",
"modified": "2024-05-08 17:27:56.569053",
"modified_by": "Administrator",
"module": "AuMMS Manufacturing",
"name": "Manufacturing Stage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ frappe.ui.form.on("Manufacturing Request", {
}
}
});
if(frm.doc.manufacturing_stages && frm.doc.manufacturing_stages.length > 0){
frm.doc.manufacturing_stages[0].previous_stage_completed = 1;
refresh_field('manufacturing_stages')
}
marked_as_previous_stage_completed(frm)
},
setup: function(frm) {
if(frm.doc.manufacturing_stages && frm.doc.manufacturing_stages.length > 0){
frm.doc.manufacturing_stages[0].previous_stage_completed = 1;
refresh_field('manufacturing_stages')
}
marked_as_previous_stage_completed(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');
}
}

frappe.ui.form.on("Manufacturing Stage", {
create_raw_material_bundle: function(frm, cdt , cdn) {
let row = locals[cdt][cdn];
Expand All @@ -42,7 +46,7 @@ frappe.ui.form.on("Manufacturing Stage", {
})
},
create_job_card: function(frm, cdt, cdn) {
frm.call('create_jewellery_job_card', { 'stage_row_id': cdn }).then(r => {
frm.call('create_jewellery_job_card', { 'stage_row_id':cdn }).then(r => {
frm.refresh_fields();
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,41 @@ def update_previous_stage_weight(self, idx):

@frappe.whitelist()
def create_jewellery_job_card(self, stage_row_id):
stage = frappe.get_doc('Manufacturing Stage', stage_row_id)
jewellery_job_card_exists = frappe.db.exists('Jewellery Job Card', {'manufacturing_request': self.name, 'manufacturing_stage': stage.manufacturing_stage})
if not jewellery_job_card_exists:
smith_email = frappe.db.get_value('Employee', stage.smith, 'user_id')
new_jewellery_job_card = frappe.new_doc('Jewellery Job Card')
new_jewellery_job_card.manufacturing_request = self.name
new_jewellery_job_card.smith = stage.smith
new_jewellery_job_card.work_station = stage.workstation
new_jewellery_job_card.required_date = self.required_date
new_jewellery_job_card.purity = self.purity
new_jewellery_job_card.expected_weight = self.expected_weight
new_jewellery_job_card.uom = self.uom
new_jewellery_job_card.type = self.type
new_jewellery_job_card.category = self.category
new_jewellery_job_card.smith_warehouse = stage.smith_warehouse
new_jewellery_job_card.expected_execution_time = stage.expected_execution_time
new_jewellery_job_card.manufacturing_stage = stage.manufacturing_stage
new_jewellery_job_card.stage = stage.manufacturing_stage
new_jewellery_job_card.supervisor_warehouse = self.supervisor_warehouse
new_jewellery_job_card.supervisor_warehouse = self.supervisor_warehouse
new_jewellery_job_card.raw_material_from_previous_stage_only = stage.is_raw_material_from_previous_stage_only
new_jewellery_job_card.keep_metal_ledger = True
new_jewellery_job_card.flags.ignore_mandatory = True
new_jewellery_job_card.save(ignore_permissions=True)
frappe.db.set_value(stage.doctype, stage.name, 'job_card_created', 1)
if smith_email:
add_assignment({"doctype": "Jewellery Job Card", "name": new_jewellery_job_card.name, "smith": [smith_email]})
frappe.msgprint("Jewellery Job Card Orders Created.", indicator="green", alert=1)
else:
frappe.throw(_("Job card already exists for this stage"))
first_stage, last_stage = False, False
if self.manufacturing_stages:
first_stage = self.manufacturing_stages[0].name
last_stage = self.manufacturing_stages[-1].name
stage = frappe.get_doc('Manufacturing Stage', stage_row_id)
jewellery_job_card_exists = frappe.db.exists('Jewellery Job Card', {'manufacturing_request': self.name, 'manufacturing_stage': stage.manufacturing_stage})
if not jewellery_job_card_exists:
smith_email = frappe.db.get_value('Employee', stage.smith, 'user_id')
new_jewellery_job_card = frappe.new_doc('Jewellery Job Card')
new_jewellery_job_card.manufacturing_request = self.name
new_jewellery_job_card.smith = stage.smith
new_jewellery_job_card.work_station = stage.workstation
new_jewellery_job_card.required_date = self.required_date
new_jewellery_job_card.purity = self.purity
new_jewellery_job_card.expected_weight = self.expected_weight
new_jewellery_job_card.uom = self.uom
new_jewellery_job_card.type = self.type
new_jewellery_job_card.category = self.category
new_jewellery_job_card.smith_warehouse = stage.smith_warehouse
new_jewellery_job_card.expected_execution_time = stage.expected_execution_time
new_jewellery_job_card.manufacturing_stage = stage.manufacturing_stage
new_jewellery_job_card.stage = stage.manufacturing_stage
new_jewellery_job_card.supervisor_warehouse = self.supervisor_warehouse
new_jewellery_job_card.supervisor_warehouse = self.supervisor_warehouse
new_jewellery_job_card.raw_material_from_previous_stage_only = stage.is_raw_material_from_previous_stage_only
new_jewellery_job_card.keep_metal_ledger = 1
if first_stage == stage_row_id:
new_jewellery_job_card.is_first_stage = 1
if last_stage == stage_row_id:
new_jewellery_job_card.is_last_stage = 1
new_jewellery_job_card.flags.ignore_mandatory = True
new_jewellery_job_card.save(ignore_permissions=True)
frappe.db.set_value(stage.doctype, stage.name, 'job_card_created', 1)
if smith_email:
add_assignment({"doctype": "Jewellery Job Card", "name": new_jewellery_job_card.name, "smith": [smith_email]})
frappe.msgprint("Jewellery Job Card Created.", indicator="green", alert=1)
else:
frappe.throw(_("Job card already exists for this stage"))

0 comments on commit 220a8a6

Please sign in to comment.