blob: 0fe5008304556fc5ede472788198a016834fe071 [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(
Ankush Menat494bd9e2022-03-28 18:52:46 +053046 voucher_type_and_no in gl_entries,
47 msg="get_voucherwise_gl_entries not returning expected GLes",
rohitwaghchaure058d9832021-09-07 12:14:40 +053048 )
tundebabzy40a02762017-10-25 07:54:34 +010049
50
51ADDRESS_RECORDS = [
52 {
53 "doctype": "Address",
54 "address_type": "Billing",
55 "address_line1": "Address line 1",
56 "address_title": "_Test Billing Address Title",
57 "city": "Lagos",
58 "country": "Nigeria",
59 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053060 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
61 ],
tundebabzy40a02762017-10-25 07:54:34 +010062 },
63 {
64 "doctype": "Address",
65 "address_type": "Shipping",
66 "address_line1": "Address line 2",
67 "address_title": "_Test Shipping Address 1 Title",
68 "city": "Lagos",
69 "country": "Nigeria",
70 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053071 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
72 ],
tundebabzy40a02762017-10-25 07:54:34 +010073 },
74 {
75 "doctype": "Address",
76 "address_type": "Shipping",
77 "address_line1": "Address line 3",
78 "address_title": "_Test Shipping Address 2 Title",
79 "city": "Lagos",
80 "country": "Nigeria",
81 "is_shipping_address": "1",
82 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053083 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
84 ],
tundebabzy40a02762017-10-25 07:54:34 +010085 },
86 {
87 "doctype": "Address",
88 "address_type": "Billing",
89 "address_line1": "Address line 4",
90 "address_title": "_Test Billing Address 2 Title",
91 "city": "Lagos",
92 "country": "Nigeria",
93 "is_shipping_address": "1",
94 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053095 {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
96 ],
97 },
tundebabzy40a02762017-10-25 07:54:34 +010098]