-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abbafca
commit cd6c801
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
asset/asset/customizations/gl_entry/doc_events/validate_cwip_accounts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <b>{0}</b> is capital Work in progress and can not be updated by Journal Entry" | ||
).format(doc.account) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); | ||
}, | ||
}); |
10 changes: 10 additions & 0 deletions
10
asset/asset/customizations/product_bundle/product_bundle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}; | ||
}); | ||
}, | ||
}); |
30 changes: 30 additions & 0 deletions
30
asset/asset/customizations/product_bundle/product_bundle.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |