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
def journal_entry(self): self.PRECISION = 2 from fa_depreciation.fixed_asset_depreciation.doctype.fixed_asset_account.fixed_asset_account import validate_default_accounts validate_default_accounts(self.company) jv = frappe.new_doc('Journal Entry') jv.voucher_type = 'Journal Entry' jv.company = self.company jv.posting_date = self.posting_date jv.user_remark = 'Fixed Asset Sale' td1 = jv.append("accounts"); td1.account = frappe.db.get_value("Fixed Asset Account", self.fixed_asset_account,"fixed_asset_account") td1.set("credit_in_account_currency", flt(self.asset_purchase_cost,self.PRECISION)) td2 = jv.append("accounts") from erpnext.accounts.party import get_party_account td2.account = get_party_account('Customer',self.sold_to, self.company) td2.party = self.sold_to td2.party_type = 'Customer' td2.set('debit_in_account_currency', flt(self.sales_amount,self.PRECISION)) td5 = jv.append("accounts") td5.account = frappe.get_doc("Company", self.company).default_accumulated_depreciation_account td5.set('debit_in_account_currency', flt(self.accumulated_depreciation,self.PRECISION)) if self.profit_or_loss == "Loss": td3 = jv.append("accounts") td3.account = self.booking_account td3.set('debit_in_account_currency', flt(self.difference,self.PRECISION)) elif self.profit_or_loss == "Profit": td4 = jv.append("accounts") td4.account = self.booking_account td4.set('credit_in_account_currency', flt(self.difference,self.PRECISION)) jv.insert() jv.submit() self.journal_ref = jv.name self.db_update() return jv