2017-05-15 06:02:06 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
import unittest
|
|
|
|
import frappe
|
|
|
|
|
|
|
|
import random, json
|
|
|
|
import frappe.utils
|
2017-07-26 12:47:11 +00:00
|
|
|
from frappe.utils import nowdate, add_months
|
2017-05-15 06:02:06 +00:00
|
|
|
from frappe.model import mapper
|
|
|
|
from frappe.test_runner import make_test_records
|
|
|
|
|
|
|
|
class TestMapper(unittest.TestCase):
|
|
|
|
def test_map_docs(self):
|
|
|
|
'''Test mapping of multiple source docs on a single target doc'''
|
|
|
|
|
|
|
|
make_test_records("Item")
|
2020-07-11 14:08:51 +00:00
|
|
|
items = ['_Test Item', '_Test Item 2', '_Test FG Item']
|
|
|
|
|
|
|
|
# Make source docs (quotations) and a target doc (sales order)
|
|
|
|
qtn1, item_list_1 = self.make_quotation(items, '_Test Customer')
|
|
|
|
qtn2, item_list_2 = self.make_quotation(items, '_Test Customer')
|
|
|
|
so, item_list_3 = self.make_sales_order()
|
2017-05-15 06:02:06 +00:00
|
|
|
|
|
|
|
# Map source docs to target with corresponding mapper method
|
|
|
|
method = "erpnext.selling.doctype.quotation.quotation.make_sales_order"
|
|
|
|
updated_so = mapper.map_docs(method, json.dumps([qtn1.name, qtn2.name]), so)
|
|
|
|
|
|
|
|
# Assert that all inserted items are present in updated sales order
|
|
|
|
src_items = item_list_1 + item_list_2 + item_list_3
|
2021-06-11 10:30:48 +00:00
|
|
|
self.assertEqual(set(d for d in src_items),
|
|
|
|
set(d.item_code for d in updated_so.items))
|
2017-05-15 06:02:06 +00:00
|
|
|
|
|
|
|
|
2020-07-11 14:08:51 +00:00
|
|
|
def make_quotation(self, item_list, customer):
|
|
|
|
|
2017-05-15 06:02:06 +00:00
|
|
|
qtn = frappe.get_doc({
|
|
|
|
"doctype": "Quotation",
|
|
|
|
"quotation_to": "Customer",
|
2019-07-03 05:04:31 +00:00
|
|
|
"party_name": customer,
|
2017-07-26 12:47:11 +00:00
|
|
|
"order_type": "Sales",
|
|
|
|
"transaction_date" : nowdate(),
|
|
|
|
"valid_till" : add_months(nowdate(), 1)
|
2017-05-15 06:02:06 +00:00
|
|
|
})
|
|
|
|
for item in item_list:
|
2020-07-11 14:08:51 +00:00
|
|
|
qtn.append("items", {"qty": "2", "item_code": item})
|
2017-05-15 06:02:06 +00:00
|
|
|
|
|
|
|
qtn.submit()
|
|
|
|
return qtn, item_list
|
|
|
|
|
|
|
|
def make_sales_order(self):
|
|
|
|
item = frappe.get_doc({
|
|
|
|
"base_amount": 1000.0,
|
|
|
|
"base_rate": 100.0,
|
|
|
|
"description": "CPU",
|
|
|
|
"doctype": "Sales Order Item",
|
2020-07-11 14:08:51 +00:00
|
|
|
"item_code": "_Test Item",
|
2017-05-15 06:02:06 +00:00
|
|
|
"item_name": "CPU",
|
|
|
|
"parentfield": "items",
|
|
|
|
"qty": 10.0,
|
|
|
|
"rate": 100.0,
|
|
|
|
"warehouse": "_Test Warehouse - _TC",
|
|
|
|
"stock_uom": "_Test UOM",
|
|
|
|
"conversion_factor": 1.0,
|
|
|
|
"uom": "_Test UOM"
|
|
|
|
})
|
|
|
|
so = frappe.get_doc(frappe.get_test_records('Sales Order')[0])
|
|
|
|
so.insert(ignore_permissions=True)
|
2020-07-11 14:08:51 +00:00
|
|
|
return so, [item.item_code]
|