mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 20:59:11 +00:00
fix(Sales Invoice): Fix GL Entry creation for Return Invoices linked with Assets
This commit is contained in:
@@ -13,7 +13,7 @@ from erpnext.accounts.utils import get_account_currency
|
|||||||
from erpnext.stock.doctype.delivery_note.delivery_note import update_billed_amount_based_on_so
|
from erpnext.stock.doctype.delivery_note.delivery_note import update_billed_amount_based_on_so
|
||||||
from erpnext.projects.doctype.timesheet.timesheet import get_projectwise_timesheet_data
|
from erpnext.projects.doctype.timesheet.timesheet import get_projectwise_timesheet_data
|
||||||
from erpnext.assets.doctype.asset.depreciation \
|
from erpnext.assets.doctype.asset.depreciation \
|
||||||
import get_disposal_account_and_cost_center, get_gl_entries_on_asset_disposal
|
import get_disposal_account_and_cost_center, get_gl_entries_on_asset_movement
|
||||||
from erpnext.stock.doctype.batch.batch import set_batch_nos
|
from erpnext.stock.doctype.batch.batch import set_batch_nos
|
||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos, get_delivery_note_serial_no
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos, get_delivery_note_serial_no
|
||||||
from erpnext.setup.doctype.company.company import update_company_current_month_sales
|
from erpnext.setup.doctype.company.company import update_company_current_month_sales
|
||||||
@@ -928,8 +928,12 @@ class SalesInvoice(SellingController):
|
|||||||
frappe.throw(_("Select finance book for the item {0} at row {1}")
|
frappe.throw(_("Select finance book for the item {0} at row {1}")
|
||||||
.format(item.item_code, item.idx))
|
.format(item.item_code, item.idx))
|
||||||
|
|
||||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset,
|
if self.is_return:
|
||||||
item.base_net_amount, item.finance_book)
|
fixed_asset_gl_entries = get_gl_entries_on_asset_movement(asset,
|
||||||
|
item.base_net_amount, item.finance_book, True)
|
||||||
|
else:
|
||||||
|
fixed_asset_gl_entries = get_gl_entries_on_asset_movement(asset,
|
||||||
|
item.base_net_amount, item.finance_book)
|
||||||
|
|
||||||
for gle in fixed_asset_gl_entries:
|
for gle in fixed_asset_gl_entries:
|
||||||
gle["against"] = self.customer
|
gle["against"] = self.customer
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ def scrap_asset(asset_name):
|
|||||||
je.company = asset.company
|
je.company = asset.company
|
||||||
je.remark = "Scrap Entry for asset {0}".format(asset_name)
|
je.remark = "Scrap Entry for asset {0}".format(asset_name)
|
||||||
|
|
||||||
for entry in get_gl_entries_on_asset_disposal(asset):
|
for entry in get_gl_entries_on_asset_movement(asset):
|
||||||
entry.update({
|
entry.update({
|
||||||
"reference_type": "Asset",
|
"reference_type": "Asset",
|
||||||
"reference_name": asset_name
|
"reference_name": asset_name
|
||||||
@@ -177,7 +177,7 @@ def restore_asset(asset_name):
|
|||||||
asset.set_status()
|
asset.set_status()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_gl_entries_on_asset_disposal(asset, selling_amount=0, finance_book=None):
|
def get_gl_entries_on_asset_movement(asset, selling_amount=0, finance_book=None, is_return = False):
|
||||||
fixed_asset_account, accumulated_depr_account, depr_expense_account = get_depreciation_accounts(asset)
|
fixed_asset_account, accumulated_depr_account, depr_expense_account = get_depreciation_accounts(asset)
|
||||||
disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company)
|
disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company)
|
||||||
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
||||||
@@ -193,6 +193,44 @@ def get_gl_entries_on_asset_disposal(asset, selling_amount=0, finance_book=None)
|
|||||||
if asset.calculate_depreciation else asset.value_after_depreciation)
|
if asset.calculate_depreciation else asset.value_after_depreciation)
|
||||||
accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(value_after_depreciation)
|
accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(value_after_depreciation)
|
||||||
|
|
||||||
|
if is_return:
|
||||||
|
gl_entries = get_gl_entries_on_asset_regain(fixed_asset_account, asset, depreciation_cost_center, accumulated_depr_account, accumulated_depr_amount)
|
||||||
|
profit_amount = abs(flt(value_after_depreciation)) - abs(flt(selling_amount))
|
||||||
|
|
||||||
|
else:
|
||||||
|
gl_entries = get_gl_entries_on_asset_disposal(fixed_asset_account, asset, depreciation_cost_center, accumulated_depr_account, accumulated_depr_amount)
|
||||||
|
profit_amount = flt(selling_amount) - flt(value_after_depreciation)
|
||||||
|
|
||||||
|
if profit_amount:
|
||||||
|
debit_or_credit = "debit" if profit_amount < 0 else "credit"
|
||||||
|
gl_entries.append({
|
||||||
|
"account": disposal_account,
|
||||||
|
"cost_center": depreciation_cost_center,
|
||||||
|
debit_or_credit: abs(profit_amount),
|
||||||
|
debit_or_credit + "_in_account_currency": abs(profit_amount)
|
||||||
|
})
|
||||||
|
|
||||||
|
return gl_entries
|
||||||
|
|
||||||
|
def get_gl_entries_on_asset_regain(fixed_asset_account, asset, depreciation_cost_center, accumulated_depr_account, accumulated_depr_amount):
|
||||||
|
gl_entries = [
|
||||||
|
{
|
||||||
|
"account": fixed_asset_account,
|
||||||
|
"debit_in_account_currency": asset.gross_purchase_amount,
|
||||||
|
"debit": asset.gross_purchase_amount,
|
||||||
|
"cost_center": depreciation_cost_center
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": accumulated_depr_account,
|
||||||
|
"credit_in_account_currency": accumulated_depr_amount,
|
||||||
|
"credit": accumulated_depr_amount,
|
||||||
|
"cost_center": depreciation_cost_center
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return gl_entries
|
||||||
|
|
||||||
|
def get_gl_entries_on_asset_disposal(fixed_asset_account, asset, depreciation_cost_center, accumulated_depr_account, accumulated_depr_amount):
|
||||||
gl_entries = [
|
gl_entries = [
|
||||||
{
|
{
|
||||||
"account": fixed_asset_account,
|
"account": fixed_asset_account,
|
||||||
@@ -208,16 +246,6 @@ def get_gl_entries_on_asset_disposal(asset, selling_amount=0, finance_book=None)
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
profit_amount = flt(selling_amount) - flt(value_after_depreciation)
|
|
||||||
if profit_amount:
|
|
||||||
debit_or_credit = "debit" if profit_amount < 0 else "credit"
|
|
||||||
gl_entries.append({
|
|
||||||
"account": disposal_account,
|
|
||||||
"cost_center": depreciation_cost_center,
|
|
||||||
debit_or_credit: abs(profit_amount),
|
|
||||||
debit_or_credit + "_in_account_currency": abs(profit_amount)
|
|
||||||
})
|
|
||||||
|
|
||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
Reference in New Issue
Block a user