diff --git a/asset/asset/customizations/gl_entry/doc_events/validate_cwip_accounts.py b/asset/asset/customizations/gl_entry/doc_events/validate_cwip_accounts.py new file mode 100644 index 0000000..2c4b064 --- /dev/null +++ b/asset/asset/customizations/gl_entry/doc_events/validate_cwip_accounts.py @@ -0,0 +1,30 @@ +import frappe +from frappe import _ +from frappe.utils import cint + + + +def validate_cwip_accounts(doc): + """Validate that CWIP account are not used in Journal Entry""" + if doc.voucher_type != "Journal Entry": + return + + cwip_enabled = any( + cint(ac.enable_cwip_accounting) + for ac in frappe.db.get_all("Asset Category", "enable_cwip_accounting") + ) + if cwip_enabled: + cwip_accounts = [ + d[0] + for d in frappe.db.sql( + """select name from tabAccount + where account_type = 'Capital Work in Progress' and is_group=0""" + ) + ] + + if doc.account in cwip_accounts: + frappe.throw( + _( + "Account: {0} is capital Work in progress and can not be updated by Journal Entry" + ).format(doc.account) + ) \ No newline at end of file diff --git a/asset/asset/customizations/gl_entry/gl_entry.py b/asset/asset/customizations/gl_entry/gl_entry.py new file mode 100644 index 0000000..858717f --- /dev/null +++ b/asset/asset/customizations/gl_entry/gl_entry.py @@ -0,0 +1,5 @@ +from asset.asset.customizations.gl_entry.doc_events.validate_cwip_accounts import validate_cwip_accounts + +def validate(doc, method= None): + if not doc.flags.from_repost: + validate_cwip_accounts(doc) \ No newline at end of file diff --git a/asset/asset/customizations/journal_entry/journal_entry.js b/asset/asset/customizations/journal_entry/journal_entry.js new file mode 100644 index 0000000..2e6e8d6 --- /dev/null +++ b/asset/asset/customizations/journal_entry/journal_entry.js @@ -0,0 +1,9 @@ +frappe.ui.form.on("Journal Entry", { + setup: function (frm) { + frm.ignore_doctypes_on_cancel_all.push( + "Asset", + "Asset Movement", + "Asset Depreciation Schedule" + ); + }, +}); \ No newline at end of file diff --git a/asset/asset/customizations/product_bundle/product_bundle.js b/asset/asset/customizations/product_bundle/product_bundle.js new file mode 100644 index 0000000..0f2ed54 --- /dev/null +++ b/asset/asset/customizations/product_bundle/product_bundle.js @@ -0,0 +1,10 @@ +frappe.ui.form.on("Product Bundle", { + refresh: function (frm) { + frm.toggle_enable("new_item_code", frm.is_new()); + frm.set_query("new_item_code", () => { + return { + query: "asset.asset.customizations.product_bundle.product_bundle.get_new_item_code", + }; + }); + }, +}); diff --git a/asset/asset/customizations/product_bundle/product_bundle.py b/asset/asset/customizations/product_bundle/product_bundle.py new file mode 100644 index 0000000..5d45d30 --- /dev/null +++ b/asset/asset/customizations/product_bundle/product_bundle.py @@ -0,0 +1,30 @@ +import frappe +from frappe import _ + +def validate(self, method = None): + validate_main_item(self) + + +def validate_main_item(self): + if frappe.db.get_value("Item", self.new_item_code, "is_fixed_asset"): + frappe.throw(_("Parent Item {0} must not be a Fixed Asset").format(self.new_item_code)) + + +@frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs +def get_new_item_code(doctype, txt, searchfield, start, page_len, filters): + product_bundles = frappe.db.get_list("Product Bundle", {"disabled": 0}, pluck="name") + + item = frappe.qb.DocType("Item") + query = ( + frappe.qb.from_(item) + .select(item.item_code, item.item_name) + .where((item.is_stock_item == 0) & (item.is_fixed_asset == 0) & (item[searchfield].like(f"%{txt}%"))) + .limit(page_len) + .offset(start) + ) + + if product_bundles: + query = query.where(item.name.notin(product_bundles)) + + return query.run() \ No newline at end of file