You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

125 lines
3.6 KiB

  1. import unittest
  2. import frappe
  3. from frappe.test_runner import make_test_objects
  4. from erpnext.accounts.party import get_party_shipping_address
  5. from erpnext.accounts.utils import (
  6. get_future_stock_vouchers,
  7. get_voucherwise_gl_entries,
  8. sort_stock_vouchers_by_posting_date,
  9. )
  10. from erpnext.stock.doctype.item.test_item import make_item
  11. from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
  12. from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
  13. class TestUtils(unittest.TestCase):
  14. @classmethod
  15. def setUpClass(cls):
  16. super(TestUtils, cls).setUpClass()
  17. make_test_objects("Address", ADDRESS_RECORDS)
  18. def test_get_party_shipping_address(self):
  19. address = get_party_shipping_address("Customer", "_Test Customer 1")
  20. self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
  21. def test_get_party_shipping_address2(self):
  22. address = get_party_shipping_address("Customer", "_Test Customer 2")
  23. self.assertEqual(address, "_Test Shipping Address 2 Title-Shipping")
  24. def test_get_voucher_wise_gl_entry(self):
  25. pr = make_purchase_receipt(
  26. item_code="_Test Item",
  27. posting_date="2021-02-01",
  28. rate=100,
  29. qty=1,
  30. warehouse="Stores - TCP1",
  31. company="_Test Company with perpetual inventory",
  32. )
  33. future_vouchers = get_future_stock_vouchers("2021-01-01", "00:00:00", for_items=["_Test Item"])
  34. voucher_type_and_no = ("Purchase Receipt", pr.name)
  35. self.assertTrue(
  36. voucher_type_and_no in future_vouchers,
  37. msg="get_future_stock_vouchers not returning correct value",
  38. )
  39. posting_date = "2021-01-01"
  40. gl_entries = get_voucherwise_gl_entries(future_vouchers, posting_date)
  41. self.assertTrue(
  42. voucher_type_and_no in gl_entries,
  43. msg="get_voucherwise_gl_entries not returning expected GLes",
  44. )
  45. def test_stock_voucher_sorting(self):
  46. vouchers = []
  47. item = make_item().name
  48. stock_entry = {"item": item, "to_warehouse": "_Test Warehouse - _TC", "qty": 1, "rate": 10}
  49. se1 = make_stock_entry(posting_date="2022-01-01", **stock_entry)
  50. se3 = make_stock_entry(posting_date="2022-03-01", **stock_entry)
  51. se2 = make_stock_entry(posting_date="2022-02-01", **stock_entry)
  52. for doc in (se1, se2, se3):
  53. vouchers.append((doc.doctype, doc.name))
  54. vouchers.append(("Stock Entry", "Wat"))
  55. sorted_vouchers = sort_stock_vouchers_by_posting_date(list(reversed(vouchers)))
  56. self.assertEqual(sorted_vouchers, vouchers)
  57. ADDRESS_RECORDS = [
  58. {
  59. "doctype": "Address",
  60. "address_type": "Billing",
  61. "address_line1": "Address line 1",
  62. "address_title": "_Test Billing Address Title",
  63. "city": "Lagos",
  64. "country": "Nigeria",
  65. "links": [
  66. {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
  67. ],
  68. },
  69. {
  70. "doctype": "Address",
  71. "address_type": "Shipping",
  72. "address_line1": "Address line 2",
  73. "address_title": "_Test Shipping Address 1 Title",
  74. "city": "Lagos",
  75. "country": "Nigeria",
  76. "links": [
  77. {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
  78. ],
  79. },
  80. {
  81. "doctype": "Address",
  82. "address_type": "Shipping",
  83. "address_line1": "Address line 3",
  84. "address_title": "_Test Shipping Address 2 Title",
  85. "city": "Lagos",
  86. "country": "Nigeria",
  87. "is_shipping_address": "1",
  88. "links": [
  89. {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
  90. ],
  91. },
  92. {
  93. "doctype": "Address",
  94. "address_type": "Billing",
  95. "address_line1": "Address line 4",
  96. "address_title": "_Test Billing Address 2 Title",
  97. "city": "Lagos",
  98. "country": "Nigeria",
  99. "is_shipping_address": "1",
  100. "links": [
  101. {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
  102. ],
  103. },
  104. ]