test: LCV entries after billing

(cherry picked from commit 53642e7417)

# Conflicts:
#	erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
This commit is contained in:
Gursheen Anand
2024-02-29 11:26:31 +05:30
committed by Mergify
parent 83ccb32be6
commit c7c9d33954
2 changed files with 67 additions and 8 deletions

View File

@@ -118,7 +118,11 @@ class StockController(AccountsController):
if self.docstatus == 1:
if not gl_entries:
gl_entries = self.get_gl_entries(warehouse_account, via_landed_cost_voucher)
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):

View File

@@ -2426,6 +2426,7 @@ class TestPurchaseReceipt(FrappeTestCase):
pr.reload()
self.assertEqual(pr.per_billed, 100)
<<<<<<< HEAD
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",
@@ -2912,6 +2913,50 @@ class TestPurchaseReceipt(FrappeTestCase):
"Serial and Batch Bundle", return_pr.items[0].rejected_serial_and_batch_bundle, "total_qty"
),
)
=======
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,
)
company = frappe.get_doc("Company", "_Test Company")
company.enable_perpetual_inventory = 1
company.default_inventory_account = "Stock In Hand - _TC"
company.stock_received_but_not_billed = "Stock Received But Not Billed - _TC"
company.save()
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()
lcv = 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)
expected_gle = (
("Stock Received But Not Billed - _TC", 0, 10000, "Main - _TC"),
("Stock In Hand - _TC", 14000, 0, "Main - _TC"),
("Freight and Forwarding Charges - _TC", 0, 2000, "Main - _TC"),
("Expenses Included In Valuation - _TC", 0, 2000, "Main - _TC"),
)
self.assertSequenceEqual(expected_gle, gl_entries)
>>>>>>> 53642e7417 (test: LCV entries after billing)
def prepare_data_for_internal_transfer():
@@ -2959,14 +3004,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):