blob: 882cd694a326a232d39c0f9224d497a4e7f441d5 [file] [log] [blame]
tundebabzy40a02762017-10-25 07:54:34 +01001import unittest
Chillar Anand915b3432021-09-02 16:44:59 +05302
Ankush Menat700e8642022-04-19 13:24:29 +05303import frappe
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
Ankush Menat700e8642022-04-19 13:24:29 +05307from erpnext.accounts.utils import (
8 get_future_stock_vouchers,
9 get_voucherwise_gl_entries,
10 sort_stock_vouchers_by_posting_date,
11)
12from erpnext.stock.doctype.item.test_item import make_item
rohitwaghchaure058d9832021-09-07 12:14:40 +053013from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
Ankush Menat700e8642022-04-19 13:24:29 +053014from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
Chillar Anand915b3432021-09-02 16:44:59 +053015
tundebabzy40a02762017-10-25 07:54:34 +010016
17class TestUtils(unittest.TestCase):
18 @classmethod
19 def setUpClass(cls):
20 super(TestUtils, cls).setUpClass()
rohitwaghchaure058d9832021-09-07 12:14:40 +053021 make_test_objects("Address", ADDRESS_RECORDS)
tundebabzy40a02762017-10-25 07:54:34 +010022
23 def test_get_party_shipping_address(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053024 address = get_party_shipping_address("Customer", "_Test Customer 1")
25 self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
tundebabzy40a02762017-10-25 07:54:34 +010026
27 def test_get_party_shipping_address2(self):
rohitwaghchaure058d9832021-09-07 12:14:40 +053028 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 Menat494bd9e2022-03-28 18:52:46 +053053 voucher_type_and_no in gl_entries,
54 msg="get_voucherwise_gl_entries not returning expected GLes",
rohitwaghchaure058d9832021-09-07 12:14:40 +053055 )
tundebabzy40a02762017-10-25 07:54:34 +010056
Ankush Menat700e8642022-04-19 13:24:29 +053057 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)
Ankush Menat700e8642022-04-19 13:24:29 +053065 se3 = make_stock_entry(posting_date="2022-03-01", **stock_entry)
Ankush Menat2535d5e2022-06-14 18:20:33 +053066 se2 = make_stock_entry(posting_date="2022-02-01", **stock_entry)
Ankush Menat700e8642022-04-19 13:24:29 +053067
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
tundebabzy40a02762017-10-25 07:54:34 +010076
77ADDRESS_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": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053086 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
87 ],
tundebabzy40a02762017-10-25 07:54:34 +010088 },
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": [
rohitwaghchaure058d9832021-09-07 12:14:40 +053097 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
98 ],
tundebabzy40a02762017-10-25 07:54:34 +010099 },
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": [
rohitwaghchaure058d9832021-09-07 12:14:40 +0530109 {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
110 ],
tundebabzy40a02762017-10-25 07:54:34 +0100111 },
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": [
rohitwaghchaure058d9832021-09-07 12:14:40 +0530121 {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
122 ],
123 },
tundebabzy40a02762017-10-25 07:54:34 +0100124]