fix: purchase receipt item showing wrong expense account (#51362)

This commit is contained in:
Mihir Kandoi
2025-12-30 11:51:50 +05:30
committed by GitHub
parent 875bf5c8a9
commit 0c43c07cf6
6 changed files with 17 additions and 5 deletions

View File

@@ -25,7 +25,6 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_accounting_dimensions,
)
from erpnext.accounts.doctype.subscription_plan.subscription_plan import get_plan_rate
from erpnext.accounts.party import get_party_account_currency
class InvoiceCancelled(frappe.ValidationError):

View File

@@ -653,7 +653,7 @@ def reset_settings():
def create_subscription(**kwargs):
subscription = frappe.new_doc("Subscription")
subscription.party_type = (kwargs.get("party_type") or "Customer",)
subscription.party_type = kwargs.get("party_type") or "Customer"
subscription.company = kwargs.get("company") or "_Test Company"
subscription.party = kwargs.get("party") or "_Test Customer"
subscription.trial_period_start = kwargs.get("trial_period_start")

View File

@@ -748,6 +748,7 @@ def make_purchase_receipt(source_name, target_doc=None, args=None):
"sales_order_item": "sales_order_item",
"wip_composite_asset": "wip_composite_asset",
},
"field_no_map": ["expense_account"],
"postprocess": update_item,
"condition": lambda doc: (
True if is_unit_price_row(doc) else abs(doc.received_qty) < abs(doc.qty)

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import json
import unittest
import frappe
from frappe import _

View File

@@ -755,7 +755,7 @@ class PurchaseReceipt(BuyingController):
stock_asset_rbnb = (
self.get_company_default("asset_received_but_not_billed")
if d.is_fixed_asset
else self.get_company_default("stock_received_but_not_billed")
else (d.expense_account or self.get_company_default("stock_received_but_not_billed"))
)
landed_cost_entries = self.get_item_account_wise_lcv_entries()
if d.is_fixed_asset:
@@ -809,7 +809,7 @@ class PurchaseReceipt(BuyingController):
stock_asset_rbnb = (
self.get_company_default("asset_received_but_not_billed")
if d.is_fixed_asset
else self.get_company_default("stock_received_but_not_billed")
else (d.expense_account or self.get_company_default("stock_received_but_not_billed"))
)
stock_value_diff = get_stock_value_difference(self.name, d.name, d.rejected_warehouse)

View File

@@ -434,6 +434,19 @@ def get_basic_details(ctx: ItemDetailsCtx, item, overwrite_warehouse=True) -> It
expense_account = get_asset_category_account(
fieldname="fixed_asset_account", item=ctx.item_code, company=ctx.company
)
elif ctx.doctype == "Purchase Receipt":
from erpnext.accounts.utils import get_company_default
if not (
frappe.get_value("Company", ctx.company, "enable_provisional_accounting_for_non_stock_items")
and not item.is_stock_item
and ctx.qty
):
expense_account = (
get_company_default(ctx.company, "stock_received_but_not_billed")
if not frappe.in_test
else f'Stock Received But Not Billed - {frappe.get_value("Company", ctx.company, "abbr")}'
)
# Set the UOM to the Default Sales UOM or Default Purchase UOM if configured in the Item Master
if not ctx.uom: