tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 1 | import unittest |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 2 | |
Ankush Menat | 700e864 | 2022-04-19 13:24:29 +0530 | [diff] [blame] | 3 | import frappe |
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 |
Ankush Menat | 700e864 | 2022-04-19 13:24:29 +0530 | [diff] [blame] | 7 | from erpnext.accounts.utils import ( |
| 8 | get_future_stock_vouchers, |
| 9 | get_voucherwise_gl_entries, |
| 10 | sort_stock_vouchers_by_posting_date, |
| 11 | ) |
| 12 | from erpnext.stock.doctype.item.test_item import make_item |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 13 | from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt |
Ankush Menat | 700e864 | 2022-04-19 13:24:29 +0530 | [diff] [blame] | 14 | from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 15 | |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 16 | |
| 17 | class TestUtils(unittest.TestCase): |
| 18 | @classmethod |
| 19 | def setUpClass(cls): |
| 20 | super(TestUtils, cls).setUpClass() |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 21 | make_test_objects("Address", ADDRESS_RECORDS) |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 22 | |
| 23 | def test_get_party_shipping_address(self): |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 24 | address = get_party_shipping_address("Customer", "_Test Customer 1") |
| 25 | self.assertEqual(address, "_Test Billing Address 2 Title-Billing") |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 26 | |
| 27 | def test_get_party_shipping_address2(self): |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 28 | address = get_party_shipping_address("Customer", "_Test Customer 2") |
| 29 | self.assertEqual(address, "_Test Shipping Address 2 Title-Shipping") |
| 30 | |
| 31 | def test_get_voucher_wise_gl_entry(self): |
| 32 | |
| 33 | pr = make_purchase_receipt( |
| 34 | item_code="_Test Item", |
| 35 | posting_date="2021-02-01", |
| 36 | rate=100, |
| 37 | qty=1, |
| 38 | warehouse="Stores - TCP1", |
| 39 | company="_Test Company with perpetual inventory", |
| 40 | ) |
| 41 | |
| 42 | future_vouchers = get_future_stock_vouchers("2021-01-01", "00:00:00", for_items=["_Test Item"]) |
| 43 | |
| 44 | voucher_type_and_no = ("Purchase Receipt", pr.name) |
| 45 | self.assertTrue( |
| 46 | voucher_type_and_no in future_vouchers, |
| 47 | msg="get_future_stock_vouchers not returning correct value", |
| 48 | ) |
| 49 | |
| 50 | posting_date = "2021-01-01" |
| 51 | gl_entries = get_voucherwise_gl_entries(future_vouchers, posting_date) |
| 52 | self.assertTrue( |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 53 | voucher_type_and_no in gl_entries, |
| 54 | msg="get_voucherwise_gl_entries not returning expected GLes", |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 55 | ) |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 56 | |
Ankush Menat | 700e864 | 2022-04-19 13:24:29 +0530 | [diff] [blame] | 57 | def test_stock_voucher_sorting(self): |
| 58 | vouchers = [] |
| 59 | |
| 60 | item = make_item().name |
| 61 | |
| 62 | stock_entry = {"item": item, "to_warehouse": "_Test Warehouse - _TC", "qty": 1, "rate": 10} |
| 63 | |
| 64 | se1 = make_stock_entry(posting_date="2022-01-01", **stock_entry) |
| 65 | se2 = make_stock_entry(posting_date="2022-02-01", **stock_entry) |
| 66 | se3 = make_stock_entry(posting_date="2022-03-01", **stock_entry) |
| 67 | |
| 68 | for doc in (se1, se2, se3): |
| 69 | vouchers.append((doc.doctype, doc.name)) |
| 70 | |
| 71 | vouchers.append(("Stock Entry", "Wat")) |
| 72 | |
| 73 | sorted_vouchers = sort_stock_vouchers_by_posting_date(list(reversed(vouchers))) |
| 74 | self.assertEqual(sorted_vouchers, vouchers) |
| 75 | |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 76 | |
| 77 | ADDRESS_RECORDS = [ |
| 78 | { |
| 79 | "doctype": "Address", |
| 80 | "address_type": "Billing", |
| 81 | "address_line1": "Address line 1", |
| 82 | "address_title": "_Test Billing Address Title", |
| 83 | "city": "Lagos", |
| 84 | "country": "Nigeria", |
| 85 | "links": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 86 | {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} |
| 87 | ], |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 88 | }, |
| 89 | { |
| 90 | "doctype": "Address", |
| 91 | "address_type": "Shipping", |
| 92 | "address_line1": "Address line 2", |
| 93 | "address_title": "_Test Shipping Address 1 Title", |
| 94 | "city": "Lagos", |
| 95 | "country": "Nigeria", |
| 96 | "links": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 97 | {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} |
| 98 | ], |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 99 | }, |
| 100 | { |
| 101 | "doctype": "Address", |
| 102 | "address_type": "Shipping", |
| 103 | "address_line1": "Address line 3", |
| 104 | "address_title": "_Test Shipping Address 2 Title", |
| 105 | "city": "Lagos", |
| 106 | "country": "Nigeria", |
| 107 | "is_shipping_address": "1", |
| 108 | "links": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 109 | {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} |
| 110 | ], |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 111 | }, |
| 112 | { |
| 113 | "doctype": "Address", |
| 114 | "address_type": "Billing", |
| 115 | "address_line1": "Address line 4", |
| 116 | "address_title": "_Test Billing Address 2 Title", |
| 117 | "city": "Lagos", |
| 118 | "country": "Nigeria", |
| 119 | "is_shipping_address": "1", |
| 120 | "links": [ |
rohitwaghchaure | 058d983 | 2021-09-07 12:14:40 +0530 | [diff] [blame] | 121 | {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"} |
| 122 | ], |
| 123 | }, |
tundebabzy | 40a0276 | 2017-10-25 07:54:34 +0100 | [diff] [blame] | 124 | ] |