Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: acc_dimention value fetched in asset_value adjustment and asset… #57

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def make_dimension_in_accounting_doctypes(doc, doclist=None):
"insert_after": set_target_dimension,
"owner": "Administrator",
"allow_on_submit": 1 if doctype in repostable_doctypes else 0,
"read_only": 1
}

meta = frappe.get_meta(doctype, cached=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,58 @@ frappe.ui.form.on("Asset Movement", {
frm.refresh_field("assets");
}
},
purpose: function (frm) {
const resetFields = () => {
frappe.db.get_list("Accounting Dimension", {
fields: ["fieldname"]
}).then(fields => {
let fieldnames_to_be_altered = {};

const target_fields = fields.map(field => `target_${field["fieldname"]}`);

target_fields.forEach(field => {
fieldnames_to_be_altered[field] = { read_only: 1, reqd: 0 };
});
fieldnames_to_be_altered["custom_target_cost_center"] = { read_only: 1, reqd: 0 }

Object.keys(fieldnames_to_be_altered).forEach((fieldname) => {
let property_to_be_altered = fieldnames_to_be_altered[fieldname];
Object.keys(property_to_be_altered).forEach((property) => {
let value = property_to_be_altered[property];
frm.fields_dict["assets"].grid.update_docfield_property(fieldname, property, value);
});
});
frm.refresh_field("assets");
});
};

if (frm.doc.purpose === "Transfer") {
frappe.db.get_list("Accounting Dimension", {
fields: ["fieldname"]
}).then(fields => {
let fieldnames_to_be_altered = {};

const target_fields = fields.map(field => `target_${field["fieldname"]}`);

target_fields.forEach(field => {
fieldnames_to_be_altered[field] = { read_only: 0, reqd: 0 };
});
fieldnames_to_be_altered["custom_target_cost_center"] = { read_only: 0, reqd: 0 }

Object.keys(fieldnames_to_be_altered).forEach((fieldname) => {
let property_to_be_altered = fieldnames_to_be_altered[fieldname];
Object.keys(property_to_be_altered).forEach((property) => {
let value = property_to_be_altered[property];
frm.fields_dict["assets"].grid.update_docfield_property(fieldname, property, value);
});
});
frm.refresh_field("assets");
});
} else {
resetFields();
}
}

});


Expand All @@ -102,6 +154,7 @@ frappe.ui.form.on("Asset Movement Item", {
}).then(fields => {
// Extract and convert field names to the required format
const field_names = fields.map(field => `from_${field.name.toLowerCase().replace(/ /g, '_')}`);
const target_fields = fields.map(field => `target_${field.name.toLowerCase().replace(/ /g, '_')}`);

// on manual entry of an asset auto sets their source location / employee
const asset_name = locals[cdt][cdn].asset;
Expand All @@ -119,8 +172,16 @@ frappe.ui.form.on("Asset Movement Item", {
if (asset_doc.cost_center) {
frappe.model.set_value(cdt, cdn, "custom_from_cost_center", asset_doc.cost_center);
}
if (frm.doc.purpose == "Issue" || frm.doc.purpose == "Reciept"){
target_fields.forEach(field => {
const original_field = field.replace("target_", "");
if (asset_doc[original_field]) {
frappe.model.set_value(cdt, cdn, field, asset_doc[original_field]);
}
});
frappe.model.set_value(cdt, cdn, "custom_target_cost_center", asset_doc.cost_center);

// Dynamically set other fields
}
field_names.forEach(field => {
const original_field = field.replace("from_", "");
if (asset_doc[original_field]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,26 @@ def set_latest_location_and_custodian_in_asset(self):

for original_field in field_mapping.values():
frappe.db.set_value("Asset", d.asset, original_field, current_values[original_field], update_modified=False)
if self.purpose == "Transfer":
if len(frappe.db.get_all("Asset Movement Item", {"asset": d.asset})) > 1:
if frappe.db.exists("Asset Depreciation Schedule", {"asset": d.asset}):
asset_depr_schedule_doc = frappe.get_doc("Asset Depreciation Schedule", {"asset":d.asset})
update_depreciation_schedule(d.asset, asset_depr_schedule_doc.name, self.transaction_date)
make_depreciation_entry(asset_depr_schedule_doc.name)

if len(frappe.db.get_all("Asset Movement Item", {"asset": d.asset})) > 1:
if frappe.db.exists("Asset Depreciation Schedule", {"asset": d.asset}):
asset_depr_schedule_doc = frappe.get_doc("Asset Depreciation Schedule", {"asset":d.asset})
update_depreciation_schedule(d.asset, asset_depr_schedule_doc.name, self.transaction_date)
make_depreciation_entry(asset_depr_schedule_doc.name)

frappe.db.set_value("Asset Depreciation Schedule",
asset_depr_schedule_doc.name,
"custom_cost_center",
custom_target_cost_center,
update_modified=True)

for original_field in field_mapping.values():
frappe.db.set_value("Asset Depreciation Schedule",
asset_depr_schedule_doc.name,
original_field,
current_values[original_field],
"custom_cost_center",
custom_target_cost_center,
update_modified=True)

for original_field in field_mapping.values():
frappe.db.set_value("Asset Depreciation Schedule",
asset_depr_schedule_doc.name,
original_field,
current_values[original_field],
update_modified=True)

if current_location and current_employee:
add_asset_activity(
d.asset,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.off("Asset Value Adjustment", "setup");
frappe.ui.form.on("Asset Value Adjustment", {
new_asset_value: function (frm) {
Expand Down Expand Up @@ -34,6 +32,10 @@ frappe.ui.form.on("Asset Value Adjustment", {
},

asset: function (frm) {
frm.trigger("set_acc_dimenstion");
},

set_acc_dimenstion: function (frm) {
if (frm.doc.asset) {
frm.call({
method: "asset_customizations.asset_modification.customizations.asset_value_adjustment.asset_value_adjustment_override.value_of_accounting_dimension",
Expand All @@ -47,6 +49,17 @@ frappe.ui.form.on("Asset Value Adjustment", {
// // }
// },
});
}else {
frappe.db.get_list("Accounting Dimension", {
fields: ["fieldname"]
}).then(fields => {
console.log(fields);
fields.forEach(field => {
frm.set_value(field.fieldname, null);
});
});
frm.set_value("cost_center", null)
frm.set_value("current_asset_value", null)
}
},
}
});
Loading