mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
test(stock): add test to validate company for receipts and expense accounts
(cherry picked from commit d58171987c)
This commit is contained in:
@@ -14,6 +14,10 @@ from erpnext.controllers.taxes_and_totals import init_landed_taxes_and_totals
|
|||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||||
|
|
||||||
|
|
||||||
|
class IncorrectCompanyValidationError(frappe.ValidationError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LandedCostVoucher(Document):
|
class LandedCostVoucher(Document):
|
||||||
# begin: auto-generated types
|
# begin: auto-generated types
|
||||||
# This code is auto-generated. Do not modify anything in this block.
|
# This code is auto-generated. Do not modify anything in this block.
|
||||||
@@ -121,6 +125,7 @@ class LandedCostVoucher(Document):
|
|||||||
frappe.bold(self.company),
|
frappe.bold(self.company),
|
||||||
),
|
),
|
||||||
title=_("Incorrect Company"),
|
title=_("Incorrect Company"),
|
||||||
|
exc=IncorrectCompanyValidationError,
|
||||||
)
|
)
|
||||||
|
|
||||||
if d.receipt_document_type == "Purchase Invoice":
|
if d.receipt_document_type == "Purchase Invoice":
|
||||||
@@ -169,6 +174,7 @@ class LandedCostVoucher(Document):
|
|||||||
frappe.bold(self.company),
|
frappe.bold(self.company),
|
||||||
),
|
),
|
||||||
title=_("Incorrect Account"),
|
title=_("Incorrect Account"),
|
||||||
|
exc=IncorrectCompanyValidationError,
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_total_taxes_and_charges(self):
|
def set_total_taxes_and_charges(self):
|
||||||
|
|||||||
@@ -174,6 +174,39 @@ class TestLandedCostVoucher(FrappeTestCase):
|
|||||||
self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)
|
self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)
|
||||||
self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0)
|
self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0)
|
||||||
|
|
||||||
|
def test_lcv_validates_company(self):
|
||||||
|
from erpnext.stock.doctype.landed_cost_voucher.landed_cost_voucher import (
|
||||||
|
IncorrectCompanyValidationError,
|
||||||
|
)
|
||||||
|
|
||||||
|
company_a = "_Test Company"
|
||||||
|
company_b = "_Test Company with perpetual inventory"
|
||||||
|
|
||||||
|
pr = make_purchase_receipt(
|
||||||
|
company=company_a,
|
||||||
|
warehouse="Stores - _TC",
|
||||||
|
qty=1,
|
||||||
|
rate=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
lcv = make_landed_cost_voucher(
|
||||||
|
company=company_b,
|
||||||
|
receipt_document_type="Purchase Receipt",
|
||||||
|
receipt_document=pr.name,
|
||||||
|
charges=50,
|
||||||
|
do_not_save=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertRaises(IncorrectCompanyValidationError, lcv.validate_receipt_documents)
|
||||||
|
lcv.company = company_a
|
||||||
|
|
||||||
|
self.assertRaises(IncorrectCompanyValidationError, lcv.validate_expense_accounts)
|
||||||
|
lcv.taxes[0].expense_account = get_expense_account(company_a)
|
||||||
|
|
||||||
|
lcv.save()
|
||||||
|
distribute_landed_cost_on_items(lcv)
|
||||||
|
lcv.submit()
|
||||||
|
|
||||||
def test_landed_cost_voucher_for_zero_purchase_rate(self):
|
def test_landed_cost_voucher_for_zero_purchase_rate(self):
|
||||||
"Test impact of LCV on future stock balances."
|
"Test impact of LCV on future stock balances."
|
||||||
from erpnext.stock.doctype.item.test_item import make_item
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
|||||||
Reference in New Issue
Block a user