blob: 4aca40cf6c0734ef5eca2f0f3587019de02bee76 [file] [log] [blame]
Chillar Anand915b3432021-09-02 16:44:59 +05301
tundebabzy40a02762017-10-25 07:54:34 +01002import unittest
Chillar Anand915b3432021-09-02 16:44:59 +05303
tundebabzy40a02762017-10-25 07:54:34 +01004from frappe.test_runner import make_test_objects
5
Chillar Anand915b3432021-09-02 16:44:59 +05306from erpnext.accounts.party import get_party_shipping_address
rohitwaghchaure058d9832021-09-07 12:14:40 +05307from erpnext.accounts.utils import get_future_stock_vouchers, get_voucherwise_gl_entries
8from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
Chillar Anand915b3432021-09-02 16:44:59 +05309
tundebabzy40a02762017-10-25 07:54:34 +010010
11class TestUtils(unittest.TestCase):
12 @classmethod
13 def setUpClass(cls):
14 super(TestUtils, cls).setUpClass()
rohitwaghchaure058d9832021-09-07 12:14:40 +053015 make_test_objects("Address", ADDRESS_RECORDS)
tundebabzy40a02762017-10-25 07:54:34 +010016
17 def test_get_party_shipping_address(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053018 address = get_party_shipping_address("Customer", "_Test Customer 1")
19 self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
tundebabzy40a02762017-10-25 07:54:34 +010020
21 def test_get_party_shipping_address2(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053022 address = get_party_shipping_address("Customer", "_Test Customer 2")
23 self.assertEqual(address, "_Test Shipping Address 2 Title-Shipping")
24
25 def test_get_voucher_wise_gl_entry(self):
26
27 pr = make_purchase_receipt(
28 item_code="_Test Item",
29 posting_date="2021-02-01",
30 rate=100,
31 qty=1,
32 warehouse="Stores - TCP1",
33 company="_Test Company with perpetual inventory",
34 )
35
36 future_vouchers = get_future_stock_vouchers("2021-01-01", "00:00:00", for_items=["_Test Item"])
37
38 voucher_type_and_no = ("Purchase Receipt", pr.name)
39 self.assertTrue(
40 voucher_type_and_no in future_vouchers,
41 msg="get_future_stock_vouchers not returning correct value",
42 )
43
44 posting_date = "2021-01-01"
45 gl_entries = get_voucherwise_gl_entries(future_vouchers, posting_date)
46 self.assertTrue(
47 voucher_type_and_no in gl_entries, msg="get_voucherwise_gl_entries not returning expected GLes",
48 )
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]