def execute(filters=None): finyrfrom, finyrto = get_fiscal_year(fiscal_year=filters["fiscal_year"])[1:] data = get_report_data( financial_year_from=str(finyrfrom), financial_year_to=str(finyrto), company=filters["company"], expand_levels=filters.expand_levels, ) columns = get_report_columns(financial_year_from=finyrfrom, financial_year_to=finyrto) return columns, data
def post_journal_entry(self): from fa_depreciation.fixed_asset_depreciation.doctype.fixed_asset_account.fixed_asset_account import validate_default_accounts validate_default_accounts(self.company) self.financial_year_from, self.financial_year_to =\ get_fiscal_year(fiscal_year = self.fiscal_year)[1:] day_before_start = self.financial_year_from - timedelta (days=1) jv = frappe.new_doc('Journal Entry') jv.voucher_type = 'Journal Entry' jv.company = self.company jv.posting_date = self.financial_year_to jv.user_remark = 'Fixed Asset Closing Entry' default_depreciation_account = frappe.get_doc("Company", self.company).\ default_depreciation_expense_account total_depreciation = 0 for assets in self.get_assets(): fixed_asset_name = assets.fixed_asset_name data = get_report_data(str(self.financial_year_from), str(self.financial_year_to), \ self.company, fixed_asset_name) total_depreciation_for_year = flt(data[0]["total_depreciation_for_current_year"],2) total_depreciation = total_depreciation + total_depreciation_for_year depr_provided_till_last_year = flt(data[0]["opening_depreciation"],2) account = frappe.get_doc("Fixed Asset Account", fixed_asset_name) dep = account.append("depreciation") dep.fiscal_year = self.fiscal_year dep.total_accumulated_depreciation = total_depreciation_for_year +\ depr_provided_till_last_year account.save() td1 = jv.append("accounts") td1.account = default_depreciation_account td1.set('debit_in_account_currency', flt(total_depreciation_for_year,2)) td1.against_fixed_asset = fixed_asset_name td2 = jv.append("accounts") td2.account = frappe.get_doc("Company", self.company).default_accumulated_depreciation_account td2.set('credit_in_account_currency', flt(total_depreciation,2)) #jv.insert() #jv.submit() return jv