mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-23 23:19:20 +00:00
feat(Asset Repair): Add total_repair_cost field
This commit is contained in:
@@ -28,7 +28,7 @@ frappe.ui.form.on('Asset Repair', {
|
|||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
frm.toggle_display(['completion_date', 'repair_status', 'accounting_details', 'accounting_dimensions_section'], !(frm.doc.__islocal));
|
frm.toggle_display(['completion_date', 'repair_status', 'accounting_details', 'accounting_dimensions_section'], !(frm.doc.__islocal));
|
||||||
frm.toggle_display(['stock_consumption_details_section'], frm.doc.stock_consumption)
|
frm.toggle_display(['stock_consumption_details_section', 'total_repair_cost'], frm.doc.stock_consumption)
|
||||||
|
|
||||||
if (frm.doc.docstatus) {
|
if (frm.doc.docstatus) {
|
||||||
frm.add_custom_button("View General Ledger", function() {
|
frm.add_custom_button("View General Ledger", function() {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"stock_consumption",
|
"stock_consumption",
|
||||||
"column_break_8",
|
"column_break_8",
|
||||||
"payable_account",
|
"payable_account",
|
||||||
|
"total_repair_cost",
|
||||||
"stock_consumption_details_section",
|
"stock_consumption_details_section",
|
||||||
"stock_items",
|
"stock_items",
|
||||||
"section_break_9",
|
"section_break_9",
|
||||||
@@ -205,12 +206,17 @@
|
|||||||
"fieldname": "stock_consumption_details_section",
|
"fieldname": "stock_consumption_details_section",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Stock Consumption Details"
|
"label": "Stock Consumption Details"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "total_repair_cost",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Total Repair Cost"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-12 21:20:18.276755",
|
"modified": "2021-05-13 02:40:57.953076",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset Repair",
|
"name": "Asset Repair",
|
||||||
|
|||||||
@@ -16,18 +16,31 @@ class AssetRepair(Document):
|
|||||||
frappe.throw(_("Please select Completion Date for Completed Repair"))
|
frappe.throw(_("Please select Completion Date for Completed Repair"))
|
||||||
|
|
||||||
self.update_status()
|
self.update_status()
|
||||||
self.set_total_value()
|
self.set_total_value() # change later
|
||||||
|
self.check_stock_items()
|
||||||
def set_total_value(self):
|
self.calculate_total_repair_cost()
|
||||||
for item in self.stock_items:
|
|
||||||
item.total_value = flt(item.valuation_rate) * flt(item.consumed_quantity)
|
|
||||||
|
|
||||||
def update_status(self):
|
def update_status(self):
|
||||||
if self.repair_status == 'Pending':
|
if self.repair_status == 'Pending':
|
||||||
frappe.db.set_value('Asset', self.asset, 'status', 'Out of Order')
|
frappe.db.set_value('Asset', self.asset, 'status', 'Out of Order')
|
||||||
else:
|
else:
|
||||||
frappe.db.set_value('Asset', self.asset, 'status', 'Submitted')
|
frappe.db.set_value('Asset', self.asset, 'status', 'Submitted')
|
||||||
|
|
||||||
|
def set_total_value(self):
|
||||||
|
for item in self.stock_items:
|
||||||
|
item.total_value = flt(item.valuation_rate) * flt(item.consumed_quantity)
|
||||||
|
|
||||||
|
def check_stock_items(self):
|
||||||
|
if self.stock_consumption:
|
||||||
|
if not self.stock_items:
|
||||||
|
frappe.throw(_("Please enter Stock Items consumed during Asset Repair."))
|
||||||
|
|
||||||
|
def calculate_total_repair_cost(self):
|
||||||
|
self.total_repair_cost = self.repair_cost
|
||||||
|
if self.stock_consumption:
|
||||||
|
for item in self.stock_items:
|
||||||
|
self.total_repair_cost += item.total_value
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if self.repair_status == "Pending":
|
if self.repair_status == "Pending":
|
||||||
frappe.throw(_("Please update Repair Status."))
|
frappe.throw(_("Please update Repair Status."))
|
||||||
@@ -81,6 +94,41 @@ class AssetRepair(Document):
|
|||||||
"posting_date": getdate()
|
"posting_date": getdate()
|
||||||
})
|
})
|
||||||
gl_entry.insert()
|
gl_entry.insert()
|
||||||
|
|
||||||
|
# if self.capitalize_repair_cost:
|
||||||
|
# fixed_asset_account = self.get_fixed_asset_account()
|
||||||
|
# gl_entry = frappe.get_doc({
|
||||||
|
# "doctype": "GL Entry",
|
||||||
|
# "account": self.payable_account,
|
||||||
|
# "credit": self.total_repair_cost,
|
||||||
|
# "credit_in_account_currency": self.repair_cost,
|
||||||
|
# "against": repair_and_maintenance_account,
|
||||||
|
# "voucher_type": self.doctype,
|
||||||
|
# "voucher_no": self.name,
|
||||||
|
# "cost_center": self.cost_center,
|
||||||
|
# "posting_date": getdate()
|
||||||
|
# })
|
||||||
|
# gl_entry.insert()
|
||||||
|
# gl_entry = frappe.get_doc({
|
||||||
|
# "doctype": "GL Entry",
|
||||||
|
# "account": fixed_asset_account,
|
||||||
|
# "debit": self.total_repair_cost,
|
||||||
|
# "debit_in_account_currency": self.repair_cost,
|
||||||
|
# "against": self.payable_account,
|
||||||
|
# "voucher_type": self.doctype,
|
||||||
|
# "voucher_no": self.name,
|
||||||
|
# "cost_center": self.cost_center,
|
||||||
|
# "posting_date": getdate()
|
||||||
|
# })
|
||||||
|
# gl_entry.insert()
|
||||||
|
|
||||||
|
# def get_fixed_asset_account(self):
|
||||||
|
# asset_category = frappe.get_doc('Asset Category', frappe.db.get_value('Asset', self.asset, 'asset_category'))
|
||||||
|
# company = frappe.db.get_value('Asset', self.asset, 'company')
|
||||||
|
# for account in asset_category.accounts:
|
||||||
|
# if account.company_name == company:
|
||||||
|
# return account.fixed_asset_account
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_downtime(failure_date, completion_date):
|
def get_downtime(failure_date, completion_date):
|
||||||
|
|||||||
Reference in New Issue
Block a user