Skip to content

Commit

Permalink
feat: add purchase order history in purcahse order
Browse files Browse the repository at this point in the history
  • Loading branch information
anhilmy committed Jul 24, 2024
1 parent 5164fd2 commit f91e28d
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 1 deletion.
282 changes: 282 additions & 0 deletions inn/fixtures/custom_field.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
[
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Purchase Order Item",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_recent_order",
"fieldtype": "Section Break",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"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": "stock_qty",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Recent Order",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2024-07-24 13:06:15.955365",
"module": "Inn Hotels",
"name": "Purchase Order Item-custom_recent_order",
"no_copy": 0,
"non_negative": 0,
"options": null,
"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,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Purchase Order Item",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_last_purchased_quantity",
"fieldtype": "Int",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"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": "custom_recent_order",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Last Purchased Quantity",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2024-07-24 13:08:10.741623",
"module": "Inn Hotels",
"name": "Purchase Order Item-custom_last_purchased_quantity",
"no_copy": 0,
"non_negative": 0,
"options": null,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 1,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Purchase Order Item",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_col_br1",
"fieldtype": "Column Break",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"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": "custom_last_purchased_quantity",
"is_system_generated": 0,
"is_virtual": 0,
"label": "",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2024-07-24 13:11:53.292843",
"module": "Inn Hotels",
"name": "Purchase Order Item-custom_col_br1",
"no_copy": 0,
"non_negative": 0,
"options": "",
"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,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Purchase Order Item",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_last_purchase_order",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"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": "custom_col_br1",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Last Purchase Order",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2024-07-24 13:14:00.775785",
"module": "Inn Hotels",
"name": "Purchase Order Item-custom_last_purchase_order",
"no_copy": 0,
"non_negative": 0,
"options": "Purchase Order",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 1,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Purchase Order Item",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_last_purchase_date",
"fieldtype": "Date",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"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": "custom_last_purchase_order",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Last Purchase Date",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2024-07-24 13:46:45.136947",
"module": "Inn Hotels",
"name": "Purchase Order Item-custom_last_purchase_date",
"no_copy": 0,
"non_negative": 0,
"options": "",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 1,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
}
]
17 changes: 16 additions & 1 deletion inn/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
# page_js = {"point-of-sale" : "public/js/inn-pos.bundle.js"}

# include js in doctype views
# doctype_js = {"doctype" : "public/js/doctype.js"}
doctype_js = {
"Purchase Order" : "public/js/purchase-order/purchase-order.js"
}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}
Expand Down Expand Up @@ -119,6 +121,19 @@
# ]
}

# Fixture
# ---------

fixtures = [
{
"doctype": "Custom Field",
"filters": [
["module", "=", "Inn Hotels"]
]
}
]


# Testing
# -------

Expand Down
Empty file.
33 changes: 33 additions & 0 deletions inn/overrides/erpnext/accounts/purchase_order/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import frappe


@frappe.whitelist()
def get_last_purchase_request(item_code):
result = {
"last_purchased_quantity": 0,
"last_purchase_order": "",
"transaction_date": ""
}
if not frappe.db.exists("Item", item_code, cache=True):
return result

query = f'''
select tpoi.parent as parent, tpoi.qty as qty, tpo.transaction_date as transaction_date
from `tabPurchase Order Item` tpoi
left join `tabPurchase Order` tpo
on tpo.name = tpoi.parent
where tpoi.item_code = '{item_code}'
and tpo.status != 'Draft'
order by tpo.transaction_date desc
limit 1
'''

last = frappe.db.sql(query, as_dict=1)
if len(last) == 0:
return result
last = last[0]

result["last_purchased_quantity"] = last.qty
result["last_purchase_order"] = last.parent
result["transaction_date"] = last.transaction_date
return result
19 changes: 19 additions & 0 deletions inn/public/js/purchase-order/purchase-order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
frappe.ui.form.on("Purchase Order Item", {

item_code: async function (frm, cdt, cdn) {
var row = locals[cdt][cdn]
console.log("called")

let result = await frappe.call({
method: "inn.overrides.erpnext.accounts.purchase_order.purchase_order.get_last_purchase_request",
args: {
item_code: row.item_code
}
})
result = result.message
row.custom_last_purchased_quantity = result.last_purchased_quantity
row.custom_last_purchase_order = result.last_purchase_order
row.custom_last_purchase_date = result.transaction_date
refresh_field("items")
}
})

0 comments on commit f91e28d

Please sign in to comment.