diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 0980ddfa7f..d34970d16d 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -34,6 +34,7 @@ class AssetRepair(Document): frappe.throw(_("Please update Repair Status.")) self.increase_asset_value() + self.make_gl_entries() def increase_asset_value(self): if self.capitalize_repair_cost: @@ -45,64 +46,42 @@ class AssetRepair(Document): print(asset_value) frappe.db.set_value('Asset', self.asset, 'asset_value', asset_value) - # self.make_gl_entries() + def on_cancel(self): + if self.payable_account: + self.make_gl_entries(cancel=True) - # def on_cancel(self): - # if self.payable_account: - # self.make_gl_entries(cancel=True) + def make_gl_entries(self, cancel=False): + if flt(self.repair_cost) > 0: + gl_entries = self.get_gl_entries() + make_gl_entries(gl_entries, cancel) - # def make_gl_entries(self, cancel=False): - # if flt(self.repair_cost) > 0: - # gl_entries = self.get_gl_entries() - # make_gl_entries(gl_entries, cancel) + def get_gl_entries(self): + gl_entry = [] + company = frappe.db.get_value('Asset', self.asset, 'company') + repair_and_maintenance_account = frappe.db.get_value('Company', company, 'repair_and_maintenance_account') - # def get_gl_entries(self): - # gl_entry = [] - # company = frappe.db.get_value('Asset', self.asset, 'company') - # repair_and_maintenance_account = frappe.db.get_value('Company', company, 'repair_and_maintenance_account') - - # gl_entry = frappe.get_doc({ - # "doctype": "GL Entry", - # "account": self.payable_account, - # "credit": self.repair_cost, - # "credit_in_account_currency": self.repair_cost, - # "against": repair_and_maintenance_account, - # "voucher_type": self.doctype, - # "voucher_no": self.name - # }) - # gl_entry.insert() - # gl_entry = frappe.get_doc({ - # "doctype": "GL Entry", - # "account": repair_and_maintenance_account, - # "debit": self.repair_cost, - # "credit_in_account_currency": self.repair_cost, - # "against": self.payable_account, - # "voucher_type": self.doctype, - # "voucher_no": self.name - # }) - # gl_entry.insert() - - # gl_entry.append( - # self.get_gl_dict({ - # "account": self.payable_account, - # "credit": self.repair_cost, - # "credit_in_account_currency": self.repair_cost, - # "against": repair_and_maintenance_account, - # "against_voucher_type": self.doctype, - # "against_voucher": self.name - # }) - # ) - - # gl_entry.append( - # self.get_gl_dict({ - # "account": repair_and_maintenance_account, - # "debit": self.repair_cost, - # "credit_in_account_currency": self.repair_cost, - # "against": self.payable_account, - # "against_voucher_type": self.doctype, - # "against_voucher": self.name - # }) - # ) + gl_entry = frappe.get_doc({ + "doctype": "GL Entry", + "account": self.payable_account, + "credit": self.repair_cost, + "credit_in_account_currency": self.repair_cost, + "against": repair_and_maintenance_account, + "voucher_type": self.doctype, + "voucher_no": self.name, + "cost_center": "Main - F" + }) + gl_entry.insert() + gl_entry = frappe.get_doc({ + "doctype": "GL Entry", + "account": repair_and_maintenance_account, + "debit": self.repair_cost, + "debit_in_account_currency": self.repair_cost, + "against": self.payable_account, + "voucher_type": self.doctype, + "voucher_no": self.name, + "cost_center": "Main - F" + }) + gl_entry.insert() @frappe.whitelist() def get_downtime(failure_date, completion_date): diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 0bc85ea092..51757f584e 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -744,8 +744,9 @@ }, { "fieldname": "repair_and_maintenance_account", - "fieldtype": "Data", - "label": "Repair and Maintenance Account" + "fieldtype": "Link", + "label": "Repair and Maintenance Account", + "options": "Account" } ], "icon": "fa fa-building", @@ -753,7 +754,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2021-05-11 21:47:04.667950", + "modified": "2021-05-12 16:51:08.187233", "modified_by": "Administrator", "module": "Setup", "name": "Company",