def make_depreciation_entry(self): asset = frappe.get_doc("Asset", self.asset) ( fixed_asset_account, accumulated_depreciation_account, depreciation_expense_account, ) = get_depreciation_accounts(asset) depreciation_cost_center, depreciation_series = frappe.get_cached_value( "Company", asset.company, ["depreciation_cost_center", "series_for_depreciation_entry"]) je = frappe.new_doc("Journal Entry") je.voucher_type = "Depreciation Entry" je.naming_series = depreciation_series je.posting_date = self.date je.company = self.company je.remark = "Depreciation Entry against {0} worth {1}".format( self.asset, self.difference_amount) je.finance_book = self.finance_book credit_entry = { "account": accumulated_depreciation_account, "credit_in_account_currency": self.difference_amount, "cost_center": depreciation_cost_center or self.cost_center, } debit_entry = { "account": depreciation_expense_account, "debit_in_account_currency": self.difference_amount, "cost_center": depreciation_cost_center or self.cost_center, } accounting_dimensions = get_checks_for_pl_and_bs_accounts() for dimension in accounting_dimensions: if dimension.get("mandatory_for_bs"): credit_entry.update({ dimension["fieldname"]: self.get(dimension["fieldname"]) or dimension.get("default_dimension") }) if dimension.get("mandatory_for_pl"): debit_entry.update({ dimension["fieldname"]: self.get(dimension["fieldname"]) or dimension.get("default_dimension") }) je.append("accounts", credit_entry) je.append("accounts", debit_entry) je.flags.ignore_permissions = True je.submit() self.db_set("journal_entry", je.name)
def validate_dimensions_for_pl_and_bs(self): account_type = frappe.db.get_value("Account", self.account, "report_type") for dimension in get_checks_for_pl_and_bs_accounts(): if account_type == "Profit and Loss" \ and self.company == dimension.company and dimension.mandatory_for_pl and not dimension.disabled: if not self.get(dimension.fieldname): frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Profit and Loss' account {1}.") .format(dimension.label, self.account)) if account_type == "Balance Sheet" \ and self.company == dimension.company and dimension.mandatory_for_bs and not dimension.disabled: if not self.get(dimension.fieldname): frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Balance Sheet' account {1}.") .format(dimension.label, self.account))
def make_depreciation_entry(asset_name, date=None): frappe.has_permission('Journal Entry', throw=True) if not date: date = today() asset = frappe.get_doc("Asset", asset_name) fixed_asset_account, accumulated_depreciation_account, depreciation_expense_account = \ get_depreciation_accounts(asset) depreciation_cost_center, depreciation_series = frappe.get_cached_value('Company', asset.company, ["depreciation_cost_center", "series_for_depreciation_entry"]) depreciation_cost_center = asset.cost_center or depreciation_cost_center accounting_dimensions = get_checks_for_pl_and_bs_accounts() for d in asset.get("schedules"): if not d.journal_entry and getdate(d.schedule_date) <= getdate(date): je = frappe.new_doc("Journal Entry") je.voucher_type = "Depreciation Entry" je.naming_series = depreciation_series je.posting_date = d.schedule_date je.company = asset.company je.finance_book = d.finance_book je.remark = "Depreciation Entry against {0} worth {1}".format(asset_name, d.depreciation_amount) credit_entry = { "account": accumulated_depreciation_account, "credit_in_account_currency": d.depreciation_amount, "reference_type": "Asset", "reference_name": asset.name } debit_entry = { "account": depreciation_expense_account, "debit_in_account_currency": d.depreciation_amount, "reference_type": "Asset", "reference_name": asset.name, "cost_center": depreciation_cost_center } for dimension in accounting_dimensions: if (asset.get(dimension['fieldname']) or dimension.get('mandatory_for_bs')): credit_entry.update({ dimension['fieldname']: asset.get(dimension['fieldname']) or dimension.get('default_dimension') }) if (asset.get(dimension['fieldname']) or dimension.get('mandatory_for_pl')): debit_entry.update({ dimension['fieldname']: asset.get(dimension['fieldname']) or dimension.get('default_dimension') }) je.append("accounts", credit_entry) je.append("accounts", debit_entry) je.flags.ignore_permissions = True je.save() if not je.meta.get_workflow(): je.submit() d.db_set("journal_entry", je.name) idx = cint(d.finance_book_id) finance_books = asset.get('finance_books')[idx - 1] finance_books.value_after_depreciation -= d.depreciation_amount finance_books.db_update() asset.set_status() return asset