Skip to content
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
23 changes: 22 additions & 1 deletion beams/beams/custom_scripts/purchase_invoice/purchase_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,25 @@ function fetch_advances_from_mcts(frm) {
},
});
}
}
}

/**
* Fetch cost head from the item doctype.
*/
function set_cost_head(cdt, cdn) {
let row = locals[cdt][cdn];
if (row.item_code) {
frappe.db.get_value('Item', row.item_code, 'cost_head')
.then(r => {
if (r.message && r.message.cost_head) {
frappe.model.set_value(cdt, cdn, 'cost_head', r.message.cost_head);
}
});
}
}

frappe.ui.form.on('Purchase Invoice Item', {
item_code: function(frm, cdt, cdn) {
set_cost_head(cdt, cdn);
}
});
10 changes: 10 additions & 0 deletions beams/beams/custom_scripts/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ def set_from_bureau_flag(doc, method):
if "Bureau User" in frappe.get_roles(user):
doc.from_bureau = 1

def set_cost_head_from_item(doc, method=None):
"""
Fetch cost head from item doctype
"""
for row in doc.get("items"):
if not row.item_code:
continue
item_cost_head = frappe.db.get_value("Item", row.item_code, "cost_head")
if item_cost_head:
row.cost_head = item_cost_head
21 changes: 21 additions & 0 deletions beams/beams/custom_scripts/purchase_order/purchase_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ function clear_checkbox_exceed(frm){
frm.set_value("is_budget_exceeded", 0);
}
}

/**
* Fetch cost head from the item doctype.
*/
function set_cost_head(cdt, cdn) {
let row = locals[cdt][cdn];
if (row.item_code) {
frappe.db.get_value('Item', row.item_code, 'cost_head')
.then(r => {
if (r.message && r.message.cost_head) {
frappe.model.set_value(cdt, cdn, 'cost_head', r.message.cost_head);
}
});
}
}

frappe.ui.form.on('Purchase Order Item', {
item_code: function(frm, cdt, cdn) {
set_cost_head(cdt, cdn);
}
});
22 changes: 22 additions & 0 deletions beams/beams/custom_scripts/sales_invoice/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,25 @@ function check_include_in_ibf(frm) {
});
}
}

/**
* Fetch cost head from the item doctype.
*/
function set_cost_head(cdt, cdn) {
let row = locals[cdt][cdn];
if (row.item_code) {
frappe.db.get_value('Item', row.item_code, 'cost_head')
.then(r => {
if (r.message && r.message.cost_head) {
frappe.model.set_value(cdt, cdn, 'cost_head', r.message.cost_head);
}
});
}
}

frappe.ui.form.on('Sales Invoice Item', {
item_code: function(frm, cdt, cdn) {
set_cost_head(cdt, cdn);
}
});

21 changes: 21 additions & 0 deletions beams/beams/custom_scripts/sales_order/sales_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,24 @@ function check_is_agent_from_customer(frm) {
});
}
}

/**
* Fetch cost head from the item doctype.
*/
function set_cost_head(cdt, cdn) {
let row = locals[cdt][cdn];
if (row.item_code) {
frappe.db.get_value('Item', row.item_code, 'cost_head')
.then(r => {
if (r.message && r.message.cost_head) {
frappe.model.set_value(cdt, cdn, 'cost_head', r.message.cost_head);
}
});
}
}

frappe.ui.form.on('Sales Order Item', {
item_code: function(frm, cdt, cdn) {
set_cost_head(cdt, cdn);
}
});
14 changes: 11 additions & 3 deletions beams/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@
"Sales Invoice": {
"on_update_after_submit":"beams.beams.custom_scripts.sales_invoice.sales_invoice.on_update_after_submit",
"autoname": "beams.beams.custom_scripts.sales_invoice.sales_invoice.autoname",
"validate": "beams.beams.custom_scripts.sales_invoice.sales_invoice.validate_sales_invoice_for_barter"
"validate": [
"beams.beams.custom_scripts.sales_invoice.sales_invoice.validate_sales_invoice_for_barter",
"beams.beams.custom_scripts.purchase_invoice.purchase_invoice.set_cost_head_from_item",
],
},
"Quotation": {
"validate": "beams.beams.custom_scripts.quotation.quotation.validate_is_barter",
Expand All @@ -208,6 +211,7 @@
"before_save": "beams.beams.custom_scripts.purchase_invoice.purchase_invoice.before_save",
"before_insert": "beams.beams.custom_scripts.purchase_invoice.purchase_invoice.set_from_bureau_flag",
"before_validate": "beams.beams.custom_scripts.purchase_order.purchase_order.set_is_budgeted",
"validate": "beams.beams.custom_scripts.purchase_invoice.purchase_invoice.set_cost_head_from_item",
},
"Account": {
"after_insert": "beams.beams.custom_scripts.account.account.create_todo_on_creation_for_account"
Expand All @@ -229,7 +233,10 @@
},
"Purchase Order": {
"on_update": "beams.beams.custom_scripts.purchase_order.purchase_order.create_todo_on_finance_verification",
"validate": "beams.beams.custom_scripts.purchase_order.purchase_order.validate_reason_for_rejection",
"validate": [
"beams.beams.custom_scripts.purchase_order.purchase_order.validate_reason_for_rejection",
"beams.beams.custom_scripts.purchase_invoice.purchase_invoice.set_cost_head_from_item",
],
"before_validate": "beams.beams.custom_scripts.purchase_order.purchase_order.set_is_budgeted",
"on_change":"beams.beams.custom_scripts.purchase_order.purchase_order.update_equipment_quantities",
},
Expand All @@ -243,7 +250,8 @@
"Sales Order": {
"autoname": "beams.beams.custom_scripts.sales_order.sales_order.autoname",
"before_save": "beams.beams.custom_scripts.sales_order.sales_order.validate_sales_order_amount_with_quotation",
"before_insert": "beams.beams.custom_scripts.sales_order.sales_order.set_region_from_quotation"
"before_insert": "beams.beams.custom_scripts.sales_order.sales_order.set_region_from_quotation",
"validate": "beams.beams.custom_scripts.purchase_invoice.purchase_invoice.set_cost_head_from_item",
},
"Contract": {
"on_update": "beams.beams.custom_scripts.contract.contract.create_todo_on_contract_verified_by_finance",
Expand Down
7 changes: 7 additions & 0 deletions beams/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,13 @@ def get_item_custom_fields():
"fieldtype": "Check",
"label": "Is Bundle Item",
"insert_after": "has_variants"
},
{
"fieldname": "cost_head",
"fieldtype": "Link",
"label": "Cost Head",
"options": "Cost Head",
"insert_after": "item_defaults"
}
]
}
Expand Down