blob: effc913da05acb9d17470a231f3cd2ea803b4b18 [file] [log] [blame]
tundebabzy40a02762017-10-25 07:54:34 +01001import unittest
Chillar Anand915b3432021-09-02 16:44:59 +05302
tundebabzy40a02762017-10-25 07:54:34 +01003from frappe.test_runner import make_test_objects
4
Chillar Anand915b3432021-09-02 16:44:59 +05305from erpnext.accounts.party import get_party_shipping_address
rohitwaghchaure058d9832021-09-07 12:14:40 +05306from erpnext.accounts.utils import get_future_stock_vouchers, get_voucherwise_gl_entries
7from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
Chillar Anand915b3432021-09-02 16:44:59 +05308
tundebabzy40a02762017-10-25 07:54:34 +01009
10class TestUtils(unittest.TestCase):
11 @classmethod
12 def setUpClass(cls):
13 super(TestUtils, cls).setUpClass()
rohitwaghchaure058d9832021-09-07 12:14:40 +053014 make_test_objects("Address", ADDRESS_RECORDS)
tundebabzy40a02762017-10-25 07:54:34 +010015
16 def test_get_party_shipping_address(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053017 address = get_party_shipping_address("Customer", "_Test Customer 1")
18 self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
tundebabzy40a02762017-10-25 07:54:34 +010019
20 def test_get_party_shipping_address2(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053021 address = get_party_shipping_address("Customer", "_Test Customer 2")
22 self.assertEqual(address, "_Test Shipping Address 2 Title-Shipping")
23
24 def test_get_voucher_wise_gl_entry(self):
25
26 pr = make_purchase_receipt(
27 item_code="_Test Item",
28 posting_date="2021-02-01",
29 rate=100,
30 qty=1,
31 warehouse="Stores - TCP1",
32 company="_Test Company with perpetual inventory",
33 )
34
35 future_vouchers = get_future_stock_vouchers("2021-01-01", "00:00:00", for_items=["_Test Item"])
36
37 voucher_type_and_no = ("Purchase Receipt", pr.name)
38 self.assertTrue(
39 voucher_type_and_no in future_vouchers,
40 msg="get_future_stock_vouchers not returning correct value",
41 )
42
43 posting_date = "2021-01-01"
44 gl_entries = get_voucherwise_gl_entries(future_vouchers, posting_date)
45 self.assertTrue(
46 voucher_type_and_no in gl_entries, msg="get_voucherwise_gl_entries not returning expected GLes",
47 )
tundebabzy40a02762017-10-25 07:54:34 +010048
49
50ADDRESS_RECORDS = [
51 {
52 "doctype": "Address",
53 "address_type": "Billing",
54 "address_line1": "Address line 1",
55 "address_title": "_Test Billing Address Title",
56 "city": "Lagos",
57 "country": "Nigeria",
58 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053059 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
60 ],
tundebabzy40a02762017-10-25 07:54:34 +010061 },
62 {
63 "doctype": "Address",
64 "address_type": "Shipping",
65 "address_line1": "Address line 2",
66 "address_title": "_Test Shipping Address 1 Title",
67 "city": "Lagos",
68 "country": "Nigeria",
69 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053070 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
71 ],
tundebabzy40a02762017-10-25 07:54:34 +010072 },
73 {
74 "doctype": "Address",
75 "address_type": "Shipping",
76 "address_line1": "Address line 3",
77 "address_title": "_Test Shipping Address 2 Title",
78 "city": "Lagos",
79 "country": "Nigeria",
80 "is_shipping_address": "1",
81 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053082 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
83 ],
tundebabzy40a02762017-10-25 07:54:34 +010084 },
85 {
86 "doctype": "Address",
87 "address_type": "Billing",
88 "address_line1": "Address line 4",
89 "address_title": "_Test Billing Address 2 Title",
90 "city": "Lagos",
91 "country": "Nigeria",
92 "is_shipping_address": "1",
93 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053094 {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
95 ],
96 },
tundebabzy40a02762017-10-25 07:54:34 +010097]