mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
test: tax account heads on PR report without LCV
(cherry picked from commit 9562628ed6)
# Conflicts:
# erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
This commit is contained in:
@@ -2499,6 +2499,172 @@ class TestPurchaseReceipt(FrappeTestCase):
|
|||||||
lcv.save().submit()
|
lcv.save().submit()
|
||||||
return lcv
|
return lcv
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
def test_tax_account_heads_on_item_repost_without_lcv(self):
|
||||||
|
"""
|
||||||
|
PO -> PR -> PI
|
||||||
|
Backdated `Repost Item valuation` should not merge tax account heads into stock_rbnb if Purchase Receipt was created first
|
||||||
|
This scenario is without LCV
|
||||||
|
"""
|
||||||
|
from erpnext.accounts.doctype.account.test_account import create_account
|
||||||
|
from erpnext.buying.doctype.purchase_order.test_purchase_order import (
|
||||||
|
create_purchase_order,
|
||||||
|
make_pr_against_po,
|
||||||
|
)
|
||||||
|
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
||||||
|
|
||||||
|
stock_rbnb = "Stock Received But Not Billed - _TC"
|
||||||
|
stock_in_hand = "Stock In Hand - _TC"
|
||||||
|
test_cc = "_Test Cost Center - _TC"
|
||||||
|
test_company = "_Test Company"
|
||||||
|
creditors = "Creditors - _TC"
|
||||||
|
|
||||||
|
company_doc = frappe.get_doc("Company", test_company)
|
||||||
|
company_doc.enable_perpetual_inventory = True
|
||||||
|
company_doc.stock_received_but_not_billed = stock_rbnb
|
||||||
|
company_doc.default_inventory_account = stock_in_hand
|
||||||
|
company_doc.save()
|
||||||
|
|
||||||
|
packaging_charges_account = create_account(
|
||||||
|
account_name="Packaging Charges",
|
||||||
|
parent_account="Indirect Expenses - _TC",
|
||||||
|
company=test_company,
|
||||||
|
account_type="Tax",
|
||||||
|
)
|
||||||
|
|
||||||
|
po = create_purchase_order(qty=10, rate=100, do_not_save=1)
|
||||||
|
po.taxes = []
|
||||||
|
po.append(
|
||||||
|
"taxes",
|
||||||
|
{
|
||||||
|
"category": "Valuation and Total",
|
||||||
|
"account_head": packaging_charges_account,
|
||||||
|
"cost_center": test_cc,
|
||||||
|
"description": "Test",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"charge_type": "Actual",
|
||||||
|
"tax_amount": 250,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
po.save().submit()
|
||||||
|
|
||||||
|
pr = make_pr_against_po(po.name, received_qty=10)
|
||||||
|
pr_gl_entries = get_gl_entries(pr.doctype, pr.name, skip_cancelled=True)
|
||||||
|
expected_pr_gles = [
|
||||||
|
{"account": stock_rbnb, "debit": 0.0, "credit": 1000.0, "cost_center": test_cc},
|
||||||
|
{"account": stock_in_hand, "debit": 1250.0, "credit": 0.0, "cost_center": test_cc},
|
||||||
|
{"account": packaging_charges_account, "debit": 0.0, "credit": 250.0, "cost_center": test_cc},
|
||||||
|
]
|
||||||
|
self.assertEqual(expected_pr_gles, pr_gl_entries)
|
||||||
|
|
||||||
|
# Make PI against Purchase Receipt
|
||||||
|
pi = make_purchase_invoice(pr.name).save().submit()
|
||||||
|
pi_gl_entries = get_gl_entries(pi.doctype, pi.name, skip_cancelled=True)
|
||||||
|
expected_pi_gles = [
|
||||||
|
{"account": stock_rbnb, "debit": 1000.0, "credit": 0.0, "cost_center": test_cc},
|
||||||
|
{"account": packaging_charges_account, "debit": 250.0, "credit": 0.0, "cost_center": test_cc},
|
||||||
|
{"account": creditors, "debit": 0.0, "credit": 1250.0, "cost_center": None},
|
||||||
|
]
|
||||||
|
self.assertEqual(expected_pi_gles, pi_gl_entries)
|
||||||
|
|
||||||
|
# Trigger Repost Item Valudation on a older date
|
||||||
|
repost_doc = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Repost Item Valuation",
|
||||||
|
"based_on": "Item and Warehouse",
|
||||||
|
"item_code": pr.items[0].item_code,
|
||||||
|
"warehouse": pr.items[0].warehouse,
|
||||||
|
"posting_date": add_days(pr.posting_date, -1),
|
||||||
|
"posting_time": "00:00:00",
|
||||||
|
"company": pr.company,
|
||||||
|
"allow_negative_stock": 1,
|
||||||
|
"via_landed_cost_voucher": 0,
|
||||||
|
"allow_zero_rate": 0,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
repost_doc.save().submit()
|
||||||
|
|
||||||
|
pr_gles_after_repost = get_gl_entries(pr.doctype, pr.name, skip_cancelled=True)
|
||||||
|
expected_pr_gles_after_repost = [
|
||||||
|
{"account": stock_rbnb, "debit": 0.0, "credit": 1000.0, "cost_center": test_cc},
|
||||||
|
{"account": stock_in_hand, "debit": 1250.0, "credit": 0.0, "cost_center": test_cc},
|
||||||
|
{"account": packaging_charges_account, "debit": 0.0, "credit": 250.0, "cost_center": test_cc},
|
||||||
|
]
|
||||||
|
self.assertEqual(len(pr_gles_after_repost), len(expected_pr_gles_after_repost))
|
||||||
|
self.assertEqual(expected_pr_gles_after_repost, pr_gles_after_repost)
|
||||||
|
|
||||||
|
# teardown
|
||||||
|
pi.reload()
|
||||||
|
pi.cancel()
|
||||||
|
pr.reload()
|
||||||
|
pr.cancel()
|
||||||
|
|
||||||
|
company_doc.enable_perpetual_inventory = False
|
||||||
|
company_doc.stock_received_but_not_billed = None
|
||||||
|
company_doc.default_inventory_account = None
|
||||||
|
company_doc.save()
|
||||||
|
|
||||||
|
def test_do_not_use_batchwise_valuation_rate(self):
|
||||||
|
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
|
||||||
|
|
||||||
|
item_code = "Test Item for Do Not Use Batchwise Valuation"
|
||||||
|
make_item(
|
||||||
|
item_code,
|
||||||
|
properties={
|
||||||
|
"is_stock_item": 1,
|
||||||
|
"has_batch_no": 1,
|
||||||
|
"create_new_batch": 1,
|
||||||
|
"batch_number_series": "TIDNBV-.#####",
|
||||||
|
"valuation_method": "Moving Average",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# 1st pr for 100 rate
|
||||||
|
pr = make_purchase_receipt(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=1,
|
||||||
|
rate=100,
|
||||||
|
posting_date=add_days(today(), -2),
|
||||||
|
)
|
||||||
|
|
||||||
|
make_purchase_receipt(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=1,
|
||||||
|
rate=200,
|
||||||
|
posting_date=add_days(today(), -1),
|
||||||
|
)
|
||||||
|
|
||||||
|
dn = create_delivery_note(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=1,
|
||||||
|
rate=300,
|
||||||
|
posting_date=today(),
|
||||||
|
use_serial_batch_fields=1,
|
||||||
|
batch_no=get_batch_from_bundle(pr.items[0].serial_and_batch_bundle),
|
||||||
|
)
|
||||||
|
dn.reload()
|
||||||
|
bundle = dn.items[0].serial_and_batch_bundle
|
||||||
|
|
||||||
|
valuation_rate = frappe.db.get_value("Serial and Batch Bundle", bundle, "avg_rate")
|
||||||
|
self.assertEqual(valuation_rate, 100)
|
||||||
|
|
||||||
|
doc = frappe.get_doc("Stock Settings")
|
||||||
|
doc.do_not_use_batchwise_valuation = 1
|
||||||
|
doc.flags.ignore_validate = True
|
||||||
|
doc.save()
|
||||||
|
|
||||||
|
pr.repost_future_sle_and_gle(force=True)
|
||||||
|
|
||||||
|
valuation_rate = frappe.db.get_value("Serial and Batch Bundle", bundle, "avg_rate")
|
||||||
|
self.assertEqual(valuation_rate, 150)
|
||||||
|
|
||||||
|
doc = frappe.get_doc("Stock Settings")
|
||||||
|
doc.do_not_use_batchwise_valuation = 0
|
||||||
|
doc.flags.ignore_validate = True
|
||||||
|
doc.save()
|
||||||
|
|
||||||
|
>>>>>>> 9562628ed6 (test: tax account heads on PR report without LCV)
|
||||||
|
|
||||||
def prepare_data_for_internal_transfer():
|
def prepare_data_for_internal_transfer():
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||||
|
|||||||
Reference in New Issue
Block a user