@@ -69,7 +69,37 @@ | |||||
"read_only": 0, | "read_only": 0, | ||||
"remember_last_selected_value": 0, | "remember_last_selected_value": 0, | ||||
"report_hide": 0, | "report_hide": 0, | ||||
"reqd": 1, | |||||
"reqd": 0, | |||||
"search_index": 0, | |||||
"set_only_once": 0, | |||||
"unique": 0 | |||||
}, | |||||
{ | |||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | |||||
"bold": 0, | |||||
"collapsible": 0, | |||||
"columns": 0, | |||||
"fieldname": "python_module", | |||||
"fieldtype": "Data", | |||||
"hidden": 0, | |||||
"ignore_user_permissions": 0, | |||||
"ignore_xss_filter": 0, | |||||
"in_filter": 0, | |||||
"in_global_search": 0, | |||||
"in_list_view": 0, | |||||
"in_standard_filter": 0, | |||||
"label": "Python Module", | |||||
"length": 0, | |||||
"no_copy": 0, | |||||
"permlevel": 0, | |||||
"precision": "", | |||||
"print_hide": 0, | |||||
"print_hide_if_no_value": 0, | |||||
"read_only": 0, | |||||
"remember_last_selected_value": 0, | |||||
"report_hide": 0, | |||||
"reqd": 0, | |||||
"search_index": 0, | "search_index": 0, | ||||
"set_only_once": 0, | "set_only_once": 0, | ||||
"unique": 0 | "unique": 0 | ||||
@@ -172,7 +202,7 @@ | |||||
"collapsible": 0, | "collapsible": 0, | ||||
"columns": 0, | "columns": 0, | ||||
"fieldname": "password", | "fieldname": "password", | ||||
"fieldtype": "Data", | |||||
"fieldtype": "Password", | |||||
"hidden": 0, | "hidden": 0, | ||||
"ignore_user_permissions": 0, | "ignore_user_permissions": 0, | ||||
"ignore_xss_filter": 0, | "ignore_xss_filter": 0, | ||||
@@ -206,8 +236,8 @@ | |||||
"issingle": 0, | "issingle": 0, | ||||
"istable": 0, | "istable": 0, | ||||
"max_attachments": 0, | "max_attachments": 0, | ||||
"modified": "2017-09-07 12:40:15.008483", | |||||
"modified_by": "faris@erpnext.com", | |||||
"modified": "2017-10-08 14:34:30.603690", | |||||
"modified_by": "Administrator", | |||||
"module": "Data Migration", | "module": "Data Migration", | ||||
"name": "Data Migration Connector", | "name": "Data Migration Connector", | ||||
"name_case": "", | "name_case": "", | ||||
@@ -234,7 +264,7 @@ | |||||
"write": 1 | "write": 1 | ||||
} | } | ||||
], | ], | ||||
"quick_entry": 1, | |||||
"quick_entry": 0, | |||||
"read_only": 0, | "read_only": 0, | ||||
"read_only_onload": 0, | "read_only_onload": 0, | ||||
"show_name_in_global_search": 0, | "show_name_in_global_search": 0, | ||||
@@ -3,16 +3,32 @@ | |||||
# For license information, please see license.txt | # For license information, please see license.txt | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | |||||
from frappe.model.document import Document | from frappe.model.document import Document | ||||
from frappe import _ | |||||
from .connectors.postgres import PostGresConnection | from .connectors.postgres import PostGresConnection | ||||
from .connectors.frappe_connection import FrappeConnection | from .connectors.frappe_connection import FrappeConnection | ||||
class DataMigrationConnector(Document): | class DataMigrationConnector(Document): | ||||
def validate(self): | |||||
if not (self.python_module or self.connector_type): | |||||
frappe.throw(_('Enter python module or select connector type')) | |||||
if self.python_module: | |||||
try: | |||||
frappe.get_module(self.python_module) | |||||
except: | |||||
frappe.throw(frappe._('Invalid module path')) | |||||
def get_connection(self): | def get_connection(self): | ||||
if self.connector_type == 'Frappe': | |||||
self.connection = FrappeConnection(self) | |||||
elif self.connector_type == 'PostGres': | |||||
self.connection = PostGresConnection(self.as_dict()) | |||||
if self.python_module: | |||||
module = frappe.get_module(self.python_module) | |||||
return module.get_connection(self) | |||||
else: | |||||
if self.connector_type == 'Frappe': | |||||
self.connection = FrappeConnection(self) | |||||
elif self.connector_type == 'PostGres': | |||||
self.connection = PostGresConnection(self.as_dict()) | |||||
return self.connection | return self.connection | ||||
@@ -10,10 +10,11 @@ from frappe.custom.doctype.custom_field.custom_field import create_custom_field | |||||
from frappe.model.document import Document | from frappe.model.document import Document | ||||
class DataMigrationPlan(Document): | class DataMigrationPlan(Document): | ||||
def after_insert(self): | |||||
self.make_custom_fields_for_mappings() | |||||
def on_update(self): | def on_update(self): | ||||
# update custom fields in mappings | |||||
self.make_custom_fields_for_mappings() | |||||
if frappe.flags.in_import or frappe.flags.in_test: | if frappe.flags.in_import or frappe.flags.in_test: | ||||
return | return | ||||
@@ -380,8 +380,16 @@ class DataMigrationRun(Document): | |||||
pull_update = self.get_log('pull_update', 0) | pull_update = self.get_log('pull_update', 0) | ||||
pull_failed = self.get_log('pull_failed', []) | pull_failed = self.get_log('pull_failed', []) | ||||
def get_migration_id_value(source, key): | |||||
value = None | |||||
try: | |||||
value = source[key] | |||||
except: | |||||
value = getattr(source, key) | |||||
return value | |||||
for d in data: | for d in data: | ||||
migration_id_value = d[connection.name_field] | |||||
migration_id_value = get_migration_id_value(d, connection.name_field) | |||||
doc = self.pre_process_doc(d) | doc = self.pre_process_doc(d) | ||||
doc = mapping.get_mapped_record(doc) | doc = mapping.get_mapped_record(doc) | ||||