fix: add LCV flag to determine negative expenses

(cherry picked from commit baa3fee1bf)

# Conflicts:
#	erpnext/controllers/stock_controller.py
This commit is contained in:
Gursheen Anand
2024-02-29 09:04:24 +05:30
committed by Mergify
parent f9a7bb0544
commit 20b8ee1e90
3 changed files with 45 additions and 16 deletions

View File

@@ -224,7 +224,7 @@ class LandedCostVoucher(Document):
# update stock & gl entries for submit state of PR
doc.docstatus = 1
doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True)
doc.make_gl_entries()
doc.make_gl_entries(via_landed_cost_voucher=True)
doc.repost_future_sle_and_gle()
def validate_asset_qty_and_status(self, receipt_document_type, receipt_document):

View File

@@ -307,13 +307,13 @@ class PurchaseReceipt(BuyingController):
self.delete_auto_created_batches()
self.set_consumed_qty_in_subcontract_order()
def get_gl_entries(self, warehouse_account=None):
def get_gl_entries(self, warehouse_account=None, via_landed_cost_voucher=False):
from erpnext.accounts.general_ledger import process_gl_map
gl_entries = []
self.make_item_gl_entries(gl_entries, warehouse_account=warehouse_account)
self.make_tax_gl_entries(gl_entries)
self.make_tax_gl_entries(gl_entries, via_landed_cost_voucher)
update_regional_gl_entries(gl_entries, self)
return process_gl_map(gl_entries)
@@ -661,7 +661,7 @@ class PurchaseReceipt(BuyingController):
posting_date=posting_date,
)
def make_tax_gl_entries(self, gl_entries):
def make_tax_gl_entries(self, gl_entries, via_landed_cost_voucher=False):
negative_expense_to_be_booked = sum([flt(d.item_tax_amount) for d in self.get("items")])
is_asset_pr = any(d.is_fixed_asset for d in self.get("items"))
# Cost center-wise amount breakup for other charges included for valuation
@@ -696,18 +696,17 @@ class PurchaseReceipt(BuyingController):
i = 1
for tax in self.get("taxes"):
if valuation_tax.get(tax.name):
negative_expense_booked_in_pi = frappe.db.sql(
"""select name from `tabPurchase Invoice Item` pi
where docstatus = 1 and purchase_receipt=%s
and exists(select name from `tabGL Entry` where voucher_type='Purchase Invoice'
and voucher_no=pi.parent and account=%s)""",
(self.name, tax.account_head),
)
if negative_expense_booked_in_pi:
account = stock_rbnb
else:
if via_landed_cost_voucher:
account = tax.account_head
else:
negative_expense_booked_in_pi = frappe.db.sql(
"""select name from `tabPurchase Invoice Item` pi
where docstatus = 1 and purchase_receipt=%s
and exists(select name from `tabGL Entry` where voucher_type='Purchase Invoice'
and voucher_no=pi.parent and account=%s)""",
(self.name, tax.account_head),
)
account = stock_rbnb if negative_expense_booked_in_pi else tax.account_head
if i == len(valuation_tax):
applicable_amount = amount_including_divisional_loss