Merge pull request #40187 from GursheenK/valuation-tax-gle-via-lcv
fix: valuation tax entries on LCV after billing PR
This commit is contained in:
@@ -97,7 +97,7 @@ class StockController(AccountsController):
|
||||
)
|
||||
)
|
||||
|
||||
def make_gl_entries(self, gl_entries=None, from_repost=False):
|
||||
def make_gl_entries(self, gl_entries=None, from_repost=False, via_landed_cost_voucher=False):
|
||||
if self.docstatus == 2:
|
||||
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
||||
|
||||
@@ -118,7 +118,11 @@ class StockController(AccountsController):
|
||||
|
||||
if self.docstatus == 1:
|
||||
if not gl_entries:
|
||||
gl_entries = self.get_gl_entries(warehouse_account)
|
||||
gl_entries = (
|
||||
self.get_gl_entries(warehouse_account, via_landed_cost_voucher)
|
||||
if self.doctype == "Purchase Receipt"
|
||||
else self.get_gl_entries(warehouse_account)
|
||||
)
|
||||
make_gl_entries(gl_entries, from_repost=from_repost)
|
||||
|
||||
def validate_serialized_batch(self):
|
||||
|
||||
@@ -252,6 +252,9 @@ class LandedCostVoucher(Document):
|
||||
doc.docstatus = 1
|
||||
doc.make_bundle_using_old_serial_batch_fields(via_landed_cost_voucher=True)
|
||||
doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True)
|
||||
if d.receipt_document_type == "Purchase Receipt":
|
||||
doc.make_gl_entries(via_landed_cost_voucher=True)
|
||||
else:
|
||||
doc.make_gl_entries()
|
||||
doc.repost_future_sle_and_gle(via_landed_cost_voucher=True)
|
||||
|
||||
|
||||
@@ -423,13 +423,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)
|
||||
@@ -767,7 +767,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
|
||||
@@ -802,6 +802,9 @@ class PurchaseReceipt(BuyingController):
|
||||
i = 1
|
||||
for tax in self.get("taxes"):
|
||||
if valuation_tax.get(tax.name):
|
||||
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
|
||||
@@ -809,11 +812,7 @@ class PurchaseReceipt(BuyingController):
|
||||
and voucher_no=pi.parent and account=%s)""",
|
||||
(self.name, tax.account_head),
|
||||
)
|
||||
|
||||
if negative_expense_booked_in_pi:
|
||||
account = stock_rbnb
|
||||
else:
|
||||
account = 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
|
||||
|
||||
@@ -10,6 +10,7 @@ import erpnext
|
||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||
from erpnext.controllers.accounts_controller import InvalidQtyError
|
||||
from erpnext.controllers.buying_controller import QtyMismatchError
|
||||
from erpnext.stock import get_warehouse_account_map
|
||||
from erpnext.stock.doctype.item.test_item import create_item, make_item
|
||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
||||
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import (
|
||||
@@ -1720,7 +1721,6 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
frappe.db.set_single_value("Stock Settings", "over_delivery_receipt_allowance", 0)
|
||||
|
||||
def test_internal_pr_gl_entries(self):
|
||||
from erpnext.stock import get_warehouse_account_map
|
||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
|
||||
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||
@@ -2466,6 +2466,54 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
pr.reload()
|
||||
self.assertEqual(pr.per_billed, 100)
|
||||
|
||||
def test_valuation_taxes_lcv_repost_after_billing(self):
|
||||
from erpnext.stock.doctype.landed_cost_voucher.test_landed_cost_voucher import (
|
||||
make_landed_cost_voucher,
|
||||
)
|
||||
|
||||
old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company")
|
||||
frappe.local.enable_perpetual_inventory["_Test Company"] = 1
|
||||
frappe.db.set_value(
|
||||
"Company",
|
||||
"_Test Company",
|
||||
"stock_received_but_not_billed",
|
||||
"Stock Received But Not Billed - _TC",
|
||||
)
|
||||
|
||||
pr = make_purchase_receipt(qty=10, rate=1000, do_not_submit=1)
|
||||
pr.append(
|
||||
"taxes",
|
||||
{
|
||||
"category": "Valuation and Total",
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Freight and Forwarding Charges - _TC",
|
||||
"tax_amount": 2000,
|
||||
"description": "Test",
|
||||
},
|
||||
)
|
||||
pr.submit()
|
||||
pi = make_purchase_invoice(pr.name)
|
||||
pi.submit()
|
||||
make_landed_cost_voucher(
|
||||
company=pr.company,
|
||||
receipt_document_type="Purchase Receipt",
|
||||
receipt_document=pr.name,
|
||||
charges=2000,
|
||||
distribute_charges_based_on="Qty",
|
||||
expense_account="Expenses Included In Valuation - _TC",
|
||||
)
|
||||
|
||||
gl_entries = get_gl_entries("Purchase Receipt", pr.name, skip_cancelled=True, as_dict=False)
|
||||
warehouse_account = get_warehouse_account_map("_Test Company")
|
||||
expected_gle = (
|
||||
("Stock Received But Not Billed - _TC", 0, 10000, "Main - _TC"),
|
||||
("Freight and Forwarding Charges - _TC", 0, 2000, "Main - _TC"),
|
||||
("Expenses Included In Valuation - _TC", 0, 2000, "Main - _TC"),
|
||||
(warehouse_account[pr.items[0].warehouse]["account"], 14000, 0, "Main - _TC"),
|
||||
)
|
||||
self.assertSequenceEqual(expected_gle, gl_entries)
|
||||
frappe.local.enable_perpetual_inventory["_Test Company"] = old_perpetual_inventory
|
||||
|
||||
def test_purchase_receipt_with_use_serial_batch_field_for_rejected_qty(self):
|
||||
batch_item = make_item(
|
||||
"_Test Purchase Receipt Batch Item For Rejected Qty",
|
||||
@@ -2999,14 +3047,24 @@ def get_sl_entries(voucher_type, voucher_no):
|
||||
)
|
||||
|
||||
|
||||
def get_gl_entries(voucher_type, voucher_no):
|
||||
return frappe.db.sql(
|
||||
"""select account, debit, credit, cost_center, is_cancelled
|
||||
from `tabGL Entry` where voucher_type=%s and voucher_no=%s
|
||||
order by account desc""",
|
||||
(voucher_type, voucher_no),
|
||||
as_dict=1,
|
||||
def get_gl_entries(voucher_type, voucher_no, skip_cancelled=False, as_dict=True):
|
||||
gl = frappe.qb.DocType("GL Entry")
|
||||
gl_query = (
|
||||
frappe.qb.from_(gl)
|
||||
.select(
|
||||
gl.account,
|
||||
gl.debit,
|
||||
gl.credit,
|
||||
gl.cost_center,
|
||||
)
|
||||
.where((gl.voucher_type == voucher_type) & (gl.voucher_no == voucher_no))
|
||||
.orderby(gl.account, order=frappe.qb.desc)
|
||||
)
|
||||
if skip_cancelled:
|
||||
gl_query = gl_query.where(gl.is_cancelled == 0)
|
||||
else:
|
||||
gl_query = gl_query.select(gl.is_cancelled)
|
||||
return gl_query.run(as_dict=as_dict)
|
||||
|
||||
|
||||
def get_taxes(**args):
|
||||
|
||||
Reference in New Issue
Block a user