mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
Merge pull request #33872 from frappe/version-13-hotfix
chore: release v13
This commit is contained in:
@@ -32,8 +32,8 @@ repos:
|
|||||||
- id: black
|
- id: black
|
||||||
additional_dependencies: ['click==8.0.4']
|
additional_dependencies: ['click==8.0.4']
|
||||||
|
|
||||||
- repo: https://github.com/timothycrosley/isort
|
- repo: https://github.com/PyCQA/isort
|
||||||
rev: 5.9.1
|
rev: 5.12.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
exclude: ".*setup.py$"
|
exclude: ".*setup.py$"
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class JournalEntry(AccountsController):
|
|||||||
self.check_credit_limit()
|
self.check_credit_limit()
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
self.update_advance_paid()
|
self.update_advance_paid()
|
||||||
|
self.update_asset_value()
|
||||||
self.update_expense_claim()
|
self.update_expense_claim()
|
||||||
self.update_inter_company_jv()
|
self.update_inter_company_jv()
|
||||||
self.update_invoice_discounting()
|
self.update_invoice_discounting()
|
||||||
@@ -235,6 +236,34 @@ class JournalEntry(AccountsController):
|
|||||||
for d in to_remove:
|
for d in to_remove:
|
||||||
self.remove(d)
|
self.remove(d)
|
||||||
|
|
||||||
|
def update_asset_value(self):
|
||||||
|
if self.voucher_type != "Depreciation Entry":
|
||||||
|
return
|
||||||
|
|
||||||
|
processed_assets = []
|
||||||
|
|
||||||
|
for d in self.get("accounts"):
|
||||||
|
if (
|
||||||
|
d.reference_type == "Asset" and d.reference_name and d.reference_name not in processed_assets
|
||||||
|
):
|
||||||
|
processed_assets.append(d.reference_name)
|
||||||
|
|
||||||
|
asset = frappe.db.get_value(
|
||||||
|
"Asset", d.reference_name, ["calculate_depreciation", "value_after_depreciation"], as_dict=1
|
||||||
|
)
|
||||||
|
|
||||||
|
if asset.calculate_depreciation:
|
||||||
|
continue
|
||||||
|
|
||||||
|
depr_value = d.debit or d.credit
|
||||||
|
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Asset",
|
||||||
|
d.reference_name,
|
||||||
|
"value_after_depreciation",
|
||||||
|
asset.value_after_depreciation - depr_value,
|
||||||
|
)
|
||||||
|
|
||||||
def update_inter_company_jv(self):
|
def update_inter_company_jv(self):
|
||||||
if (
|
if (
|
||||||
self.voucher_type == "Inter Company Journal Entry"
|
self.voucher_type == "Inter Company Journal Entry"
|
||||||
@@ -293,19 +322,39 @@ class JournalEntry(AccountsController):
|
|||||||
d.db_update()
|
d.db_update()
|
||||||
|
|
||||||
def unlink_asset_reference(self):
|
def unlink_asset_reference(self):
|
||||||
|
if self.voucher_type != "Depreciation Entry":
|
||||||
|
return
|
||||||
|
|
||||||
|
processed_assets = []
|
||||||
|
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
if d.reference_type == "Asset" and d.reference_name:
|
if (
|
||||||
|
d.reference_type == "Asset" and d.reference_name and d.reference_name not in processed_assets
|
||||||
|
):
|
||||||
|
processed_assets.append(d.reference_name)
|
||||||
|
|
||||||
asset = frappe.get_doc("Asset", d.reference_name)
|
asset = frappe.get_doc("Asset", d.reference_name)
|
||||||
for s in asset.get("schedules"):
|
|
||||||
if s.journal_entry == self.name:
|
|
||||||
s.db_set("journal_entry", None)
|
|
||||||
|
|
||||||
idx = cint(s.finance_book_id) or 1
|
if asset.calculate_depreciation:
|
||||||
finance_books = asset.get("finance_books")[idx - 1]
|
for s in asset.get("schedules"):
|
||||||
finance_books.value_after_depreciation += s.depreciation_amount
|
if s.journal_entry == self.name:
|
||||||
finance_books.db_update()
|
s.db_set("journal_entry", None)
|
||||||
|
|
||||||
asset.set_status()
|
idx = cint(s.finance_book_id) or 1
|
||||||
|
finance_books = asset.get("finance_books")[idx - 1]
|
||||||
|
finance_books.value_after_depreciation += s.depreciation_amount
|
||||||
|
finance_books.db_update()
|
||||||
|
|
||||||
|
asset.set_status()
|
||||||
|
else:
|
||||||
|
depr_value = d.debit or d.credit
|
||||||
|
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Asset",
|
||||||
|
d.reference_name,
|
||||||
|
"value_after_depreciation",
|
||||||
|
asset.value_after_depreciation + depr_value,
|
||||||
|
)
|
||||||
|
|
||||||
def unlink_inter_company_jv(self):
|
def unlink_inter_company_jv(self):
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -1255,6 +1255,7 @@ def get_outstanding_reference_documents(args):
|
|||||||
args.get("party_type"),
|
args.get("party_type"),
|
||||||
args.get("party"),
|
args.get("party"),
|
||||||
args.get("party_account"),
|
args.get("party_account"),
|
||||||
|
args.get("company"),
|
||||||
filters=args,
|
filters=args,
|
||||||
condition=condition,
|
condition=condition,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ class PaymentReconciliation(Document):
|
|||||||
condition += " and cost_center = '{0}' ".format(self.cost_center)
|
condition += " and cost_center = '{0}' ".format(self.cost_center)
|
||||||
|
|
||||||
non_reconciled_invoices = get_outstanding_invoices(
|
non_reconciled_invoices = get_outstanding_invoices(
|
||||||
self.party_type, self.party, self.receivable_payable_account, condition=condition
|
self.party_type, self.party, self.receivable_payable_account, self.company, condition=condition
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.invoice_limit:
|
if self.invoice_limit:
|
||||||
|
|||||||
@@ -1790,6 +1790,8 @@
|
|||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"fetch_from": "sales_partner.commission_rate",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "commission_rate",
|
"fieldname": "commission_rate",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"hide_days": 1,
|
"hide_days": 1,
|
||||||
@@ -2045,7 +2047,7 @@
|
|||||||
"link_fieldname": "consolidated_invoice"
|
"link_fieldname": "consolidated_invoice"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2022-09-16 17:44:22.227332",
|
"modified": "2023-01-28 19:45:47.538163",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Sales Invoice",
|
"name": "Sales Invoice",
|
||||||
|
|||||||
@@ -585,10 +585,35 @@ class GrossProfitGenerator(object):
|
|||||||
return self.calculate_buying_amount_from_sle(
|
return self.calculate_buying_amount_from_sle(
|
||||||
row, my_sle, parenttype, parent, item_row, item_code
|
row, my_sle, parenttype, parent, item_row, item_code
|
||||||
)
|
)
|
||||||
|
elif row.sales_order and row.so_detail:
|
||||||
|
incoming_amount = self.get_buying_amount_from_so_dn(row.sales_order, row.so_detail, item_code)
|
||||||
|
if incoming_amount:
|
||||||
|
return incoming_amount
|
||||||
else:
|
else:
|
||||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||||
|
|
||||||
return 0.0
|
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||||
|
|
||||||
|
def get_buying_amount_from_so_dn(self, sales_order, so_detail, item_code):
|
||||||
|
from frappe.query_builder.functions import Sum
|
||||||
|
|
||||||
|
delivery_note = frappe.qb.DocType("Delivery Note")
|
||||||
|
delivery_note_item = frappe.qb.DocType("Delivery Note Item")
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(delivery_note)
|
||||||
|
.inner_join(delivery_note_item)
|
||||||
|
.on(delivery_note.name == delivery_note_item.parent)
|
||||||
|
.select(Sum(delivery_note_item.incoming_rate * delivery_note_item.stock_qty))
|
||||||
|
.where(delivery_note.docstatus == 1)
|
||||||
|
.where(delivery_note_item.item_code == item_code)
|
||||||
|
.where(delivery_note_item.against_sales_order == sales_order)
|
||||||
|
.where(delivery_note_item.so_detail == so_detail)
|
||||||
|
.groupby(delivery_note_item.item_code)
|
||||||
|
)
|
||||||
|
|
||||||
|
incoming_amount = query.run()
|
||||||
|
return flt(incoming_amount[0][0]) if incoming_amount else 0
|
||||||
|
|
||||||
def get_average_buying_rate(self, row, item_code):
|
def get_average_buying_rate(self, row, item_code):
|
||||||
args = row
|
args = row
|
||||||
@@ -665,7 +690,8 @@ class GrossProfitGenerator(object):
|
|||||||
`tabSales Invoice`.territory, `tabSales Invoice Item`.item_code,
|
`tabSales Invoice`.territory, `tabSales Invoice Item`.item_code,
|
||||||
`tabSales Invoice Item`.item_name, `tabSales Invoice Item`.description,
|
`tabSales Invoice Item`.item_name, `tabSales Invoice Item`.description,
|
||||||
`tabSales Invoice Item`.warehouse, `tabSales Invoice Item`.item_group,
|
`tabSales Invoice Item`.warehouse, `tabSales Invoice Item`.item_group,
|
||||||
`tabSales Invoice Item`.brand, `tabSales Invoice Item`.dn_detail,
|
`tabSales Invoice Item`.brand, `tabSales Invoice Item`.so_detail,
|
||||||
|
`tabSales Invoice Item`.sales_order, `tabSales Invoice Item`.dn_detail,
|
||||||
`tabSales Invoice Item`.delivery_note, `tabSales Invoice Item`.stock_qty as qty,
|
`tabSales Invoice Item`.delivery_note, `tabSales Invoice Item`.stock_qty as qty,
|
||||||
`tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount,
|
`tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount,
|
||||||
`tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return,
|
`tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return,
|
||||||
|
|||||||
@@ -301,3 +301,82 @@ class TestGrossProfit(FrappeTestCase):
|
|||||||
|
|
||||||
columns, data = execute(filters=filters)
|
columns, data = execute(filters=filters)
|
||||||
self.assertGreater(len(data), 0)
|
self.assertGreater(len(data), 0)
|
||||||
|
|
||||||
|
def test_order_connected_dn_and_inv(self):
|
||||||
|
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||||
|
|
||||||
|
"""
|
||||||
|
Test gp calculation when invoice and delivery note aren't directly connected.
|
||||||
|
SO -- INV
|
||||||
|
|
|
||||||
|
DN
|
||||||
|
"""
|
||||||
|
se = make_stock_entry(
|
||||||
|
company=self.company,
|
||||||
|
item_code=self.item,
|
||||||
|
target=self.warehouse,
|
||||||
|
qty=3,
|
||||||
|
basic_rate=100,
|
||||||
|
do_not_submit=True,
|
||||||
|
)
|
||||||
|
item = se.items[0]
|
||||||
|
se.append(
|
||||||
|
"items",
|
||||||
|
{
|
||||||
|
"item_code": item.item_code,
|
||||||
|
"s_warehouse": item.s_warehouse,
|
||||||
|
"t_warehouse": item.t_warehouse,
|
||||||
|
"qty": 10,
|
||||||
|
"basic_rate": 200,
|
||||||
|
"conversion_factor": item.conversion_factor or 1.0,
|
||||||
|
"transfer_qty": flt(item.qty) * (flt(item.conversion_factor) or 1.0),
|
||||||
|
"serial_no": item.serial_no,
|
||||||
|
"batch_no": item.batch_no,
|
||||||
|
"cost_center": item.cost_center,
|
||||||
|
"expense_account": item.expense_account,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
se = se.save().submit()
|
||||||
|
|
||||||
|
so = make_sales_order(
|
||||||
|
customer=self.customer,
|
||||||
|
company=self.company,
|
||||||
|
warehouse=self.warehouse,
|
||||||
|
item=self.item,
|
||||||
|
qty=4,
|
||||||
|
do_not_save=False,
|
||||||
|
do_not_submit=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
from erpnext.selling.doctype.sales_order.sales_order import (
|
||||||
|
make_delivery_note,
|
||||||
|
make_sales_invoice,
|
||||||
|
)
|
||||||
|
|
||||||
|
make_delivery_note(so.name).submit()
|
||||||
|
sinv = make_sales_invoice(so.name).submit()
|
||||||
|
|
||||||
|
filters = frappe._dict(
|
||||||
|
company=self.company, from_date=nowdate(), to_date=nowdate(), group_by="Invoice"
|
||||||
|
)
|
||||||
|
|
||||||
|
columns, data = execute(filters=filters)
|
||||||
|
expected_entry = {
|
||||||
|
"parent_invoice": sinv.name,
|
||||||
|
"currency": "INR",
|
||||||
|
"sales_invoice": self.item,
|
||||||
|
"customer": self.customer,
|
||||||
|
"posting_date": frappe.utils.datetime.date.fromisoformat(nowdate()),
|
||||||
|
"item_code": self.item,
|
||||||
|
"item_name": self.item,
|
||||||
|
"warehouse": "Stores - _GP",
|
||||||
|
"qty": 4.0,
|
||||||
|
"avg._selling_rate": 100.0,
|
||||||
|
"valuation_rate": 125.0,
|
||||||
|
"selling_amount": 400.0,
|
||||||
|
"buying_amount": 500.0,
|
||||||
|
"gross_profit": -100.0,
|
||||||
|
"gross_profit_%": -25.0,
|
||||||
|
}
|
||||||
|
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
||||||
|
self.assertDictContainsSubset(expected_entry, gp_entry[0])
|
||||||
|
|||||||
@@ -840,7 +840,7 @@ def remove_return_pos_invoices(party_type, party, invoice_list):
|
|||||||
return invoice_list
|
return invoice_list
|
||||||
|
|
||||||
|
|
||||||
def get_outstanding_invoices(party_type, party, account, condition=None, filters=None):
|
def get_outstanding_invoices(party_type, party, account, company, condition=None, filters=None):
|
||||||
outstanding_invoices = []
|
outstanding_invoices = []
|
||||||
precision = frappe.get_precision("Sales Invoice", "outstanding_amount") or 2
|
precision = frappe.get_precision("Sales Invoice", "outstanding_amount") or 2
|
||||||
|
|
||||||
@@ -892,61 +892,73 @@ def get_outstanding_invoices(party_type, party, account, condition=None, filters
|
|||||||
|
|
||||||
invoice_list = remove_return_pos_invoices(party_type, party, invoice_list)
|
invoice_list = remove_return_pos_invoices(party_type, party, invoice_list)
|
||||||
|
|
||||||
payment_entries = frappe.db.sql(
|
if invoice_list:
|
||||||
"""
|
invoices = [d.voucher_no for d in invoice_list]
|
||||||
select against_voucher_type, against_voucher,
|
payment_entries = frappe.db.sql(
|
||||||
ifnull(sum({payment_dr_or_cr}), 0) as payment_amount
|
"""
|
||||||
from `tabGL Entry`
|
select against_voucher_type, against_voucher,
|
||||||
where party_type = %(party_type)s and party = %(party)s
|
ifnull(sum({payment_dr_or_cr}), 0) as payment_amount
|
||||||
and account = %(account)s
|
from `tabGL Entry`
|
||||||
and {payment_dr_or_cr} > 0
|
where
|
||||||
and against_voucher is not null and against_voucher != ''
|
company = %(company)s
|
||||||
and is_cancelled=0
|
and party_type = %(party_type)s and party = %(party)s
|
||||||
group by against_voucher_type, against_voucher
|
and account = %(account)s
|
||||||
""".format(
|
and {payment_dr_or_cr} > 0
|
||||||
payment_dr_or_cr=payment_dr_or_cr
|
and ifnull(against_voucher, '') != ''
|
||||||
),
|
and is_cancelled=0
|
||||||
{"party_type": party_type, "party": party, "account": account},
|
and against_voucher in %(invoices)s
|
||||||
as_dict=True,
|
group by against_voucher_type, against_voucher
|
||||||
)
|
""".format(
|
||||||
|
payment_dr_or_cr=payment_dr_or_cr,
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"company": company,
|
||||||
|
"party_type": party_type,
|
||||||
|
"party": party,
|
||||||
|
"account": account,
|
||||||
|
"invoices": invoices,
|
||||||
|
},
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
|
||||||
pe_map = frappe._dict()
|
pe_map = frappe._dict()
|
||||||
for d in payment_entries:
|
for d in payment_entries:
|
||||||
pe_map.setdefault((d.against_voucher_type, d.against_voucher), d.payment_amount)
|
pe_map.setdefault((d.against_voucher_type, d.against_voucher), d.payment_amount)
|
||||||
|
|
||||||
for d in invoice_list:
|
for d in invoice_list:
|
||||||
payment_amount = pe_map.get((d.voucher_type, d.voucher_no), 0)
|
payment_amount = pe_map.get((d.voucher_type, d.voucher_no), 0)
|
||||||
outstanding_amount = flt(d.invoice_amount - payment_amount, precision)
|
outstanding_amount = flt(d.invoice_amount - payment_amount, precision)
|
||||||
if outstanding_amount > 0.5 / (10**precision):
|
if outstanding_amount > 0.5 / (10**precision):
|
||||||
if (
|
if (
|
||||||
filters
|
filters
|
||||||
and filters.get("outstanding_amt_greater_than")
|
and filters.get("outstanding_amt_greater_than")
|
||||||
and not (
|
and not (
|
||||||
outstanding_amount >= filters.get("outstanding_amt_greater_than")
|
outstanding_amount >= filters.get("outstanding_amt_greater_than")
|
||||||
and outstanding_amount <= filters.get("outstanding_amt_less_than")
|
and outstanding_amount <= filters.get("outstanding_amt_less_than")
|
||||||
)
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not d.voucher_type == "Purchase Invoice" or d.voucher_no not in held_invoices:
|
|
||||||
outstanding_invoices.append(
|
|
||||||
frappe._dict(
|
|
||||||
{
|
|
||||||
"voucher_no": d.voucher_no,
|
|
||||||
"voucher_type": d.voucher_type,
|
|
||||||
"posting_date": d.posting_date,
|
|
||||||
"invoice_amount": flt(d.invoice_amount),
|
|
||||||
"payment_amount": payment_amount,
|
|
||||||
"outstanding_amount": outstanding_amount,
|
|
||||||
"due_date": d.due_date,
|
|
||||||
"currency": d.currency,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
)
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not d.voucher_type == "Purchase Invoice" or d.voucher_no not in held_invoices:
|
||||||
|
outstanding_invoices.append(
|
||||||
|
frappe._dict(
|
||||||
|
{
|
||||||
|
"voucher_no": d.voucher_no,
|
||||||
|
"voucher_type": d.voucher_type,
|
||||||
|
"posting_date": d.posting_date,
|
||||||
|
"invoice_amount": flt(d.invoice_amount),
|
||||||
|
"payment_amount": payment_amount,
|
||||||
|
"outstanding_amount": outstanding_amount,
|
||||||
|
"due_date": d.due_date,
|
||||||
|
"currency": d.currency,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
outstanding_invoices = sorted(
|
||||||
|
outstanding_invoices, key=lambda k: k["due_date"] or getdate(nowdate())
|
||||||
|
)
|
||||||
|
|
||||||
outstanding_invoices = sorted(
|
|
||||||
outstanding_invoices, key=lambda k: k["due_date"] or getdate(nowdate())
|
|
||||||
)
|
|
||||||
return outstanding_invoices
|
return outstanding_invoices
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ frappe.ui.form.on('Asset', {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
setup_chart: function(frm) {
|
setup_chart: async function(frm) {
|
||||||
if(frm.doc.finance_books.length > 1) {
|
if(frm.doc.finance_books.length > 1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -219,20 +219,34 @@ frappe.ui.form.on('Asset', {
|
|||||||
flt(frm.doc.opening_accumulated_depreciation));
|
flt(frm.doc.opening_accumulated_depreciation));
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(frm.doc.schedules || [], function(i, v) {
|
if(frm.doc.calculate_depreciation) {
|
||||||
x_intervals.push(v.schedule_date);
|
$.each(frm.doc.schedules || [], function(i, v) {
|
||||||
var asset_value = flt(frm.doc.gross_purchase_amount) - flt(v.accumulated_depreciation_amount);
|
x_intervals.push(v.schedule_date);
|
||||||
if(v.journal_entry) {
|
var asset_value = flt(frm.doc.gross_purchase_amount) - flt(v.accumulated_depreciation_amount);
|
||||||
last_depreciation_date = v.schedule_date;
|
if(v.journal_entry) {
|
||||||
asset_values.push(asset_value);
|
last_depreciation_date = v.schedule_date;
|
||||||
} else {
|
asset_values.push(asset_value);
|
||||||
if (in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
|
||||||
asset_values.push(null);
|
|
||||||
} else {
|
} else {
|
||||||
asset_values.push(asset_value)
|
if (in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||||
|
asset_values.push(null);
|
||||||
|
} else {
|
||||||
|
asset_values.push(asset_value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
} else {
|
||||||
|
let depr_entries = (await frappe.call({
|
||||||
|
method: "get_manual_depreciation_entries",
|
||||||
|
doc: frm.doc,
|
||||||
|
})).message;
|
||||||
|
|
||||||
|
$.each(depr_entries || [], function(i, v) {
|
||||||
|
x_intervals.push(v.posting_date);
|
||||||
|
last_depreciation_date = v.posting_date;
|
||||||
|
let last_asset_value = asset_values[asset_values.length - 1]
|
||||||
|
asset_values.push(last_asset_value - v.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
if(in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||||
x_intervals.push(frm.doc.disposal_date);
|
x_intervals.push(frm.doc.disposal_date);
|
||||||
|
|||||||
@@ -504,9 +504,15 @@
|
|||||||
"group": "Value",
|
"group": "Value",
|
||||||
"link_doctype": "Asset Value Adjustment",
|
"link_doctype": "Asset Value Adjustment",
|
||||||
"link_fieldname": "asset"
|
"link_fieldname": "asset"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"group": "Journal Entry",
|
||||||
|
"link_doctype": "Journal Entry",
|
||||||
|
"link_fieldname": "reference_name",
|
||||||
|
"table_fieldname": "accounts"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2023-01-17 00:28:37.789345",
|
"modified": "2023-01-31 01:03:09.467817",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset",
|
"name": "Asset",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
|||||||
from erpnext.assets.doctype.asset.depreciation import (
|
from erpnext.assets.doctype.asset.depreciation import (
|
||||||
get_depreciation_accounts,
|
get_depreciation_accounts,
|
||||||
get_disposal_account_and_cost_center,
|
get_disposal_account_and_cost_center,
|
||||||
|
is_last_day_of_the_month,
|
||||||
)
|
)
|
||||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||||
from erpnext.controllers.accounts_controller import AccountsController
|
from erpnext.controllers.accounts_controller import AccountsController
|
||||||
@@ -555,7 +556,9 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
if int(d.finance_book_id) not in finance_books:
|
if int(d.finance_book_id) not in finance_books:
|
||||||
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
||||||
value_after_depreciation = flt(self.get_value_after_depreciation(d.finance_book_id))
|
value_after_depreciation = flt(
|
||||||
|
self.get("finance_books")[cint(d.finance_book_id) - 1].value_after_depreciation
|
||||||
|
)
|
||||||
finance_books.append(int(d.finance_book_id))
|
finance_books.append(int(d.finance_book_id))
|
||||||
|
|
||||||
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
||||||
@@ -580,9 +583,6 @@ class Asset(AccountsController):
|
|||||||
accumulated_depreciation, d.precision("accumulated_depreciation_amount")
|
accumulated_depreciation, d.precision("accumulated_depreciation_amount")
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_value_after_depreciation(self, idx):
|
|
||||||
return flt(self.get("finance_books")[cint(idx) - 1].value_after_depreciation)
|
|
||||||
|
|
||||||
def validate_expected_value_after_useful_life(self):
|
def validate_expected_value_after_useful_life(self):
|
||||||
for row in self.get("finance_books"):
|
for row in self.get("finance_books"):
|
||||||
accumulated_depreciation_after_full_schedule = [
|
accumulated_depreciation_after_full_schedule = [
|
||||||
@@ -637,15 +637,20 @@ class Asset(AccountsController):
|
|||||||
movement.cancel()
|
movement.cancel()
|
||||||
|
|
||||||
def delete_depreciation_entries(self):
|
def delete_depreciation_entries(self):
|
||||||
for d in self.get("schedules"):
|
if self.calculate_depreciation:
|
||||||
if d.journal_entry:
|
for d in self.get("schedules"):
|
||||||
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
if d.journal_entry:
|
||||||
d.db_set("journal_entry", None)
|
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
||||||
|
else:
|
||||||
|
depr_entries = self.get_manual_depreciation_entries()
|
||||||
|
|
||||||
self.db_set(
|
for depr_entry in depr_entries or []:
|
||||||
"value_after_depreciation",
|
frappe.get_doc("Journal Entry", depr_entry.name).cancel()
|
||||||
(flt(self.gross_purchase_amount) - flt(self.opening_accumulated_depreciation)),
|
|
||||||
)
|
self.db_set(
|
||||||
|
"value_after_depreciation",
|
||||||
|
(flt(self.gross_purchase_amount) - flt(self.opening_accumulated_depreciation)),
|
||||||
|
)
|
||||||
|
|
||||||
def set_status(self, status=None):
|
def set_status(self, status=None):
|
||||||
"""Get and update status"""
|
"""Get and update status"""
|
||||||
@@ -676,6 +681,17 @@ class Asset(AccountsController):
|
|||||||
status = "Cancelled"
|
status = "Cancelled"
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
def get_value_after_depreciation(self, finance_book=None):
|
||||||
|
if not self.calculate_depreciation:
|
||||||
|
return self.value_after_depreciation
|
||||||
|
|
||||||
|
if not finance_book:
|
||||||
|
return self.get("finance_books")[0].value_after_depreciation
|
||||||
|
|
||||||
|
for row in self.get("finance_books"):
|
||||||
|
if finance_book == row.finance_book:
|
||||||
|
return row.value_after_depreciation
|
||||||
|
|
||||||
def get_default_finance_book_idx(self):
|
def get_default_finance_book_idx(self):
|
||||||
if not self.get("default_finance_book") and self.company:
|
if not self.get("default_finance_book") and self.company:
|
||||||
self.default_finance_book = erpnext.get_default_finance_book(self.company)
|
self.default_finance_book = erpnext.get_default_finance_book(self.company)
|
||||||
@@ -685,6 +701,24 @@ class Asset(AccountsController):
|
|||||||
if d.finance_book == self.default_finance_book:
|
if d.finance_book == self.default_finance_book:
|
||||||
return cint(d.idx) - 1
|
return cint(d.idx) - 1
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_manual_depreciation_entries(self):
|
||||||
|
(_, _, depreciation_expense_account) = get_depreciation_accounts(self)
|
||||||
|
|
||||||
|
gle = frappe.qb.DocType("GL Entry")
|
||||||
|
|
||||||
|
records = (
|
||||||
|
frappe.qb.from_(gle)
|
||||||
|
.select(gle.voucher_no.as_("name"), gle.debit.as_("value"), gle.posting_date)
|
||||||
|
.where(gle.against_voucher == self.name)
|
||||||
|
.where(gle.account == depreciation_expense_account)
|
||||||
|
.where(gle.debit != 0)
|
||||||
|
.where(gle.is_cancelled == 0)
|
||||||
|
.orderby(gle.posting_date)
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
|
return records
|
||||||
|
|
||||||
def validate_make_gl_entry(self):
|
def validate_make_gl_entry(self):
|
||||||
purchase_document = self.get_purchase_document()
|
purchase_document = self.get_purchase_document()
|
||||||
if not purchase_document:
|
if not purchase_document:
|
||||||
@@ -849,7 +883,6 @@ def update_maintenance_status():
|
|||||||
|
|
||||||
|
|
||||||
def make_post_gl_entry():
|
def make_post_gl_entry():
|
||||||
|
|
||||||
asset_categories = frappe.db.get_all("Asset Category", fields=["name", "enable_cwip_accounting"])
|
asset_categories = frappe.db.get_all("Asset Category", fields=["name", "enable_cwip_accounting"])
|
||||||
|
|
||||||
for asset_category in asset_categories:
|
for asset_category in asset_categories:
|
||||||
@@ -1002,7 +1035,7 @@ def make_journal_entry(asset_name):
|
|||||||
depreciation_expense_account,
|
depreciation_expense_account,
|
||||||
) = get_depreciation_accounts(asset)
|
) = get_depreciation_accounts(asset)
|
||||||
|
|
||||||
depreciation_cost_center, depreciation_series = frappe.db.get_value(
|
depreciation_cost_center, depreciation_series = frappe.get_cached_value(
|
||||||
"Company", asset.company, ["depreciation_cost_center", "series_for_depreciation_entry"]
|
"Company", asset.company, ["depreciation_cost_center", "series_for_depreciation_entry"]
|
||||||
)
|
)
|
||||||
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
||||||
@@ -1069,6 +1102,13 @@ def is_cwip_accounting_enabled(asset_category):
|
|||||||
return cint(frappe.db.get_value("Asset Category", asset_category, "enable_cwip_accounting"))
|
return cint(frappe.db.get_value("Asset Category", asset_category, "enable_cwip_accounting"))
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_asset_value_after_depreciation(asset_name, finance_book=None):
|
||||||
|
asset = frappe.get_doc("Asset", asset_name)
|
||||||
|
|
||||||
|
return asset.get_value_after_depreciation(finance_book)
|
||||||
|
|
||||||
|
|
||||||
def get_total_days(date, frequency):
|
def get_total_days(date, frequency):
|
||||||
period_start_date = add_months(date, cint(frequency) * -1)
|
period_start_date = add_months(date, cint(frequency) * -1)
|
||||||
|
|
||||||
@@ -1078,12 +1118,6 @@ def get_total_days(date, frequency):
|
|||||||
return date_diff(date, period_start_date)
|
return date_diff(date, period_start_date)
|
||||||
|
|
||||||
|
|
||||||
def is_last_day_of_the_month(date):
|
|
||||||
last_day_of_the_month = get_last_day(date)
|
|
||||||
|
|
||||||
return getdate(last_day_of_the_month) == getdate(date)
|
|
||||||
|
|
||||||
|
|
||||||
@erpnext.allow_regional
|
@erpnext.allow_regional
|
||||||
def get_depreciation_amount(asset, depreciable_value, row):
|
def get_depreciation_amount(asset, depreciable_value, row):
|
||||||
if row.depreciation_method in ("Straight Line", "Manual"):
|
if row.depreciation_method in ("Straight Line", "Manual"):
|
||||||
|
|||||||
@@ -4,7 +4,16 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import add_months, cint, flt, get_link_to_form, getdate, nowdate, today
|
from frappe.utils import (
|
||||||
|
add_months,
|
||||||
|
cint,
|
||||||
|
flt,
|
||||||
|
get_last_day,
|
||||||
|
get_link_to_form,
|
||||||
|
getdate,
|
||||||
|
nowdate,
|
||||||
|
today,
|
||||||
|
)
|
||||||
from frappe.utils.user import get_users_with_role
|
from frappe.utils.user import get_users_with_role
|
||||||
|
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
@@ -372,6 +381,9 @@ def disposal_was_made_on_original_schedule_date(asset, schedule, row, posting_da
|
|||||||
finance_book.depreciation_start_date, row * cint(finance_book.frequency_of_depreciation)
|
finance_book.depreciation_start_date, row * cint(finance_book.frequency_of_depreciation)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if is_last_day_of_the_month(finance_book.depreciation_start_date):
|
||||||
|
orginal_schedule_date = get_last_day(orginal_schedule_date)
|
||||||
|
|
||||||
if orginal_schedule_date == posting_date_of_disposal:
|
if orginal_schedule_date == posting_date_of_disposal:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -457,18 +469,8 @@ def get_asset_details(asset, finance_book=None):
|
|||||||
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
|
||||||
|
|
||||||
idx = 1
|
value_after_depreciation = asset.get_value_after_depreciation(finance_book)
|
||||||
if finance_book:
|
|
||||||
for d in asset.finance_books:
|
|
||||||
if d.finance_book == finance_book:
|
|
||||||
idx = d.idx
|
|
||||||
break
|
|
||||||
|
|
||||||
value_after_depreciation = (
|
|
||||||
asset.finance_books[idx - 1].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)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -508,3 +510,9 @@ def get_disposal_account_and_cost_center(company):
|
|||||||
frappe.throw(_("Please set 'Asset Depreciation Cost Center' in Company {0}").format(company))
|
frappe.throw(_("Please set 'Asset Depreciation Cost Center' in Company {0}").format(company))
|
||||||
|
|
||||||
return disposal_account, depreciation_cost_center
|
return disposal_account, depreciation_cost_center
|
||||||
|
|
||||||
|
|
||||||
|
def is_last_day_of_the_month(date):
|
||||||
|
last_day_of_the_month = get_last_day(date)
|
||||||
|
|
||||||
|
return getdate(last_day_of_the_month) == getdate(date)
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ from frappe.utils import (
|
|||||||
nowdate,
|
nowdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||||
from erpnext.assets.doctype.asset.asset import make_sales_invoice, update_maintenance_status
|
from erpnext.assets.doctype.asset.asset import make_sales_invoice, update_maintenance_status
|
||||||
from erpnext.assets.doctype.asset.depreciation import (
|
from erpnext.assets.doctype.asset.depreciation import (
|
||||||
|
is_last_day_of_the_month,
|
||||||
post_depreciation_entries,
|
post_depreciation_entries,
|
||||||
restore_asset,
|
restore_asset,
|
||||||
scrap_asset,
|
scrap_asset,
|
||||||
@@ -1409,6 +1411,36 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
for i, schedule in enumerate(asset.schedules):
|
for i, schedule in enumerate(asset.schedules):
|
||||||
self.assertEqual(getdate(expected_dates[i]), getdate(schedule.schedule_date))
|
self.assertEqual(getdate(expected_dates[i]), getdate(schedule.schedule_date))
|
||||||
|
|
||||||
|
def test_manual_depreciation_for_existing_asset(self):
|
||||||
|
asset = create_asset(
|
||||||
|
item_code="Macbook Pro",
|
||||||
|
is_existing_asset=1,
|
||||||
|
purchase_date="2020-01-30",
|
||||||
|
available_for_use_date="2020-01-30",
|
||||||
|
submit=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(asset.status, "Submitted")
|
||||||
|
self.assertEqual(asset.get("value_after_depreciation"), 100000)
|
||||||
|
|
||||||
|
jv = make_journal_entry(
|
||||||
|
"_Test Depreciations - _TC", "_Test Accumulated Depreciations - _TC", 100, save=False
|
||||||
|
)
|
||||||
|
for d in jv.accounts:
|
||||||
|
d.reference_type = "Asset"
|
||||||
|
d.reference_name = asset.name
|
||||||
|
jv.voucher_type = "Depreciation Entry"
|
||||||
|
jv.insert()
|
||||||
|
jv.submit()
|
||||||
|
|
||||||
|
asset.reload()
|
||||||
|
self.assertEqual(asset.get("value_after_depreciation"), 99900)
|
||||||
|
|
||||||
|
jv.cancel()
|
||||||
|
|
||||||
|
asset.reload()
|
||||||
|
self.assertEqual(asset.get("value_after_depreciation"), 100000)
|
||||||
|
|
||||||
|
|
||||||
def create_asset_data():
|
def create_asset_data():
|
||||||
if not frappe.db.exists("Asset Category", "Computers"):
|
if not frappe.db.exists("Asset Category", "Computers"):
|
||||||
@@ -1529,9 +1561,3 @@ def set_depreciation_settings_in_company():
|
|||||||
|
|
||||||
def enable_cwip_accounting(asset_category, enable=1):
|
def enable_cwip_accounting(asset_category, enable=1):
|
||||||
frappe.db.set_value("Asset Category", asset_category, "enable_cwip_accounting", enable)
|
frappe.db.set_value("Asset Category", asset_category, "enable_cwip_accounting", enable)
|
||||||
|
|
||||||
|
|
||||||
def is_last_day_of_the_month(dt):
|
|
||||||
last_day_of_the_month = get_last_day(dt)
|
|
||||||
|
|
||||||
return getdate(dt) == getdate(last_day_of_the_month)
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import unittest
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import flt, nowdate
|
from frappe.utils import flt, nowdate
|
||||||
|
|
||||||
|
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
|
||||||
from erpnext.assets.doctype.asset.test_asset import (
|
from erpnext.assets.doctype.asset.test_asset import (
|
||||||
create_asset,
|
create_asset,
|
||||||
create_asset_data,
|
create_asset_data,
|
||||||
@@ -105,20 +106,20 @@ class TestAssetRepair(unittest.TestCase):
|
|||||||
|
|
||||||
def test_increase_in_asset_value_due_to_stock_consumption(self):
|
def test_increase_in_asset_value_due_to_stock_consumption(self):
|
||||||
asset = create_asset(calculate_depreciation=1, submit=1)
|
asset = create_asset(calculate_depreciation=1, submit=1)
|
||||||
initial_asset_value = get_asset_value(asset)
|
initial_asset_value = get_asset_value_after_depreciation(asset.name)
|
||||||
asset_repair = create_asset_repair(asset=asset, stock_consumption=1, submit=1)
|
asset_repair = create_asset_repair(asset=asset, stock_consumption=1, submit=1)
|
||||||
asset.reload()
|
asset.reload()
|
||||||
|
|
||||||
increase_in_asset_value = get_asset_value(asset) - initial_asset_value
|
increase_in_asset_value = get_asset_value_after_depreciation(asset.name) - initial_asset_value
|
||||||
self.assertEqual(asset_repair.stock_items[0].total_value, increase_in_asset_value)
|
self.assertEqual(asset_repair.stock_items[0].total_value, increase_in_asset_value)
|
||||||
|
|
||||||
def test_increase_in_asset_value_due_to_repair_cost_capitalisation(self):
|
def test_increase_in_asset_value_due_to_repair_cost_capitalisation(self):
|
||||||
asset = create_asset(calculate_depreciation=1, submit=1)
|
asset = create_asset(calculate_depreciation=1, submit=1)
|
||||||
initial_asset_value = get_asset_value(asset)
|
initial_asset_value = get_asset_value_after_depreciation(asset.name)
|
||||||
asset_repair = create_asset_repair(asset=asset, capitalize_repair_cost=1, submit=1)
|
asset_repair = create_asset_repair(asset=asset, capitalize_repair_cost=1, submit=1)
|
||||||
asset.reload()
|
asset.reload()
|
||||||
|
|
||||||
increase_in_asset_value = get_asset_value(asset) - initial_asset_value
|
increase_in_asset_value = get_asset_value_after_depreciation(asset.name) - initial_asset_value
|
||||||
self.assertEqual(asset_repair.repair_cost, increase_in_asset_value)
|
self.assertEqual(asset_repair.repair_cost, increase_in_asset_value)
|
||||||
|
|
||||||
def test_purchase_invoice(self):
|
def test_purchase_invoice(self):
|
||||||
@@ -143,10 +144,6 @@ class TestAssetRepair(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_asset_value(asset):
|
|
||||||
return asset.finance_books[0].value_after_depreciation
|
|
||||||
|
|
||||||
|
|
||||||
def num_of_depreciations(asset):
|
def num_of_depreciations(asset):
|
||||||
return asset.finance_books[0].total_number_of_depreciations
|
return asset.finance_books[0].total_number_of_depreciations
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ frappe.ui.form.on('Asset Value Adjustment', {
|
|||||||
set_current_asset_value: function(frm) {
|
set_current_asset_value: function(frm) {
|
||||||
if (frm.doc.asset) {
|
if (frm.doc.asset) {
|
||||||
frm.call({
|
frm.call({
|
||||||
method: "erpnext.assets.doctype.asset_value_adjustment.asset_value_adjustment.get_current_asset_value",
|
method: "erpnext.assets.doctype.asset.asset.get_asset_value_after_depreciation",
|
||||||
args: {
|
args: {
|
||||||
asset: frm.doc.asset,
|
asset: frm.doc.asset,
|
||||||
finance_book: frm.doc.finance_book
|
finance_book: frm.doc.finance_book
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ from frappe.utils import cint, date_diff, flt, formatdate, getdate
|
|||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
get_checks_for_pl_and_bs_accounts,
|
get_checks_for_pl_and_bs_accounts,
|
||||||
)
|
)
|
||||||
from erpnext.assets.doctype.asset.asset import get_depreciation_amount
|
from erpnext.assets.doctype.asset.asset import (
|
||||||
|
get_asset_value_after_depreciation,
|
||||||
|
get_depreciation_amount,
|
||||||
|
)
|
||||||
from erpnext.assets.doctype.asset.depreciation import get_depreciation_accounts
|
from erpnext.assets.doctype.asset.depreciation import get_depreciation_accounts
|
||||||
from erpnext.regional.india.utils import (
|
from erpnext.regional.india.utils import (
|
||||||
get_depreciation_amount as get_depreciation_amount_for_india,
|
get_depreciation_amount as get_depreciation_amount_for_india,
|
||||||
@@ -45,7 +48,7 @@ class AssetValueAdjustment(Document):
|
|||||||
|
|
||||||
def set_current_asset_value(self):
|
def set_current_asset_value(self):
|
||||||
if not self.current_asset_value and self.asset:
|
if not self.current_asset_value and self.asset:
|
||||||
self.current_asset_value = get_current_asset_value(self.asset, self.finance_book)
|
self.current_asset_value = get_asset_value_after_depreciation(self.asset, self.finance_book)
|
||||||
|
|
||||||
def make_depreciation_entry(self):
|
def make_depreciation_entry(self):
|
||||||
asset = frappe.get_doc("Asset", self.asset)
|
asset = frappe.get_doc("Asset", self.asset)
|
||||||
@@ -148,12 +151,3 @@ class AssetValueAdjustment(Document):
|
|||||||
for asset_data in asset.schedules:
|
for asset_data in asset.schedules:
|
||||||
if not asset_data.journal_entry:
|
if not asset_data.journal_entry:
|
||||||
asset_data.db_update()
|
asset_data.db_update()
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def get_current_asset_value(asset, finance_book=None):
|
|
||||||
cond = {"parent": asset, "parenttype": "Asset"}
|
|
||||||
if finance_book:
|
|
||||||
cond.update({"finance_book": finance_book})
|
|
||||||
|
|
||||||
return frappe.db.get_value("Asset Finance Book", cond, "value_after_depreciation")
|
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import unittest
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import add_days, get_last_day, nowdate
|
from frappe.utils import add_days, get_last_day, nowdate
|
||||||
|
|
||||||
|
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
|
||||||
from erpnext.assets.doctype.asset.test_asset import create_asset_data
|
from erpnext.assets.doctype.asset.test_asset import create_asset_data
|
||||||
from erpnext.assets.doctype.asset_value_adjustment.asset_value_adjustment import (
|
|
||||||
get_current_asset_value,
|
|
||||||
)
|
|
||||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
|
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
asset_doc.submit()
|
asset_doc.submit()
|
||||||
|
|
||||||
current_value = get_current_asset_value(asset_doc.name)
|
current_value = get_asset_value_after_depreciation(asset_doc.name)
|
||||||
self.assertEqual(current_value, 100000.0)
|
self.assertEqual(current_value, 100000.0)
|
||||||
|
|
||||||
def test_asset_depreciation_value_adjustment(self):
|
def test_asset_depreciation_value_adjustment(self):
|
||||||
@@ -73,7 +71,7 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
asset_doc.submit()
|
asset_doc.submit()
|
||||||
|
|
||||||
current_value = get_current_asset_value(asset_doc.name)
|
current_value = get_asset_value_after_depreciation(asset_doc.name)
|
||||||
adj_doc = make_asset_value_adjustment(
|
adj_doc = make_asset_value_adjustment(
|
||||||
asset=asset_doc.name, current_asset_value=current_value, new_asset_value=50000.0
|
asset=asset_doc.name, current_asset_value=current_value, new_asset_value=50000.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,13 +4,16 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cstr, flt, formatdate, getdate
|
from frappe.query_builder.functions import Sum
|
||||||
|
from frappe.utils import cstr, formatdate, getdate
|
||||||
|
|
||||||
from erpnext.accounts.report.financial_statements import (
|
from erpnext.accounts.report.financial_statements import (
|
||||||
get_fiscal_year_data,
|
get_fiscal_year_data,
|
||||||
get_period_list,
|
get_period_list,
|
||||||
validate_fiscal_year,
|
validate_fiscal_year,
|
||||||
)
|
)
|
||||||
|
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
|
||||||
|
from erpnext.assets.doctype.asset.depreciation import get_depreciation_accounts
|
||||||
|
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
@@ -85,6 +88,7 @@ def get_data(filters):
|
|||||||
"asset_name",
|
"asset_name",
|
||||||
"status",
|
"status",
|
||||||
"department",
|
"department",
|
||||||
|
"company",
|
||||||
"cost_center",
|
"cost_center",
|
||||||
"calculate_depreciation",
|
"calculate_depreciation",
|
||||||
"purchase_receipt",
|
"purchase_receipt",
|
||||||
@@ -98,8 +102,25 @@ def get_data(filters):
|
|||||||
]
|
]
|
||||||
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
||||||
|
|
||||||
|
finance_book_filter = ("is", "not set")
|
||||||
|
if filters.finance_book:
|
||||||
|
finance_book_filter = ("=", filters.finance_book)
|
||||||
|
|
||||||
|
assets_linked_to_fb = frappe.db.get_all(
|
||||||
|
doctype="Asset Finance Book",
|
||||||
|
filters={"finance_book": finance_book_filter},
|
||||||
|
pluck="parent",
|
||||||
|
)
|
||||||
|
|
||||||
for asset in assets_record:
|
for asset in assets_record:
|
||||||
asset_value = get_asset_value(asset, filters.finance_book)
|
if filters.finance_book:
|
||||||
|
if asset.asset_id not in assets_linked_to_fb:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if asset.calculate_depreciation and asset.asset_id not in assets_linked_to_fb:
|
||||||
|
continue
|
||||||
|
|
||||||
|
asset_value = get_asset_value_after_depreciation(asset.asset_id, filters.finance_book)
|
||||||
row = {
|
row = {
|
||||||
"asset_id": asset.asset_id,
|
"asset_id": asset.asset_id,
|
||||||
"asset_name": asset.asset_name,
|
"asset_name": asset.asset_name,
|
||||||
@@ -110,7 +131,7 @@ def get_data(filters):
|
|||||||
or pi_supplier_map.get(asset.purchase_invoice),
|
or pi_supplier_map.get(asset.purchase_invoice),
|
||||||
"gross_purchase_amount": asset.gross_purchase_amount,
|
"gross_purchase_amount": asset.gross_purchase_amount,
|
||||||
"opening_accumulated_depreciation": asset.opening_accumulated_depreciation,
|
"opening_accumulated_depreciation": asset.opening_accumulated_depreciation,
|
||||||
"depreciated_amount": depreciation_amount_map.get(asset.asset_id) or 0.0,
|
"depreciated_amount": get_depreciation_amount_of_asset(asset, depreciation_amount_map, filters),
|
||||||
"available_for_use_date": asset.available_for_use_date,
|
"available_for_use_date": asset.available_for_use_date,
|
||||||
"location": asset.location,
|
"location": asset.location,
|
||||||
"asset_category": asset.asset_category,
|
"asset_category": asset.asset_category,
|
||||||
@@ -122,21 +143,6 @@ def get_data(filters):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_asset_value(asset, finance_book=None):
|
|
||||||
if not asset.calculate_depreciation:
|
|
||||||
return flt(asset.gross_purchase_amount) - flt(asset.opening_accumulated_depreciation)
|
|
||||||
|
|
||||||
finance_book_filter = ["finance_book", "is", "not set"]
|
|
||||||
if finance_book:
|
|
||||||
finance_book_filter = ["finance_book", "=", finance_book]
|
|
||||||
|
|
||||||
return frappe.db.get_value(
|
|
||||||
doctype="Asset Finance Book",
|
|
||||||
filters=[["parent", "=", asset.asset_id], finance_book_filter],
|
|
||||||
fieldname="value_after_depreciation",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_chart_data(data, filters):
|
def prepare_chart_data(data, filters):
|
||||||
labels_values_map = {}
|
labels_values_map = {}
|
||||||
date_field = frappe.scrub(filters.date_based_on)
|
date_field = frappe.scrub(filters.date_based_on)
|
||||||
@@ -182,6 +188,15 @@ def prepare_chart_data(data, filters):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_depreciation_amount_of_asset(asset, depreciation_amount_map, filters):
|
||||||
|
if asset.calculate_depreciation:
|
||||||
|
depr_amount = depreciation_amount_map.get(asset.asset_id) or 0.0
|
||||||
|
else:
|
||||||
|
depr_amount = get_manual_depreciation_amount_of_asset(asset, filters)
|
||||||
|
|
||||||
|
return depr_amount
|
||||||
|
|
||||||
|
|
||||||
def get_finance_book_value_map(filters):
|
def get_finance_book_value_map(filters):
|
||||||
date = filters.to_date if filters.filter_based_on == "Date Range" else filters.year_end_date
|
date = filters.to_date if filters.filter_based_on == "Date Range" else filters.year_end_date
|
||||||
|
|
||||||
@@ -201,6 +216,31 @@ def get_finance_book_value_map(filters):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_manual_depreciation_amount_of_asset(asset, filters):
|
||||||
|
date = filters.to_date if filters.filter_based_on == "Date Range" else filters.year_end_date
|
||||||
|
|
||||||
|
(_, _, depreciation_expense_account) = get_depreciation_accounts(asset)
|
||||||
|
|
||||||
|
gle = frappe.qb.DocType("GL Entry")
|
||||||
|
|
||||||
|
result = (
|
||||||
|
frappe.qb.from_(gle)
|
||||||
|
.select(Sum(gle.debit))
|
||||||
|
.where(gle.against_voucher == asset.asset_id)
|
||||||
|
.where(gle.account == depreciation_expense_account)
|
||||||
|
.where(gle.debit != 0)
|
||||||
|
.where(gle.is_cancelled == 0)
|
||||||
|
.where(gle.posting_date <= date)
|
||||||
|
).run()
|
||||||
|
|
||||||
|
if result and result[0] and result[0][0]:
|
||||||
|
depr_amount = result[0][0]
|
||||||
|
else:
|
||||||
|
depr_amount = 0
|
||||||
|
|
||||||
|
return depr_amount
|
||||||
|
|
||||||
|
|
||||||
def get_purchase_receipt_supplier_map():
|
def get_purchase_receipt_supplier_map():
|
||||||
return frappe._dict(
|
return frappe._dict(
|
||||||
frappe.db.sql(
|
frappe.db.sql(
|
||||||
|
|||||||
@@ -375,3 +375,4 @@ erpnext.patches.v13_0.show_hr_payroll_deprecation_warning
|
|||||||
erpnext.patches.v13_0.create_accounting_dimensions_for_asset_repair
|
erpnext.patches.v13_0.create_accounting_dimensions_for_asset_repair
|
||||||
execute:frappe.db.set_value("Naming Series", "Naming Series", {"select_doc_for_series": "", "set_options": "", "prefix": "", "current_value": 0, "user_must_always_select": 0})
|
execute:frappe.db.set_value("Naming Series", "Naming Series", {"select_doc_for_series": "", "set_options": "", "prefix": "", "current_value": 0, "user_must_always_select": 0})
|
||||||
erpnext.patches.v13_0.update_schedule_type_in_loans
|
erpnext.patches.v13_0.update_schedule_type_in_loans
|
||||||
|
erpnext.patches.v13_0.update_asset_value_for_manual_depr_entries
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import frappe
|
||||||
|
from frappe.query_builder.functions import IfNull, Sum
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
asset = frappe.qb.DocType("Asset")
|
||||||
|
gle = frappe.qb.DocType("GL Entry")
|
||||||
|
aca = frappe.qb.DocType("Asset Category Account")
|
||||||
|
company = frappe.qb.DocType("Company")
|
||||||
|
|
||||||
|
asset_total_depr_value_map = (
|
||||||
|
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(Sum(gle.debit).as_("value"), asset.name.as_("asset_name"))
|
||||||
|
.where(
|
||||||
|
gle.account == IfNull(aca.depreciation_expense_account, company.depreciation_expense_account)
|
||||||
|
)
|
||||||
|
.where(gle.debit != 0)
|
||||||
|
.where(gle.is_cancelled == 0)
|
||||||
|
.where(asset.docstatus == 1)
|
||||||
|
.where(asset.calculate_depreciation == 0)
|
||||||
|
.groupby(asset.name)
|
||||||
|
)
|
||||||
|
|
||||||
|
frappe.qb.update(asset).join(asset_total_depr_value_map).on(
|
||||||
|
asset_total_depr_value_map.asset_name == asset.name
|
||||||
|
).set(
|
||||||
|
asset.value_after_depreciation, asset.value_after_depreciation - asset_total_depr_value_map.value
|
||||||
|
).where(
|
||||||
|
asset.docstatus == 1
|
||||||
|
).where(
|
||||||
|
asset.calculate_depreciation == 0
|
||||||
|
).run()
|
||||||
@@ -1781,6 +1781,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
var valid = true;
|
var valid = true;
|
||||||
|
|
||||||
|
if (frappe.flags.ignore_company_party_validation) {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
$.each(["company", "customer"], function(i, fieldname) {
|
$.each(["company", "customer"], function(i, fieldname) {
|
||||||
if(frappe.meta.has_field(me.frm.doc.doctype, fieldname) && me.frm.doc.doctype != "Purchase Order") {
|
if(frappe.meta.has_field(me.frm.doc.doctype, fieldname) && me.frm.doc.doctype != "Purchase Order") {
|
||||||
if (!me.frm.doc[fieldname]) {
|
if (!me.frm.doc[fieldname]) {
|
||||||
|
|||||||
@@ -466,7 +466,20 @@ erpnext.utils.update_child_items = function(opts) {
|
|||||||
const child_meta = frappe.get_meta(`${frm.doc.doctype} Item`);
|
const child_meta = frappe.get_meta(`${frm.doc.doctype} Item`);
|
||||||
const get_precision = (fieldname) => child_meta.fields.find(f => f.fieldname == fieldname).precision;
|
const get_precision = (fieldname) => child_meta.fields.find(f => f.fieldname == fieldname).precision;
|
||||||
|
|
||||||
this.data = [];
|
this.data = frm.doc[opts.child_docname].map((d) => {
|
||||||
|
return {
|
||||||
|
"docname": d.name,
|
||||||
|
"name": d.name,
|
||||||
|
"item_code": d.item_code,
|
||||||
|
"delivery_date": d.delivery_date,
|
||||||
|
"schedule_date": d.schedule_date,
|
||||||
|
"conversion_factor": d.conversion_factor,
|
||||||
|
"qty": d.qty,
|
||||||
|
"rate": d.rate,
|
||||||
|
"uom": d.uom
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const fields = [{
|
const fields = [{
|
||||||
fieldtype:'Data',
|
fieldtype:'Data',
|
||||||
fieldname:"docname",
|
fieldname:"docname",
|
||||||
@@ -559,7 +572,7 @@ erpnext.utils.update_child_items = function(opts) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialog = new frappe.ui.Dialog({
|
new frappe.ui.Dialog({
|
||||||
title: __("Update Items"),
|
title: __("Update Items"),
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
@@ -595,24 +608,7 @@ erpnext.utils.update_child_items = function(opts) {
|
|||||||
refresh_field("items");
|
refresh_field("items");
|
||||||
},
|
},
|
||||||
primary_action_label: __('Update')
|
primary_action_label: __('Update')
|
||||||
});
|
}).show();
|
||||||
|
|
||||||
frm.doc[opts.child_docname].forEach(d => {
|
|
||||||
dialog.fields_dict.trans_items.df.data.push({
|
|
||||||
"docname": d.name,
|
|
||||||
"name": d.name,
|
|
||||||
"item_code": d.item_code,
|
|
||||||
"delivery_date": d.delivery_date,
|
|
||||||
"schedule_date": d.schedule_date,
|
|
||||||
"conversion_factor": d.conversion_factor,
|
|
||||||
"qty": d.qty,
|
|
||||||
"rate": d.rate,
|
|
||||||
"uom": d.uom
|
|
||||||
});
|
|
||||||
this.data = dialog.fields_dict.trans_items.df.data;
|
|
||||||
dialog.fields_dict.trans_items.grid.refresh();
|
|
||||||
})
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
erpnext.utils.map_current_doc = function(opts) {
|
erpnext.utils.map_current_doc = function(opts) {
|
||||||
|
|||||||
@@ -13,9 +13,10 @@
|
|||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "Workspace",
|
"doctype": "Workspace",
|
||||||
"extends_another_page": 0,
|
"extends_another_page": 0,
|
||||||
"hide_custom": 1,
|
"hide_custom": 0,
|
||||||
"icon": "sell",
|
"icon": "sell",
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
|
"is_default": 0,
|
||||||
"is_standard": 1,
|
"is_standard": 1,
|
||||||
"label": "Selling",
|
"label": "Selling",
|
||||||
"links": [
|
"links": [
|
||||||
@@ -515,7 +516,7 @@
|
|||||||
"type": "Link"
|
"type": "Link"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2020-12-01 13:38:35.971277",
|
"modified": "2023-01-28 17:10:02.716760",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Selling",
|
"name": "Selling",
|
||||||
|
|||||||
@@ -849,6 +849,12 @@ function open_form(frm, doctype, child_doctype, parentfield) {
|
|||||||
new_child_doc.uom = frm.doc.stock_uom;
|
new_child_doc.uom = frm.doc.stock_uom;
|
||||||
new_child_doc.description = frm.doc.description;
|
new_child_doc.description = frm.doc.description;
|
||||||
|
|
||||||
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
|
frappe.run_serially([
|
||||||
|
() => frappe.ui.form.make_quick_entry(doctype, null, null, new_doc),
|
||||||
|
() => {
|
||||||
|
frappe.flags.ignore_company_party_validation = true;
|
||||||
|
frappe.model.trigger("item_code", frm.doc.name, new_child_doc);
|
||||||
|
}
|
||||||
|
])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ class QualityInspection(Document):
|
|||||||
def item_query(doctype, txt, searchfield, start, page_len, filters):
|
def item_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
from frappe.desk.reportview import get_match_cond
|
from frappe.desk.reportview import get_match_cond
|
||||||
|
|
||||||
from_doctype = cstr(filters.get("doctype"))
|
from_doctype = cstr(filters.get("from"))
|
||||||
if not from_doctype or not frappe.db.exists("DocType", from_doctype):
|
if not from_doctype or not frappe.db.exists("DocType", from_doctype):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user