mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-06 23:10:26 +00:00
Merge pull request #49016 from frappe/version-15-hotfix
This commit is contained in:
@@ -13,7 +13,7 @@ def get():
|
|||||||
_("Bank Accounts"): {"account_type": "Bank", "is_group": 1},
|
_("Bank Accounts"): {"account_type": "Bank", "is_group": 1},
|
||||||
_("Cash In Hand"): {_("Cash"): {"account_type": "Cash"}, "account_type": "Cash"},
|
_("Cash In Hand"): {_("Cash"): {"account_type": "Cash"}, "account_type": "Cash"},
|
||||||
_("Loans and Advances (Assets)"): {
|
_("Loans and Advances (Assets)"): {
|
||||||
_("Employee Advances"): {},
|
_("Employee Advances"): {"account_type": "Payable"},
|
||||||
},
|
},
|
||||||
_("Securities and Deposits"): {_("Earnest Money"): {}},
|
_("Securities and Deposits"): {_("Earnest Money"): {}},
|
||||||
_("Stock Assets"): {
|
_("Stock Assets"): {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def get():
|
|||||||
"account_number": "1100",
|
"account_number": "1100",
|
||||||
},
|
},
|
||||||
_("Loans and Advances (Assets)"): {
|
_("Loans and Advances (Assets)"): {
|
||||||
_("Employee Advances"): {"account_number": "1610"},
|
_("Employee Advances"): {"account_number": "1610", "account_type": "Payable"},
|
||||||
"account_number": "1600",
|
"account_number": "1600",
|
||||||
},
|
},
|
||||||
_("Securities and Deposits"): {
|
_("Securities and Deposits"): {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
from erpnext.accounts.utils import update_voucher_outstanding
|
from erpnext.accounts.utils import get_advance_payment_doctypes, update_voucher_outstanding
|
||||||
|
|
||||||
|
|
||||||
class AdvancePaymentLedgerEntry(Document):
|
class AdvancePaymentLedgerEntry(Document):
|
||||||
@@ -29,7 +29,7 @@ class AdvancePaymentLedgerEntry(Document):
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
if (
|
if (
|
||||||
self.against_voucher_type in ["Purchase Order", "Sales Order"]
|
self.against_voucher_type in get_advance_payment_doctypes()
|
||||||
and self.flags.update_outstanding == "Yes"
|
and self.flags.update_outstanding == "Yes"
|
||||||
and not frappe.flags.is_reverse_depr_entry
|
and not frappe.flags.is_reverse_depr_entry
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -470,7 +470,6 @@ def reconcile_against_document(
|
|||||||
reconciled_entries[(row.voucher_type, row.voucher_no)] = []
|
reconciled_entries[(row.voucher_type, row.voucher_no)] = []
|
||||||
|
|
||||||
reconciled_entries[(row.voucher_type, row.voucher_no)].append(row)
|
reconciled_entries[(row.voucher_type, row.voucher_no)].append(row)
|
||||||
|
|
||||||
for key, entries in reconciled_entries.items():
|
for key, entries in reconciled_entries.items():
|
||||||
voucher_type, voucher_no = key
|
voucher_type, voucher_no = key
|
||||||
|
|
||||||
@@ -1805,6 +1804,7 @@ def get_payment_ledger_entries(gl_entries, cancel=0):
|
|||||||
|
|
||||||
dr_or_cr = 0
|
dr_or_cr = 0
|
||||||
account_type = None
|
account_type = None
|
||||||
|
|
||||||
for gle in gl_entries:
|
for gle in gl_entries:
|
||||||
if gle.account in receivable_or_payable_accounts:
|
if gle.account in receivable_or_payable_accounts:
|
||||||
account_type = get_account_type(gle.account)
|
account_type = get_account_type(gle.account)
|
||||||
@@ -1909,7 +1909,7 @@ def update_voucher_outstanding(voucher_type, voucher_no, account, party_type, pa
|
|||||||
if not voucher_type or not voucher_no:
|
if not voucher_type or not voucher_no:
|
||||||
return
|
return
|
||||||
|
|
||||||
if voucher_type in ["Purchase Order", "Sales Order"]:
|
if voucher_type in get_advance_payment_doctypes():
|
||||||
ref_doc = frappe.get_lazy_doc(voucher_type, voucher_no)
|
ref_doc = frappe.get_lazy_doc(voucher_type, voucher_no)
|
||||||
ref_doc.set_total_advance_paid()
|
ref_doc.set_total_advance_paid()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -31,6 +31,91 @@ def execute(filters=None):
|
|||||||
return columns, data, None, chart
|
return columns, data, None, chart
|
||||||
|
|
||||||
|
|
||||||
|
def get_data(filters):
|
||||||
|
data = []
|
||||||
|
|
||||||
|
conditions = get_conditions(filters)
|
||||||
|
pr_supplier_map = get_purchase_receipt_supplier_map()
|
||||||
|
pi_supplier_map = get_purchase_invoice_supplier_map()
|
||||||
|
|
||||||
|
assets_linked_to_fb = get_assets_linked_to_fb(filters)
|
||||||
|
|
||||||
|
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
||||||
|
|
||||||
|
if filters.include_default_book_assets and company_fb:
|
||||||
|
finance_book = company_fb
|
||||||
|
elif filters.finance_book:
|
||||||
|
finance_book = filters.finance_book
|
||||||
|
else:
|
||||||
|
finance_book = None
|
||||||
|
|
||||||
|
depreciation_amount_map = get_asset_depreciation_amount_map(filters, finance_book)
|
||||||
|
|
||||||
|
revaluation_amount_map = get_asset_value_adjustment_map(filters, finance_book)
|
||||||
|
|
||||||
|
group_by = frappe.scrub(filters.get("group_by"))
|
||||||
|
|
||||||
|
if group_by in ("asset_category", "location"):
|
||||||
|
data = get_group_by_data(
|
||||||
|
group_by, conditions, assets_linked_to_fb, depreciation_amount_map, revaluation_amount_map
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
"name as asset_id",
|
||||||
|
"asset_name",
|
||||||
|
"status",
|
||||||
|
"department",
|
||||||
|
"company",
|
||||||
|
"cost_center",
|
||||||
|
"calculate_depreciation",
|
||||||
|
"purchase_receipt",
|
||||||
|
"asset_category",
|
||||||
|
"purchase_date",
|
||||||
|
"gross_purchase_amount",
|
||||||
|
"location",
|
||||||
|
"available_for_use_date",
|
||||||
|
"purchase_invoice",
|
||||||
|
"opening_accumulated_depreciation",
|
||||||
|
]
|
||||||
|
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
||||||
|
|
||||||
|
for asset in assets_record:
|
||||||
|
if assets_linked_to_fb and asset.calculate_depreciation and asset.asset_id not in assets_linked_to_fb:
|
||||||
|
continue
|
||||||
|
|
||||||
|
depreciation_amount = depreciation_amount_map.get(asset.asset_id) or 0.0
|
||||||
|
revaluation_amount = revaluation_amount_map.get(asset.asset_id, 0.0)
|
||||||
|
asset_value = (
|
||||||
|
asset.gross_purchase_amount
|
||||||
|
- asset.opening_accumulated_depreciation
|
||||||
|
- depreciation_amount
|
||||||
|
+ revaluation_amount
|
||||||
|
)
|
||||||
|
|
||||||
|
row = {
|
||||||
|
"asset_id": asset.asset_id,
|
||||||
|
"asset_name": asset.asset_name,
|
||||||
|
"status": asset.status,
|
||||||
|
"department": asset.department,
|
||||||
|
"cost_center": asset.cost_center,
|
||||||
|
"vendor_name": pr_supplier_map.get(asset.purchase_receipt)
|
||||||
|
or pi_supplier_map.get(asset.purchase_invoice),
|
||||||
|
"gross_purchase_amount": asset.gross_purchase_amount,
|
||||||
|
"opening_accumulated_depreciation": asset.opening_accumulated_depreciation,
|
||||||
|
"depreciated_amount": depreciation_amount,
|
||||||
|
"available_for_use_date": asset.available_for_use_date,
|
||||||
|
"location": asset.location,
|
||||||
|
"asset_category": asset.asset_category,
|
||||||
|
"purchase_date": asset.purchase_date,
|
||||||
|
"asset_value": asset_value,
|
||||||
|
"company": asset.company,
|
||||||
|
}
|
||||||
|
data.append(row)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_conditions(filters):
|
||||||
conditions = {"docstatus": 1}
|
conditions = {"docstatus": 1}
|
||||||
status = filters.status
|
status = filters.status
|
||||||
@@ -76,83 +161,6 @@ def get_conditions(filters):
|
|||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
|
||||||
def get_data(filters):
|
|
||||||
data = []
|
|
||||||
|
|
||||||
conditions = get_conditions(filters)
|
|
||||||
pr_supplier_map = get_purchase_receipt_supplier_map()
|
|
||||||
pi_supplier_map = get_purchase_invoice_supplier_map()
|
|
||||||
|
|
||||||
assets_linked_to_fb = get_assets_linked_to_fb(filters)
|
|
||||||
|
|
||||||
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
|
||||||
|
|
||||||
if filters.include_default_book_assets and company_fb:
|
|
||||||
finance_book = company_fb
|
|
||||||
elif filters.finance_book:
|
|
||||||
finance_book = filters.finance_book
|
|
||||||
else:
|
|
||||||
finance_book = None
|
|
||||||
|
|
||||||
depreciation_amount_map = get_asset_depreciation_amount_map(filters, finance_book)
|
|
||||||
|
|
||||||
group_by = frappe.scrub(filters.get("group_by"))
|
|
||||||
|
|
||||||
if group_by in ("asset_category", "location"):
|
|
||||||
data = get_group_by_data(group_by, conditions, assets_linked_to_fb, depreciation_amount_map)
|
|
||||||
return data
|
|
||||||
|
|
||||||
fields = [
|
|
||||||
"name as asset_id",
|
|
||||||
"asset_name",
|
|
||||||
"status",
|
|
||||||
"department",
|
|
||||||
"company",
|
|
||||||
"cost_center",
|
|
||||||
"calculate_depreciation",
|
|
||||||
"purchase_receipt",
|
|
||||||
"asset_category",
|
|
||||||
"purchase_date",
|
|
||||||
"gross_purchase_amount",
|
|
||||||
"location",
|
|
||||||
"available_for_use_date",
|
|
||||||
"purchase_invoice",
|
|
||||||
"opening_accumulated_depreciation",
|
|
||||||
]
|
|
||||||
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
|
||||||
|
|
||||||
for asset in assets_record:
|
|
||||||
if assets_linked_to_fb and asset.calculate_depreciation and asset.asset_id not in assets_linked_to_fb:
|
|
||||||
continue
|
|
||||||
|
|
||||||
depreciation_amount = depreciation_amount_map.get(asset.asset_id) or 0.0
|
|
||||||
asset_value = (
|
|
||||||
asset.gross_purchase_amount - asset.opening_accumulated_depreciation - depreciation_amount
|
|
||||||
)
|
|
||||||
|
|
||||||
row = {
|
|
||||||
"asset_id": asset.asset_id,
|
|
||||||
"asset_name": asset.asset_name,
|
|
||||||
"status": asset.status,
|
|
||||||
"department": asset.department,
|
|
||||||
"cost_center": asset.cost_center,
|
|
||||||
"vendor_name": pr_supplier_map.get(asset.purchase_receipt)
|
|
||||||
or pi_supplier_map.get(asset.purchase_invoice),
|
|
||||||
"gross_purchase_amount": asset.gross_purchase_amount,
|
|
||||||
"opening_accumulated_depreciation": asset.opening_accumulated_depreciation,
|
|
||||||
"depreciated_amount": depreciation_amount,
|
|
||||||
"available_for_use_date": asset.available_for_use_date,
|
|
||||||
"location": asset.location,
|
|
||||||
"asset_category": asset.asset_category,
|
|
||||||
"purchase_date": asset.purchase_date,
|
|
||||||
"asset_value": asset_value,
|
|
||||||
"company": asset.company,
|
|
||||||
}
|
|
||||||
data.append(row)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_chart_data(data, filters):
|
def prepare_chart_data(data, filters):
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
@@ -290,7 +298,59 @@ def get_asset_depreciation_amount_map(filters, finance_book):
|
|||||||
return dict(asset_depr_amount_map)
|
return dict(asset_depr_amount_map)
|
||||||
|
|
||||||
|
|
||||||
def get_group_by_data(group_by, conditions, assets_linked_to_fb, depreciation_amount_map):
|
def get_asset_value_adjustment_map(filters, finance_book):
|
||||||
|
start_date = filters.from_date if filters.filter_based_on == "Date Range" else filters.year_start_date
|
||||||
|
end_date = filters.to_date if filters.filter_based_on == "Date Range" else filters.year_end_date
|
||||||
|
|
||||||
|
asset = frappe.qb.DocType("Asset")
|
||||||
|
gle = frappe.qb.DocType("GL Entry")
|
||||||
|
aca = frappe.qb.DocType("Asset Category Account")
|
||||||
|
company = frappe.qb.DocType("Company")
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(gle)
|
||||||
|
.join(asset)
|
||||||
|
.on(gle.against_voucher == asset.name)
|
||||||
|
.join(aca)
|
||||||
|
.on((aca.parent == asset.asset_category) & (aca.company_name == asset.company))
|
||||||
|
.join(company)
|
||||||
|
.on(company.name == asset.company)
|
||||||
|
.select(asset.name.as_("asset"), Sum(gle.debit - gle.credit).as_("adjustment_amount"))
|
||||||
|
.where(gle.account == aca.fixed_asset_account)
|
||||||
|
.where(gle.is_cancelled == 0)
|
||||||
|
.where(company.name == filters.company)
|
||||||
|
.where(asset.docstatus == 1)
|
||||||
|
)
|
||||||
|
|
||||||
|
if filters.only_existing_assets:
|
||||||
|
query = query.where(asset.is_existing_asset == 1)
|
||||||
|
if filters.asset_category:
|
||||||
|
query = query.where(asset.asset_category == filters.asset_category)
|
||||||
|
if filters.cost_center:
|
||||||
|
query = query.where(asset.cost_center == filters.cost_center)
|
||||||
|
if filters.status:
|
||||||
|
if filters.status == "In Location":
|
||||||
|
query = query.where(asset.status.notin(["Sold", "Scrapped", "Capitalized"]))
|
||||||
|
else:
|
||||||
|
query = query.where(asset.status.isin(["Sold", "Scrapped", "Capitalized"]))
|
||||||
|
if finance_book:
|
||||||
|
query = query.where((gle.finance_book.isin([cstr(finance_book), ""])) | (gle.finance_book.isnull()))
|
||||||
|
else:
|
||||||
|
query = query.where((gle.finance_book.isin([""])) | (gle.finance_book.isnull()))
|
||||||
|
if filters.filter_based_on in ("Date Range", "Fiscal Year"):
|
||||||
|
query = query.where(gle.posting_date >= start_date)
|
||||||
|
query = query.where(gle.posting_date <= end_date)
|
||||||
|
|
||||||
|
query = query.groupby(asset.name)
|
||||||
|
|
||||||
|
asset_adjustment_map = query.run()
|
||||||
|
|
||||||
|
return dict(asset_adjustment_map)
|
||||||
|
|
||||||
|
|
||||||
|
def get_group_by_data(
|
||||||
|
group_by, conditions, assets_linked_to_fb, depreciation_amount_map, revaluation_amount_map
|
||||||
|
):
|
||||||
fields = [
|
fields = [
|
||||||
group_by,
|
group_by,
|
||||||
"name",
|
"name",
|
||||||
@@ -307,8 +367,12 @@ def get_group_by_data(group_by, conditions, assets_linked_to_fb, depreciation_am
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
a["depreciated_amount"] = depreciation_amount_map.get(a["name"], 0.0)
|
a["depreciated_amount"] = depreciation_amount_map.get(a["name"], 0.0)
|
||||||
|
a["revaluation_amount"] = revaluation_amount_map.get(a["name"], 0.0)
|
||||||
a["asset_value"] = (
|
a["asset_value"] = (
|
||||||
a["gross_purchase_amount"] - a["opening_accumulated_depreciation"] - a["depreciated_amount"]
|
a["gross_purchase_amount"]
|
||||||
|
- a["opening_accumulated_depreciation"]
|
||||||
|
- a["depreciated_amount"]
|
||||||
|
+ a["revaluation_amount"]
|
||||||
)
|
)
|
||||||
|
|
||||||
del a["name"]
|
del a["name"]
|
||||||
|
|||||||
@@ -29,4 +29,4 @@ def execute():
|
|||||||
|
|
||||||
if docs:
|
if docs:
|
||||||
cancel_incorrect_gl_entries([d.name for d in docs])
|
cancel_incorrect_gl_entries([d.name for d in docs])
|
||||||
recreate_gl_entries([d.voucher_no for d in docs])
|
recreate_gl_entries([d.voucher_no for d in docs])
|
||||||
|
|||||||
Reference in New Issue
Block a user