Skip to content

Commit

Permalink
feat: gl entry
Browse files Browse the repository at this point in the history
  • Loading branch information
sibikumarkuppusamy committed Jul 25, 2024
1 parent abbafca commit cd6c801
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
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)
)
5 changes: 5 additions & 0 deletions asset/asset/customizations/gl_entry/gl_entry.py
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)
9 changes: 9 additions & 0 deletions asset/asset/customizations/journal_entry/journal_entry.js
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 asset/asset/customizations/product_bundle/product_bundle.js
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 asset/asset/customizations/product_bundle/product_bundle.py
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()

0 comments on commit cd6c801

Please sign in to comment.