brotherton-erpnext/erpnext/controllers/tests/test_mapper.py
Rucha Mahabal eaa956b994
feat(Healthcare): Rehabilitation Module (#21216)
* feat: added rehab sub-module doctypes

* feat: rehab module

* feat: prescribe procedures in Patient Encounter

* feat: create Therapy Plan on Encounter submission

* feat: manage item for Therapy Type

* feat: book appointments, get prescribed therapies for Therapy Sessions

* feat: invoice Therapy Sessions

* feat: plan completion progress bar and exercise countsindicators

* feat: Motor Assessment Scale

* feat: add editable card view for exercise steps

* fix: add rehab in healthcare desk page

* fix: card deletion not working when child table is hidden

* feat: automatically fetch therapies according to Body Part

* fix: added tests for Therapy Type and Plan

* fix: add exercises according to body parts in Therapy Type

* fix: label for Exercise Instructions

* fix: exercise cards css

* feat: add dashboard for Therapy Plan

* feat: Patient Assessment Template and Patient Assessment

* feat: add title fields in Therapy Plan and Session

* fix: remove Motor Assessment Scale

* fix: fetch assessment description

* feat: create Patient Assessment from Therapy Session

* fix: anti pattern code

* fix: update desk page

* fix: exercise card rendering

* fix(test): filter out disabled Items in test_mapper

* fix: get stock uom from Stock Settings for Therapy Type Item creation

* fix: multiline SQL query

* fix: permissions for DocTypes

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
2020-04-22 13:07:12 +05:30

76 lines
2.5 KiB
Python

from __future__ import unicode_literals
import unittest
import frappe
import random, json
import frappe.utils
from frappe.utils import nowdate, add_months
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")
items = frappe.get_all("Item", fields = ["name", "item_code"], filters = {'is_sales_item': 1, 'has_variants': 0, 'disabled': 0})
customers = frappe.get_all("Customer")
if items and customers:
# Make source docs (quotations) and a target doc (sales order)
customer = random.choice(customers).name
qtn1, item_list_1 = self.make_quotation(items, customer)
qtn2, item_list_2 = self.make_quotation(items, customer)
so, item_list_3 = self.make_sales_order()
# 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
self.assertEqual(set([d.item_code for d in src_items]),
set([d.item_code for d in updated_so.items]))
def get_random_items(self, items, limit):
'''Get a number of random items from a list of given items'''
random_items = []
for i in range(0, limit):
random_items.append(random.choice(items))
return random_items
def make_quotation(self, items, customer):
item_list = self.get_random_items(items, 3)
qtn = frappe.get_doc({
"doctype": "Quotation",
"quotation_to": "Customer",
"party_name": customer,
"order_type": "Sales",
"transaction_date" : nowdate(),
"valid_till" : add_months(nowdate(), 1)
})
for item in item_list:
qtn.append("items", {"qty": "2", "item_code": item.item_code})
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",
"item_code": "_Test Item Home Desktop 100",
"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)
return so, [item]