Skip to content

Commit

Permalink
feat: delivery note and purchase receipt items added
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishBarvaliya committed Sep 19, 2024
1 parent f999595 commit f2c612f
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,70 @@
"field_order": [
"item_code",
"qty",
"uom"
"uom",
"stock_uom",
"conversion_factor",
"stock_qty",
"serial_no"
],
"fields": [
{
"fieldname": "item_code",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item Code",
"options": "Item"
"options": "Item",
"reqd": 1
},
{
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Quantity"
"label": "Quantity",
"reqd": 1
},
{
"fieldname": "uom",
"fieldtype": "Link",
"in_list_view": 1,
"label": "UOM",
"options": "UOM"
"options": "UOM",
"reqd": 1
},
{
"depends_on": "eval:doc.uom != doc.stock_uom",
"fieldname": "stock_uom",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Stock UOM",
"options": "UOM",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "serial_no",
"fieldtype": "Text",
"label": "Serial No"
},
{
"depends_on": "eval:doc.uom != doc.stock_uom",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"label": "UOM Conversion Factor",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "stock_qty",
"fieldtype": "Float",
"label": "Qty in Stock UOM",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-07-31 08:54:38.313784",
"modified": "2024-09-19 08:05:10.135145",
"modified_by": "Administrator",
"module": "D2H",
"name": "Delivery Note Item Duplicate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
"engine": "InnoDB",
"field_order": [
"item_code",
"uom",
"base_rate",
"stock_uom",
"received_qty",
"conversion_factor",
"qty",
"rejected_qty"
"rejected_qty",
"serial_no",
"purchase_order"
],
"fields": [
{
Expand All @@ -19,6 +26,8 @@
"label": "Item Code",
"options": "Item",
"print_width": "100px",
"reqd": 1,
"search_index": 1,
"width": "100px"
},
{
Expand All @@ -38,12 +47,64 @@
"label": "Rejected Quantity",
"max_height": "100px",
"width": "100px"
},
{
"fieldname": "uom",
"fieldtype": "Link",
"label": "UOM",
"options": "UOM",
"reqd": 1
},
{
"fieldname": "stock_uom",
"fieldtype": "Link",
"label": "Stock UOM",
"options": "UOM",
"reqd": 1
},
{
"depends_on": "eval:doc.uom != doc.stock_uom",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"label": "Conversion Factor",
"print_hide": 1,
"reqd": 1
},
{
"default": "0",
"fieldname": "received_qty",
"fieldtype": "Float",
"label": "Received Quantity",
"no_copy": 1,
"print_hide": 1,
"read_only": 1,
"reqd": 1
},
{
"fieldname": "base_rate",
"fieldtype": "Currency",
"label": "Rate (Company Currency)",
"options": "Company:company:default_currency",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "serial_no",
"fieldtype": "Text",
"label": "Serial No"
},
{
"fieldname": "purchase_order",
"fieldtype": "Link",
"label": "Purchase Order",
"options": "Purchase Order",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-07-30 08:19:38.495886",
"modified": "2024-09-19 07:35:58.296873",
"modified_by": "Administrator",
"module": "D2H",
"name": "Purchase Receipt Item Duplicate",
Expand Down
8 changes: 3 additions & 5 deletions d2h/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,9 @@

doc_events = {
"Purchase Receipt": {
"before_save": "d2h.overrides.purchase_receipt_before_save",
"on_submit": "d2h.overrides.on_submit_purchase_receipt",
"on_trash": "d2h.overrides.on_delete_purchase_receipt"
},
"Delivery Note": {
"before_save": "d2h.overrides.delivery_note_before_save"
},
"*": {
"before_print": "d2h.api.before_print"
}
Expand All @@ -245,4 +241,6 @@

app_include_js = "/assets/d2h/js/form.js"

doctype_js = {"Purchase Receipt" : "public/js/purchase_receipt.js", "Purchase Order" : "public/js/purchase_order.js", "Delivery Note" : "public/js/delivery_note.js", "Sales Order" : "public/js/sales_order.js"}
doctype_js = {"Purchase Receipt" : "public/js/purchase_receipt.js", "Purchase Order" : "public/js/purchase_order.js", "Delivery Note" : "public/js/delivery_note.js", "Sales Order" : "public/js/sales_order.js"}

doctype_list_js = {"Delivery Note" : "public/js/delivery_note_list.js", "Purchase Receipt" : "public/js/purchase_receipt_list.js", "Sales Order" : "public/js/sales_order_list.js"}
37 changes: 10 additions & 27 deletions d2h/overrides.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
import frappe

def purchase_receipt_before_save(doc, method):
if len(doc.items) > 0:
doc.custom_item_duplicate = []
for item in doc.items:
new_item = doc.append("custom_item_duplicate", {})
new_item.item_code = item.item_code
new_item.qty = item.qty
new_item.rejected_qty = item.rejected_qty

def delivery_note_before_save(doc, method):
if len(doc.items) > 0:
doc.custom_delivery_note_item_duplicate = []
for item in doc.items:
new_item = doc.append("custom_delivery_note_item_duplicate", {})
new_item.item_code = item.item_code
new_item.qty = item.qty
new_item.uom = item.uom

def on_submit_purchase_receipt(doc, method):
for item in doc.items:
item_order = frappe.get_doc("Purchase Order Item", {
"item_code": item.item_code,
"parent": item.purchase_order
})
if(item_order.custom_good_in_transit_qty > item.qty):
item_order.custom_good_in_transit_qty -= item.qty
else:
item_order.custom_good_in_transit_qty = 0
item_order.save()
if item.purchase_order:
item_order = frappe.get_doc("Purchase Order Item", {
"item_code": item.item_code,
"parent": item.purchase_order
})
if(item_order.custom_good_in_transit_qty > item.qty):
item_order.custom_good_in_transit_qty -= item.qty
else:
item_order.custom_good_in_transit_qty = 0
item_order.save()

def on_delete_purchase_receipt(doc, method):
on_submit_purchase_receipt(doc, method)
Expand Down
35 changes: 35 additions & 0 deletions d2h/public/js/delivery_note.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,39 @@ frappe.ui.form.on("Delivery Note", {
frm.set_df_property("custom_section_break_jwbcu", "hidden", false);
}
},
validate(frm) {
if (
frappe.user_roles.includes("Store Dept") &&
!frappe.user_roles.includes("Administrator")
) {
frm.doc.items = [];
frm.refresh_field("items");
frm.doc.custom_delivery_note_item_duplicate.map((item) => {
const new_item = frm.add_child("items");
new_item.item_code = item.item_code;
new_item.item_name = item.item_code;
new_item.qty = item.qty;
new_item.uom = item.uom;
new_item.stock_uom = item.stock_uom;
new_item.conversion_factor = item.conversion_factor;
new_item.stock_qty = item.stock_qty;
new_item.serial_no = item.serial_no;
});
frm.refresh_field("items");
} else {
frm.doc.custom_delivery_note_item_duplicate = [];
frm.refresh_field("custom_delivery_note_item_duplicate");
frm.doc.items.map((item) => {
const new_item = frm.add_child("custom_delivery_note_item_duplicate");
new_item.item_code = item.item_code;
new_item.qty = item.qty;
new_item.uom = item.uom;
new_item.stock_uom = item.stock_uom;
new_item.conversion_factor = item.conversion_factor;
new_item.stock_qty = item.stock_qty;
new_item.serial_no = item.serial_no;
});
frm.refresh_field("custom_delivery_note_item_duplicate");
}
},
});
13 changes: 13 additions & 0 deletions d2h/public/js/delivery_note_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
frappe.listview_settings["Delivery Note"] = {
onload: function (listview) {
if (frappe.user.has_role("Store Dept")) {
listview.columns = listview.columns.filter(function (col) {
if (col.df) {
return col.df.fieldname !== "grand_total";
}
return true;
});
listview.render_header(listview.columns);
}
},
};
43 changes: 43 additions & 0 deletions d2h/public/js/purchase_receipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ frappe.ui.form.on("Purchase Receipt", {
frm.set_df_property("sec_warehouse", "hidden", true);
frm.set_df_property("items_section", "hidden", true);
frm.set_df_property("section_break0", "hidden", true);
frm.set_df_property("accounting_dimensions_section", "hidden", true);
frm.set_df_property("currency_and_price_list", "hidden", true);
frm.set_df_property("taxes_charges_section", "hidden", true);
frm.set_df_property("taxes_section", "hidden", true);
frm.set_df_property("totals", "hidden", true);
Expand All @@ -18,4 +20,45 @@ frappe.ui.form.on("Purchase Receipt", {
frm.set_df_property("custom_section_break_fmgux", "hidden", false);
}
},
validate(frm) {
if (
frappe.user_roles.includes("Store Dept") &&
!frappe.user_roles.includes("Administrator")
) {
frm.doc.items = [];
frm.refresh_field("items");
frm.doc.custom_item_duplicate.map((item) => {
const new_item = frm.add_child("items");
new_item.item_code = item.item_code;
new_item.item_name = item.item_code;
new_item.qty = item.qty;
new_item.uom = item.uom;
new_item.base_rate = item.base_rate;
new_item.stock_uom = item.stock_uom;
new_item.conversion_factor = item.conversion_factor;
new_item.received_qty = item.received_qty;
new_item.serial_no = item.serial_no;
new_item.rejected_qty = item.rejected_qty;
new_item.purchase_order = item.purchase_order;
});
frm.refresh_field("items");
} else {
frm.doc.custom_item_duplicate = [];
frm.refresh_field("custom_item_duplicate");
frm.doc.items.map((item) => {
const new_item = frm.add_child("custom_item_duplicate");
new_item.item_code = item.item_code;
new_item.qty = item.qty;
new_item.uom = item.uom;
new_item.base_rate = item.base_rate;
new_item.stock_uom = item.stock_uom;
new_item.conversion_factor = item.conversion_factor;
new_item.received_qty = item.received_qty;
new_item.serial_no = item.serial_no;
new_item.rejected_qty = item.rejected_qty;
new_item.purchase_order = item.purchase_order;
});
frm.refresh_field("custom_item_duplicate");
}
},
});
13 changes: 13 additions & 0 deletions d2h/public/js/purchase_receipt_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
frappe.listview_settings["Purchase Receipt"] = {
onload: function (listview) {
if (frappe.user.has_role("Store Dept")) {
listview.columns = listview.columns.filter(function (col) {
if (col.df) {
return col.df.fieldname !== "grand_total";
}
return true;
});
listview.render_header(listview.columns);
}
},
};

0 comments on commit f2c612f

Please sign in to comment.