Skip to content

Commit

Permalink
fix: Purchase date and amount is not mandatory for composite asset cr…
Browse files Browse the repository at this point in the history
…eation

(cherry picked from commit c34f09c)

# Conflicts:
#	erpnext/assets/doctype/asset/asset.py
  • Loading branch information
nabinhait authored and mergify[bot] committed Jan 8, 2024
1 parent 580e9f6 commit 0f6477a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
12 changes: 6 additions & 6 deletions erpnext/assets/doctype/asset/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@
"fieldname": "purchase_date",
"fieldtype": "Date",
"label": "Purchase Date",
"mandatory_depends_on": "eval:!doc.is_existing_asset",
"read_only": 1,
"read_only_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset",
"reqd": 1
"read_only_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset"
},
{
"fieldname": "disposal_date",
Expand All @@ -227,15 +227,15 @@
"fieldname": "gross_purchase_amount",
"fieldtype": "Currency",
"label": "Gross Purchase Amount",
"mandatory_depends_on": "eval:(!doc.is_composite_asset || doc.docstatus==1)",
"options": "Company:company:default_currency",
"read_only_depends_on": "eval:!doc.is_existing_asset",
"reqd": 1
"read_only_depends_on": "eval:!doc.is_existing_asset"
},
{
"fieldname": "available_for_use_date",
"fieldtype": "Date",
"label": "Available-for-use Date",
"reqd": 1
"mandatory_depends_on": "eval:(!doc.is_composite_asset || doc.docstatus==1)"
},
{
"default": "0",
Expand Down Expand Up @@ -583,7 +583,7 @@
"link_fieldname": "target_asset"
}
],
"modified": "2023-12-21 16:46:20.732869",
"modified": "2024-01-05 17:36:53.131512",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
Expand Down
91 changes: 90 additions & 1 deletion erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,86 @@


class Asset(AccountsController):
<<<<<<< HEAD
=======
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from frappe.types import DF

from erpnext.assets.doctype.asset_finance_book.asset_finance_book import AssetFinanceBook

additional_asset_cost: DF.Currency
amended_from: DF.Link | None
asset_category: DF.Link | None
asset_name: DF.Data
asset_owner: DF.Literal["", "Company", "Supplier", "Customer"]
asset_owner_company: DF.Link | None
asset_quantity: DF.Int
available_for_use_date: DF.Date | None
booked_fixed_asset: DF.Check
calculate_depreciation: DF.Check
capitalized_in: DF.Link | None
company: DF.Link
comprehensive_insurance: DF.Data | None
cost_center: DF.Link | None
custodian: DF.Link | None
customer: DF.Link | None
default_finance_book: DF.Link | None
department: DF.Link | None
depr_entry_posting_status: DF.Literal["", "Successful", "Failed"]
depreciation_method: DF.Literal["", "Straight Line", "Double Declining Balance", "Manual"]
disposal_date: DF.Date | None
finance_books: DF.Table[AssetFinanceBook]
frequency_of_depreciation: DF.Int
gross_purchase_amount: DF.Currency
image: DF.AttachImage | None
insurance_end_date: DF.Date | None
insurance_start_date: DF.Date | None
insured_value: DF.Data | None
insurer: DF.Data | None
is_composite_asset: DF.Check
is_existing_asset: DF.Check
is_fully_depreciated: DF.Check
item_code: DF.Link
item_name: DF.ReadOnly | None
journal_entry_for_scrap: DF.Link | None
location: DF.Link
maintenance_required: DF.Check
naming_series: DF.Literal["ACC-ASS-.YYYY.-"]
next_depreciation_date: DF.Date | None
number_of_depreciations_booked: DF.Int
opening_accumulated_depreciation: DF.Currency
policy_number: DF.Data | None
purchase_date: DF.Date | None
purchase_invoice: DF.Link | None
purchase_receipt: DF.Link | None
purchase_receipt_amount: DF.Currency
split_from: DF.Link | None
status: DF.Literal[
"Draft",
"Submitted",
"Partially Depreciated",
"Fully Depreciated",
"Sold",
"Scrapped",
"In Maintenance",
"Out of Order",
"Issue",
"Receipt",
"Capitalized",
"Decapitalized",
]
supplier: DF.Link | None
total_asset_cost: DF.Currency
total_number_of_depreciations: DF.Int
value_after_depreciation: DF.Currency
# end: auto-generated types

>>>>>>> c34f09c503 (fix: Purchase date and amount is not mandatory for composite asset creation)
def validate(self):
self.validate_asset_values()
self.validate_asset_and_reference()
Expand Down Expand Up @@ -247,7 +327,16 @@ def validate_asset_values(self):
frappe.throw(_("Gross Purchase Amount is mandatory"), frappe.MandatoryError)

if is_cwip_accounting_enabled(self.asset_category):
<<<<<<< HEAD
if not self.is_existing_asset and not (self.purchase_receipt or self.purchase_invoice):
=======
if (
not self.is_existing_asset
and not self.is_composite_asset
and not self.purchase_receipt
and not self.purchase_invoice
):
>>>>>>> c34f09c503 (fix: Purchase date and amount is not mandatory for composite asset creation)
frappe.throw(
_("Please create purchase receipt or purchase invoice for the item {0}").format(
self.item_code
Expand All @@ -260,7 +349,7 @@ def validate_asset_values(self):
and not frappe.db.get_value("Purchase Invoice", self.purchase_invoice, "update_stock")
):
frappe.throw(
_("Update stock must be enable for the purchase invoice {0}").format(self.purchase_invoice)
_("Update stock must be enabled for the purchase invoice {0}").format(self.purchase_invoice)
)

if not self.calculate_depreciation:
Expand Down

0 comments on commit 0f6477a

Please sign in to comment.