Skip to content

Commit

Permalink
Merge pull request #394 from efeone/aumms_29
Browse files Browse the repository at this point in the history
feat:Create raw material request as per the number of rows in raw material bundle
  • Loading branch information
SherinKR authored May 10, 2024
2 parents 2abce53 + 2fb79a8 commit 9744682
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ def create_jewellery_job_card(self, stage_row_id):
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})
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')
Expand All @@ -141,6 +145,10 @@ def create_jewellery_job_card(self, stage_row_id):
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.append('item_details', {
'item': stage.previous_stage_product,
'weight': stage.previous_stage_weight,
})
new_jewellery_job_card.keep_metal_ledger = 1
if first_stage == stage_row_id:
new_jewellery_job_card.is_first_stage = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ frappe.ui.form.on("Raw Material Bundle", {
freeze: true,
callback: (r) => {
frm.reload_doc();
var raw_material_request = r.message;
if (raw_material_request) {
frappe.set_route('Form', 'Raw Material Request', raw_material_request.name);
}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,39 @@ def mark_as_raw_material_bundle_created(self, created):

@frappe.whitelist()
def create_raw_material_request(docname):
raw_material_bundle = frappe.get_doc("Raw Material Bundle", docname)
uom = s_warehouse = frappe.get_single("AuMMS Settings").get("metal_ledger_uom")
for raw_material in raw_material_bundle.items:
raw_material_request_exists = frappe.db.exists('Raw Material Request', {
'manufacturing_request': raw_material_bundle.manufacturing_request,
'item': raw_material.item
})
raw_material_bundle = frappe.get_doc("Raw Material Bundle", docname)
uom = frappe.get_single("AuMMS Settings").get("metal_ledger_uom")
raw_material_request_count = 0
for raw_material in raw_material_bundle.items:
raw_material_request_exists = frappe.db.exists('Raw Material Request', {
'manufacturing_request': raw_material_bundle.manufacturing_request,
'item': raw_material.item
})
if not raw_material_request_exists:
new_raw_material_request = frappe.new_doc('Raw Material Request')
new_raw_material_request.raw_material_request_type = "Raw Material Request"
new_raw_material_request.raw_material_bundle = raw_material_bundle.name
new_raw_material_request.manufacturing_request = raw_material_bundle.manufacturing_request
new_raw_material_request.required_quantity = raw_material.required_quantity - raw_material.available_quantity
new_raw_material_request.required_date = raw_material_bundle.required_date
new_raw_material_request.uom = raw_material_bundle.uom
new_raw_material_request.item_type = raw_material_bundle.type
new_raw_material_request.purity = raw_material_bundle.purity
new_raw_material_request.supervisor_warehouse = raw_material_bundle.supervisor_warehouse
new_raw_material_request.bundle_id = raw_material.raw_material_id
new_raw_material_request.uom = uom
raw_material_details = {
'item': raw_material.item,
'warehouse': raw_material.warehouse,
'required_quantity': raw_material.required_quantity,
'available_quantity': raw_material.available_quantity,
'required_weight': raw_material.required_weight,
'available_weight': raw_material.available_weight,
}
new_raw_material_request.append('raw_material_details', raw_material_details)
new_raw_material_request.insert(ignore_permissions=True)
raw_material_request_count += 1

if not raw_material_request_exists:
new_raw_material_request = frappe.new_doc('Raw Material Request')
new_raw_material_request.raw_material_request_type = "Raw Material Request"
new_raw_material_request.raw_material_bundle = raw_material_bundle.name
new_raw_material_request.manufacturing_request = raw_material_bundle.manufacturing_request
new_raw_material_request.required_quantity = raw_material.required_quantity - raw_material.available_quantity
new_raw_material_request.required_date = raw_material_bundle.required_date
new_raw_material_request.uom = raw_material_bundle.uom
new_raw_material_request.item_type = raw_material_bundle.type
new_raw_material_request.purity = raw_material_bundle.purity
new_raw_material_request.supervisor_warehouse = raw_material_bundle.supervisor_warehouse
new_raw_material_request.bundle_id = raw_material.raw_material_id
new_raw_material_request.uom = uom
new_raw_material_request.append('raw_material_details', {
'item': raw_material.item,
'warehouse': raw_material.warehouse,
'required_quantity': raw_material.required_quantity,
'available_quantity': raw_material.available_quantity,
'required_weight': raw_material.required_weight,
'available_weight': raw_material.available_weight,
})
new_raw_material_request.insert(ignore_permissions=True)
frappe.msgprint("Raw Material Request Created.", indicator="green", alert=True)
return new_raw_material_request


else:
frappe.throw(_("Raw Material Request already exists for item {0}").format(raw_material.item))
else:
frappe.throw(_("Raw Material Request already exists for item {0}").format(raw_material.item))
frappe.msgprint(f"{raw_material_request_count} Manufacturing Requests Created.", indicator="green", alert=True)

0 comments on commit 9744682

Please sign in to comment.