Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### EXECUTE THIS SCRIPT AFTER YOU HAVE MIGRATED INVOICE DATA
- ### account.invoice, account.invoice.line, account.move.line
- ### account.full.reconcile(Only name field is enough)
- from collections import OrderedDict
- import xmlrpc.client
- import ssl
- import sys
- src_url = "https://industruino.com"
- dst_url = "http://industruino.v120.mylocal.com"
- src_db = "Industruino"
- dst_db = "industruino.v120.mylocal.com"
- src_username = 'connect@industruino.com'
- src_password = 'M1D8JHMLR4MVSC8V'
- dst_username = 'connect@industruino.com'
- dst_password = 'a'
- uid = 1
- context_src = {}
- context_dst = {}
- skipped_groups = []
- exit = False
- try:
- common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(src_url))
- user_id = common.authenticate(src_db, src_username, src_password, {})
- if not user_id:
- exit = True
- print("Unable to connect Source DB")
- else:
- print("Connection successful to Source DB")
- except:
- exit = True
- print("Unable to connect Source DB")
- try:
- common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(dst_url))
- user_id = common.authenticate(dst_db, dst_username, dst_password, {})
- if not user_id:
- exit = True
- print("Unable to connect Destination DB")
- else:
- print("Connection successful to Destination DB")
- except:
- exit = True
- print("Unable to connect Destination DB")
- if exit:
- sys.exit()
- src_conn = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(src_url), context=ssl._create_unverified_context())
- dst_conn = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(dst_url), context=ssl._create_unverified_context())
- def create_records(cursor, model, values, type='src'):
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- id = cursor.execute_kw(database, uid, password, model, 'create', [values])
- print ("created record %s : %s" %(model,id))
- return id
- def write_records(cursor, model, record_id, values, type='src'):
- print ("Updating records %s : %s" %(model, record_id))
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- id = cursor.execute_kw(database, uid, password, model, 'write', [[record_id],values])
- print ("Updated record %s : %s" %(model,id))
- return id
- def search_read_list_to_dict(result_list):
- result_dict = {}
- for dict in result_list:
- for key, value in dict.items():
- result_dict.update({dict['id']: dict['login']})
- return result_dict
- def format_groups(result_list):
- result_dict = {}
- for dict in result_list:
- for key, value in dict.items():
- if key == 'id':
- result_dict.update({dict['full_name']: (dict['id'], dict['category_id'], dict['users'])})
- return result_dict
- def search_records(cursor, model, domain=[[]], fields=[], type='src'):
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- print("Searching model %s with domain %s" % (model, domain))
- records = cursor.execute_kw(database, uid, password,
- model, 'search', domain)
- print("records found for model %s : %s" % (model, len(records)))
- return records
- def read_records_with_id(cursor, model, record_ids=[], type='src'):
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- records = cursor.execute_kw(database, uid, password,
- model, 'read', [record_ids])
- return records
- def read_records(cursor, model, domain=[[]], fields=[], type='src'):
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- record_ids = search_records(cursor, model, domain, fields)
- records = cursor.execute_kw(database, uid, password,
- model, 'read', [record_ids])
- print ("Found record.................", records)
- return records
- def update_record(cursor, model, id, vals={}, type='src'):
- print("updating record %s with vals %s" % (id, vals))
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- cursor.execute_kw(database, uid, password, model, 'write', [[id], vals])
- return True
- def search_read_records(cursor, model, domain=[[]], fields=[], type='src'):
- if type == 'src':
- password = src_password
- database = src_db
- else:
- password = dst_password
- database = dst_db
- records = cursor.execute_kw(database, uid, password,
- model, 'search_read', domain, {'fields': fields})
- return records
- src_conn = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(src_url), context=ssl._create_unverified_context())
- dst_conn = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(dst_url), context=ssl._create_unverified_context())
- #['id','in',(1235,1286)]
- objects = OrderedDict({
- 'account.voucher': {'fields': [], 'domain': [], 'context_store': True},
- })
- for object, values in objects.items():
- domain = values.get('domain', [])
- fields = values.get('fields', [])
- # Source Records
- src_records = search_read_records(src_conn, object, [domain], fields, type='src')
- for record in src_records:
- print ("Rec9ord.....................")
- vals = {'payment_type' : 'inbound',
- 'partner_type' : 'customer',
- 'partner_id' : record['partner_id'][0],
- 'amount' : abs(record['amount']),
- 'journal_id' : record['journal_id'][0],
- 'payment_date': record['date'],
- 'communication' : record['name'],
- 'payment_method_id' : 1,
- }
- ## Create Payment
- payment_id = create_records(dst_conn, 'account.payment', vals, type='dst')
- ## Set move lines
- for move_id in record['move_ids']:
- write_records(dst_conn, 'account.move.line', move_id, {'payment_id' : payment_id}, type='dst')
- ## Create Payments
- ## Read Invoices
- # Setting Payment information
- src_invoices = search_read_records(src_conn, 'account.invoice', [], ['id','payment_ids'], type='src')
- for invoice in src_invoices:
- for move_id in invoice['payment_ids']:
- dst_records = read_records_with_id(dst_conn, 'account.move.line', move_id, type='dst')
- for record in dst_records:
- if record['payment_id']:
- print ("linking payments...........%s to invoice %s", ( (4,record['payment_id'][0]),invoice['id'] ))
- write_records(dst_conn, 'account.invoice', invoice['id'], {'payment_ids': [(4,record['payment_id'][0])]}, type='dst')
- ## Read Reconciliation
- src_reconcile = search_read_records(src_conn, 'account.move.reconcile', [], ['id','line_id'], type='src')
- for reconcile in src_reconcile:
- for line_id in reconcile['line_id']:
- print(reconcile['line_id'])
- print ("lines..................", line_id, reconcile['id'])
- write_records(dst_conn, 'account.move.line', line_id, {'full_reconcile_id': reconcile['id']}, type='dst')
- ### SERVER ACTION TO LINK PAYMENTS IN INVOICES
- # for item in env['account.full.reconcile'].search([]):
- # for line in item.reconciled_line_ids:
- # if line.credit > 0:
- # debit_move_id = item.reconciled_line_ids.filtered(lambda p: p.debit> 0)
- # if len(debit_move_id):
- # env['account.partial.reconcile'].create({
- # 'debit_move_id':debit_move_id.id,
- # 'credit_move_id': line.id,
- # 'amount': line.credit,
- # 'full_reconcile_id':item.id,
- # 'company_currency_id':1,
- # })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement