Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 1 | |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 2 | import unittest |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 3 | |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 4 | from frappe.test_runner import make_test_objects |
| 5 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 6 | from erpnext.accounts.party import get_party_shipping_address |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 7 | from erpnext.accounts.utils import get_future_stock_vouchers, get_voucherwise_gl_entries |
| 8 | from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 9 | |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 10 | |
| 11 | class TestUtils(unittest.TestCase): |
| 12 | @classmethod |
| 13 | def setUpClass(cls): |
| 14 | super(TestUtils, cls).setUpClass() |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 15 | make_test_objects("Address", ADDRESS_RECORDS) |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 16 | |
| 17 | def test_get_party_shipping_address(self): |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 18 | address = get_party_shipping_address("Customer", "_Test Customer 1") |
| 19 | self.assertEqual(address, "_Test Billing Address 2 Title-Billing") |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 20 | |
| 21 | def test_get_party_shipping_address2(self): |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 22 | 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 | ) |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 49 | |
| 50 | |
| 51 | ADDRESS_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": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 60 | {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} |
| 61 | ], |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 62 | }, |
| 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": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 71 | {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} |
| 72 | ], |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 73 | }, |
| 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": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 83 | {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} |
| 84 | ], |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 85 | }, |
| 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": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 95 | {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"} |
| 96 | ], |
| 97 | }, |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 98 | ] |