mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-24 17:18:30 +00:00
fix: enforce permission check for purchase invoice and update test to use service expense account
This commit is contained in:
@@ -490,6 +490,8 @@ def get_repair_cost_for_purchase_invoice(purchase_invoice: str) -> float:
|
|||||||
if not purchase_invoice:
|
if not purchase_invoice:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
frappe.has_permission("Purchase Invoice", "read", purchase_invoice, throw=True)
|
||||||
|
|
||||||
expense_accounts = _get_expense_accounts_for_purchase_invoice(purchase_invoice)
|
expense_accounts = _get_expense_accounts_for_purchase_invoice(purchase_invoice)
|
||||||
|
|
||||||
if not expense_accounts:
|
if not expense_accounts:
|
||||||
@@ -502,7 +504,7 @@ def _get_expense_accounts_for_purchase_invoice(purchase_invoice: str) -> list[st
|
|||||||
"""
|
"""
|
||||||
Get expense accounts for non-stock items from the purchase invoice.
|
Get expense accounts for non-stock items from the purchase invoice.
|
||||||
"""
|
"""
|
||||||
pi_items = frappe.db.get_list(
|
pi_items = frappe.get_all(
|
||||||
"Purchase Invoice Item",
|
"Purchase Invoice Item",
|
||||||
filters={"parent": purchase_invoice},
|
filters={"parent": purchase_invoice},
|
||||||
fields=["item_code", "expense_account", "is_fixed_asset"],
|
fields=["item_code", "expense_account", "is_fixed_asset"],
|
||||||
|
|||||||
@@ -343,14 +343,14 @@ class TestAssetRepair(unittest.TestCase):
|
|||||||
company=company,
|
company=company,
|
||||||
)
|
)
|
||||||
|
|
||||||
expense_account = frappe.db.get_value("Company", company, "default_expense_account")
|
service_expense_account = "Miscellaneous Expenses - TCP1"
|
||||||
cost_center = frappe.db.get_value("Company", company, "cost_center")
|
cost_center = frappe.db.get_value("Company", company, "cost_center")
|
||||||
|
|
||||||
pi = make_purchase_invoice(
|
pi = make_purchase_invoice(
|
||||||
item_code=service_item.name,
|
item_code=service_item.name,
|
||||||
qty=1,
|
qty=1,
|
||||||
rate=500,
|
rate=500,
|
||||||
expense_account=expense_account,
|
expense_account=service_expense_account,
|
||||||
cost_center=cost_center,
|
cost_center=cost_center,
|
||||||
warehouse=warehouse,
|
warehouse=warehouse,
|
||||||
update_stock=0,
|
update_stock=0,
|
||||||
@@ -466,6 +466,7 @@ def create_asset_repair(**args):
|
|||||||
if asset.calculate_depreciation:
|
if asset.calculate_depreciation:
|
||||||
asset_repair.increase_in_asset_life = 12
|
asset_repair.increase_in_asset_life = 12
|
||||||
pi = make_purchase_invoice(
|
pi = make_purchase_invoice(
|
||||||
|
item=args.item or "_Test Non Stock Item",
|
||||||
company=asset.company,
|
company=asset.company,
|
||||||
expense_account=frappe.db.get_value("Company", asset.company, "default_expense_account"),
|
expense_account=frappe.db.get_value("Company", asset.company, "default_expense_account"),
|
||||||
cost_center=asset_repair.cost_center,
|
cost_center=asset_repair.cost_center,
|
||||||
|
|||||||
Reference in New Issue
Block a user