blob: c3f6d274437451bc251c74a39f3cb2db5d706daa [file] [log] [blame]
Aditya Hasef3c22f32019-01-22 18:22:20 +05301from __future__ import unicode_literals
Chillar Anand915b3432021-09-02 16:44:59 +05302
tundebabzy40a02762017-10-25 07:54:34 +01003import unittest
Chillar Anand915b3432021-09-02 16:44:59 +05304
tundebabzy40a02762017-10-25 07:54:34 +01005from frappe.test_runner import make_test_objects
6
Chillar Anand915b3432021-09-02 16:44:59 +05307from erpnext.accounts.party import get_party_shipping_address
rohitwaghchaure058d9832021-09-07 12:14:40 +05308from erpnext.accounts.utils import get_future_stock_vouchers, get_voucherwise_gl_entries
9from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
Chillar Anand915b3432021-09-02 16:44:59 +053010
tundebabzy40a02762017-10-25 07:54:34 +010011
12class TestUtils(unittest.TestCase):
13 @classmethod
14 def setUpClass(cls):
15 super(TestUtils, cls).setUpClass()
rohitwaghchaure058d9832021-09-07 12:14:40 +053016 make_test_objects("Address", ADDRESS_RECORDS)
tundebabzy40a02762017-10-25 07:54:34 +010017
18 def test_get_party_shipping_address(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053019 address = get_party_shipping_address("Customer", "_Test Customer 1")
20 self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
tundebabzy40a02762017-10-25 07:54:34 +010021
22 def test_get_party_shipping_address2(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053023 address = get_party_shipping_address("Customer", "_Test Customer 2")
24 self.assertEqual(address, "_Test Shipping Address 2 Title-Shipping")
25
26 def test_get_voucher_wise_gl_entry(self):
27
28 pr = make_purchase_receipt(
29 item_code="_Test Item",
30 posting_date="2021-02-01",
31 rate=100,
32 qty=1,
33 warehouse="Stores - TCP1",
34 company="_Test Company with perpetual inventory",
35 )
36
37 future_vouchers = get_future_stock_vouchers("2021-01-01", "00:00:00", for_items=["_Test Item"])
38
39 voucher_type_and_no = ("Purchase Receipt", pr.name)
40 self.assertTrue(
41 voucher_type_and_no in future_vouchers,
42 msg="get_future_stock_vouchers not returning correct value",
43 )
44
45 posting_date = "2021-01-01"
46 gl_entries = get_voucherwise_gl_entries(future_vouchers, posting_date)
47 self.assertTrue(
48 voucher_type_and_no in gl_entries, msg="get_voucherwise_gl_entries not returning expected GLes",
49 )
tundebabzy40a02762017-10-25 07:54:34 +010050
51
52ADDRESS_RECORDS = [
53 {
54 "doctype": "Address",
55 "address_type": "Billing",
56 "address_line1": "Address line 1",
57 "address_title": "_Test Billing Address Title",
58 "city": "Lagos",
59 "country": "Nigeria",
60 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053061 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
62 ],
tundebabzy40a02762017-10-25 07:54:34 +010063 },
64 {
65 "doctype": "Address",
66 "address_type": "Shipping",
67 "address_line1": "Address line 2",
68 "address_title": "_Test Shipping Address 1 Title",
69 "city": "Lagos",
70 "country": "Nigeria",
71 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053072 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
73 ],
tundebabzy40a02762017-10-25 07:54:34 +010074 },
75 {
76 "doctype": "Address",
77 "address_type": "Shipping",
78 "address_line1": "Address line 3",
79 "address_title": "_Test Shipping Address 2 Title",
80 "city": "Lagos",
81 "country": "Nigeria",
82 "is_shipping_address": "1",
83 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053084 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
85 ],
tundebabzy40a02762017-10-25 07:54:34 +010086 },
87 {
88 "doctype": "Address",
89 "address_type": "Billing",
90 "address_line1": "Address line 4",
91 "address_title": "_Test Billing Address 2 Title",
92 "city": "Lagos",
93 "country": "Nigeria",
94 "is_shipping_address": "1",
95 "links": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053096 {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
97 ],
98 },
tundebabzy40a02762017-10-25 07:54:34 +010099]