fix: link Purchase Invoice and Receipt Items to Asset
This commit is contained in:
@@ -1267,7 +1267,11 @@ class PurchaseInvoice(BuyingController):
|
|||||||
def update_gross_purchase_amount_for_linked_assets(self, item):
|
def update_gross_purchase_amount_for_linked_assets(self, item):
|
||||||
assets = frappe.db.get_all(
|
assets = frappe.db.get_all(
|
||||||
"Asset",
|
"Asset",
|
||||||
filters={"purchase_invoice": self.name, "item_code": item.item_code},
|
filters={
|
||||||
|
"purchase_invoice": self.name,
|
||||||
|
"item_code": item.item_code,
|
||||||
|
"purchase_invoice_item": ("in", [item.name, ""]),
|
||||||
|
},
|
||||||
fields=["name", "asset_quantity"],
|
fields=["name", "asset_quantity"],
|
||||||
)
|
)
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
|
|||||||
@@ -670,6 +670,11 @@ frappe.ui.form.on("Asset", {
|
|||||||
if (item.asset_location) {
|
if (item.asset_location) {
|
||||||
frm.set_value("location", item.asset_location);
|
frm.set_value("location", item.asset_location);
|
||||||
}
|
}
|
||||||
|
if (doctype === "Purchase Receipt") {
|
||||||
|
frm.set_value("purchase_receipt_item", item.name);
|
||||||
|
} else if (doctype === "Purchase Invoice") {
|
||||||
|
frm.set_value("purchase_invoice_item", item.name);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,16 @@
|
|||||||
"dimension_col_break",
|
"dimension_col_break",
|
||||||
"purchase_details_section",
|
"purchase_details_section",
|
||||||
"purchase_receipt",
|
"purchase_receipt",
|
||||||
|
"purchase_receipt_item",
|
||||||
"purchase_invoice",
|
"purchase_invoice",
|
||||||
|
"purchase_invoice_item",
|
||||||
|
"purchase_date",
|
||||||
"available_for_use_date",
|
"available_for_use_date",
|
||||||
"total_asset_cost",
|
|
||||||
"additional_asset_cost",
|
|
||||||
"column_break_23",
|
"column_break_23",
|
||||||
"gross_purchase_amount",
|
"gross_purchase_amount",
|
||||||
"asset_quantity",
|
"asset_quantity",
|
||||||
"purchase_date",
|
"additional_asset_cost",
|
||||||
|
"total_asset_cost",
|
||||||
"section_break_23",
|
"section_break_23",
|
||||||
"calculate_depreciation",
|
"calculate_depreciation",
|
||||||
"column_break_33",
|
"column_break_33",
|
||||||
@@ -536,6 +538,20 @@
|
|||||||
"fieldname": "opening_number_of_booked_depreciations",
|
"fieldname": "opening_number_of_booked_depreciations",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"label": "Opening Number of Booked Depreciations"
|
"label": "Opening Number of Booked Depreciations"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "purchase_receipt_item",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "Purchase Receipt Item",
|
||||||
|
"options": "Purchase Receipt Item"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "purchase_invoice_item",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "Purchase Invoice Item",
|
||||||
|
"options": "Purchase Invoice Item"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"idx": 72,
|
"idx": 72,
|
||||||
@@ -579,7 +595,7 @@
|
|||||||
"link_fieldname": "target_asset"
|
"link_fieldname": "target_asset"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2024-08-01 16:39:09.340973",
|
"modified": "2024-08-26 23:28:29.095139",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset",
|
"name": "Asset",
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ class Asset(AccountsController):
|
|||||||
purchase_amount: DF.Currency
|
purchase_amount: DF.Currency
|
||||||
purchase_date: DF.Date | None
|
purchase_date: DF.Date | None
|
||||||
purchase_invoice: DF.Link | None
|
purchase_invoice: DF.Link | None
|
||||||
|
purchase_invoice_item: DF.Link | None
|
||||||
purchase_receipt: DF.Link | None
|
purchase_receipt: DF.Link | None
|
||||||
|
purchase_receipt_item: DF.Link | None
|
||||||
split_from: DF.Link | None
|
split_from: DF.Link | None
|
||||||
status: DF.Literal[
|
status: DF.Literal[
|
||||||
"Draft",
|
"Draft",
|
||||||
|
|||||||
@@ -824,6 +824,8 @@ class BuyingController(SubcontractingController):
|
|||||||
"asset_quantity": asset_quantity,
|
"asset_quantity": asset_quantity,
|
||||||
"purchase_receipt": self.name if self.doctype == "Purchase Receipt" else None,
|
"purchase_receipt": self.name if self.doctype == "Purchase Receipt" else None,
|
||||||
"purchase_invoice": self.name if self.doctype == "Purchase Invoice" else None,
|
"purchase_invoice": self.name if self.doctype == "Purchase Invoice" else None,
|
||||||
|
"purchase_receipt_item": row.name if self.doctype == "Purchase Receipt" else None,
|
||||||
|
"purchase_invoice_item": row.name if self.doctype == "Purchase Invoice" else None,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -377,3 +377,4 @@ erpnext.patches.v15_0.update_total_number_of_booked_depreciations
|
|||||||
erpnext.patches.v15_0.do_not_use_batchwise_valuation
|
erpnext.patches.v15_0.do_not_use_batchwise_valuation
|
||||||
erpnext.patches.v15_0.drop_index_posting_datetime_from_sle
|
erpnext.patches.v15_0.drop_index_posting_datetime_from_sle
|
||||||
erpnext.patches.v15_0.set_standard_stock_entry_type
|
erpnext.patches.v15_0.set_standard_stock_entry_type
|
||||||
|
erpnext.patches.v15_0.link_purchase_item_to_asset_doc
|
||||||
|
|||||||
68
erpnext/patches/v15_0/link_purchase_item_to_asset_doc.py
Normal file
68
erpnext/patches/v15_0/link_purchase_item_to_asset_doc.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
if frappe.db.has_column("Asset", "purchase_invoice_item") and frappe.db.has_column(
|
||||||
|
"Asset", "purchase_receipt_item"
|
||||||
|
):
|
||||||
|
# Get all assets with their related Purchase Invoice and Purchase Receipt
|
||||||
|
assets = frappe.get_all(
|
||||||
|
"Asset",
|
||||||
|
filters={"docstatus": 0},
|
||||||
|
fields=[
|
||||||
|
"name",
|
||||||
|
"item_code",
|
||||||
|
"purchase_invoice",
|
||||||
|
"purchase_receipt",
|
||||||
|
"gross_purchase_amount",
|
||||||
|
"asset_quantity",
|
||||||
|
"purchase_invoice_item",
|
||||||
|
"purchase_receipt_item",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
for asset in assets:
|
||||||
|
# Get Purchase Invoice Items
|
||||||
|
if asset.purchase_invoice and not asset.purchase_invoice_item:
|
||||||
|
purchase_invoice_item = get_linked_item(
|
||||||
|
"Purchase Invoice Item",
|
||||||
|
asset.purchase_invoice,
|
||||||
|
asset.item_code,
|
||||||
|
asset.gross_purchase_amount,
|
||||||
|
asset.asset_quantity,
|
||||||
|
)
|
||||||
|
frappe.db.set_value("Asset", asset.name, "purchase_invoice_item", purchase_invoice_item)
|
||||||
|
|
||||||
|
# Get Purchase Receipt Items
|
||||||
|
if asset.purchase_receipt and not asset.purchase_receipt_item:
|
||||||
|
purchase_receipt_item = get_linked_item(
|
||||||
|
"Purchase Receipt Item",
|
||||||
|
asset.purchase_receipt,
|
||||||
|
asset.item_code,
|
||||||
|
asset.gross_purchase_amount,
|
||||||
|
asset.asset_quantity,
|
||||||
|
)
|
||||||
|
frappe.db.set_value("Asset", asset.name, "purchase_receipt_item", purchase_receipt_item)
|
||||||
|
|
||||||
|
|
||||||
|
def get_linked_item(doctype, parent, item_code, amount, quantity):
|
||||||
|
items = frappe.get_all(
|
||||||
|
doctype,
|
||||||
|
filters={
|
||||||
|
"parenttype": doctype.replace(" Item", ""),
|
||||||
|
"parent": parent,
|
||||||
|
"item_code": item_code,
|
||||||
|
},
|
||||||
|
fields=["name", "amount", "qty", "landed_cost_voucher_amount"],
|
||||||
|
)
|
||||||
|
if len(items) == 1:
|
||||||
|
# If only one item exists, return it directly
|
||||||
|
return items[0].name
|
||||||
|
|
||||||
|
for item in items:
|
||||||
|
landed_cost = item.get("landed_cost_voucher_amount", 0)
|
||||||
|
if item.amount + landed_cost == amount and item.qty == quantity:
|
||||||
|
return item.name
|
||||||
|
|
||||||
|
# If no exact match, return None
|
||||||
|
return None
|
||||||
@@ -828,7 +828,11 @@ class PurchaseReceipt(BuyingController):
|
|||||||
def update_assets(self, item, valuation_rate):
|
def update_assets(self, item, valuation_rate):
|
||||||
assets = frappe.db.get_all(
|
assets = frappe.db.get_all(
|
||||||
"Asset",
|
"Asset",
|
||||||
filters={"purchase_receipt": self.name, "item_code": item.item_code},
|
filters={
|
||||||
|
"purchase_receipt": self.name,
|
||||||
|
"item_code": item.item_code,
|
||||||
|
"purchase_receipt_item": ("in", [item.name, ""]),
|
||||||
|
},
|
||||||
fields=["name", "asset_quantity"],
|
fields=["name", "asset_quantity"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user