def generate_demo_plans(self): demo_plan_module_obj = self.env['saas_portal.demo_plan_module'] demo_plan_hidden_module_obj = self.env['saas_portal.hidden_demo_plan_module'] for record in self: db, uid, password, models = record._get_xmlrpc_object(record.name) ids = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['demo_url', '!=', False]]], ) modules = models.execute_kw(db, uid, password, 'ir.module.module', 'read', [ids]) for module in modules: plan = record._create_demo_plan(module) if not plan: continue vals = record._prepare_module(module, plan) demo_plan_module_obj.create(vals) record._create_demo_product(module, plan) if module.get('demo_addons'): ids = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['name', 'in', module['demo_addons'].split(',')]]], {'limit': 10}) addon_modules = models.execute_kw(db, uid, password, 'ir.module.module', 'read', [ids]) for addon in addon_modules: vals = record._prepare_module(addon, plan) demo_plan_module_obj.create(vals) if module.get('demo_addons_hidden'): for addon in module['demo_addons_hidden'].split(','): demo_plan_hidden_module_obj.create({'technical_name': addon, 'demo_plan_id': plan.id}) return True
def notify_feedback_state_change(self, database, url, question_num, new_state, update_data={}): if new_state not in ['submitted','handled','solved']: return False # print url try: # if url.contains(':') : # url = url.split(":")[0] common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) uid = common.authenticate(database, FEEDBACK_SERVER_USER_LOGIN, FEEDBACK_SERVER_USER_PASSWORD, {'raise_exception': True}) if not uid: return False ids = models.execute_kw(database, uid, FEEDBACK_SERVER_USER_PASSWORD,'ct_feedback_client.question', 'search', [[['info_num', '=', question_num]]], {'limit': 1}) # print 'SEARCH results for ', question_num, ids if ids: vals = { 'state': new_state, } vals.update(update_data) # if new_state == 'solved': # vals[''] update_statue = models.execute_kw(database, uid, FEEDBACK_SERVER_USER_PASSWORD, 'ct_feedback_client.question', 'write', [[ids[0]], vals]) # print update_statue return update_statue except Exception as e: print 'EXCEPTION ', e return False
def generate_demo_plans(self): demo_plan_module_obj = self.env['saas_portal.demo_plan_module'] demo_plan_hidden_module_obj = self.env['saas_portal.hidden_demo_plan_module'] for record in self: db, uid, password, models = record._get_xmlrpc_object(record.name) ids = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['demo_url', '!=', False]]], ) modules = models.execute_kw(db, uid, password, 'ir.module.module', 'read', [ids]) for module in modules: plan = record._create_demo_plan(module) if not plan: continue vals = record._prepare_module(module, plan) demo_plan_module_obj.create(vals) record._create_demo_product(module, plan) if module.get('demo_addons'): ids = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['name', 'in', module['demo_addons'].split(',')]]], {'limit': 10}) addon_modules = models.execute_kw(db, uid, password, 'ir.module.module', 'read', [ids]) for addon in addon_modules: vals = record._prepare_module(addon, plan) demo_plan_module_obj.create(vals) if module.get('demo_addons_hidden'): for addon in module['demo_addons_hidden'].split(','): demo_plan_hidden_module_obj.create({'technical_name': addon, 'demo_plan_id': plan.id}) return True
def action_forpo(self): fos_parts_po_id = self.fos_parts_po_id db = self.db url = self.url username = self.username password = self.password # attempt to connect logger.info("Connecting to " + url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) if models: logger.info("Models: " + str(models)) mod_out = models.execute_kw(db, uid, password, 'fos.parts.po', 'write', [[ fos_parts_po_id, ], { 'state': 'forpo' }]) if mod_out: # search dealer's parts existence for line in self.order_line: name_template = line.assigned_product_id.product_tmpl_id.name dealer_pt = models.execute_kw( db, uid, password, 'product.product', 'search_read', [[['name', '=', name_template]]]) if not dealer_pt: raise exceptions.except_orm( _('Remote Search Failed'), _(name_template + " does not exists on Dealer's Parts Master")) else: logger.info("Product ID:" + str(line.assigned_product_id.id)) is_updated = models.execute_kw( db, uid, password, 'fos.parts.po.line', 'write', [[ line.fos_parts_po_line_id, ], { 'assigned_product_id': dealer_pt[0]['id'], 'assigned_product_name': line.assigned_product_name, 'assigned_description': line.assigned_description, 'assigned_order_qty': line.assigned_order_qty, 'assigned_price_unit': line.assigned_price_unit, 'assigned_vat_amount': line.assigned_vat_amount, 'assigned_subtotal_with_vat': line.assigned_subtotal_with_vat, 'eta': line.eta }]) self.write({'state': 'forpo'})
def _out_ajuste_inicial(self, db, uid, password, models): self._cr.execute("""\ SELECT location_id, product_id, SUM(qty) as product_qty FROM stock_quant WHERE location_id IN (SELECT DISTINCT id FROM stock_location WHERE usage='internal') GROUP BY location_id, product_id """) ubicaciones = {} for location_id, product_id, product_qty in self._cr.fetchall(): ubicacion_bd_origen = self.env['stock.location'].browse( location_id) producto_bd_origen = self.env['product.product'].browse(product_id) ubicacion_bd_destino_id = self.buscar_destino( db, uid, password, models, 'stock.location', ['sinc_id', '=', ubicacion_bd_origen.id]) producto_bd_destino_id = self.buscar_destino( db, uid, password, models, 'product.product', ['sinc_id', '=', producto_bd_origen.id]) if ubicacion_bd_destino_id and producto_bd_destino_id: ubicacion_bd_destino_id = ubicacion_bd_destino_id[0] producto_bd_destino_id = producto_bd_destino_id[0] if location_id not in ubicaciones: dict = {} dict[ 'name'] = 'Ajuste inicial - ' + ubicacion_bd_origen.name dict['location_id'] = ubicacion_bd_destino_id line_ids = [] line_ids.append((0, 0, { 'location_id': ubicacion_bd_destino_id, 'product_id': producto_bd_destino_id, 'product_qty': product_qty, })) dict['line_ids'] = line_ids obj_id = models.execute_kw(db, uid, password, 'stock.inventory', 'create', [dict]) ubicaciones[location_id] = obj_id else: obj_id = ubicaciones[location_id] line_ids = [] line_ids.append((0, 0, { 'location_id': ubicacion_bd_destino_id, 'product_id': producto_bd_destino_id, 'product_qty': product_qty, })) dict['line_ids'] = line_ids models.execute_kw(db, uid, password, 'stock.inventory', 'write', [[obj_id], dict])
def _get_odoo_version(self): self.ensure_one() db, uid, password, models = self._get_xmlrpc_object(self.name) ids = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['name', '=', 'base']]], ) base_module = models.execute_kw(db, uid, password, 'ir.module.module', 'read', [ids], {'fields': ['latest_version']}) return base_module[0].get('latest_version')
def update_templates(self): for record in self: plans = self.env['saas_portal.plan'].search([('server_id', '=', record.id), ('demo_plan_module_ids', '!=', False), ('template_id.state', '=', 'template')]) for plan in plans: db, uid, password, models = plan.template_id._get_xmlrpc_object() id = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['name', 'in', ['base']]]]) models.execute_kw(db, uid, password, 'ir.module.module', 'button_immediate_upgrade', [id]) return True
def _get_odoo_version(self): self.ensure_one() db, uid, password, models = self._get_xmlrpc_object(self.name) ids = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['name', '=', 'base']]], ) base_module = models.execute_kw(db, uid, password, 'ir.module.module', 'read', [ids], {'fields': ['latest_version']}) return base_module[0].get('latest_version')
def update_templates(self): for record in self: plans = self.env['saas_portal.plan'].search([('server_id', '=', record.id), ('demo_plan_module_ids', '!=', False), ('template_id.state', '=', 'template')]) for plan in plans: db, uid, password, models = plan.template_id._get_xmlrpc_object() id = models.execute_kw(db, uid, password, 'ir.module.module', 'search', [[['name', 'in', ['base']]]]) models.execute_kw(db, uid, password, 'ir.module.module', 'button_upgrade', [id]) return True
def update_repositories(self): for record in self: db, uid, password, models = record._get_xmlrpc_object(record.name) ids = models.execute_kw( db, uid, password, 'saas_server.repository', 'search', [[]], ) models.execute_kw(db, uid, password, 'saas_server.repository', 'update', [ids]) return True
def create(self, values): res = super(ResUsers, self).create(values) if res.partner_id: res.partner_id.with_context(from_user=True).write({ 'email': res.login, 'user_role': res.user_role }) if res.state == 'new': res.partner_id.with_context(from_user=True).write({ 'res_user_state': 'Pending' }) elif res.state == 'active': res.partner_id.with_context(from_user=True).write({ 'res_user_state': 'Active' }) parent_company = res.partner_id.parent_id if parent_company.subscription_company: url = parent_company.instance_url db = parent_company.databse_id.name self.env.cr.execute( 'select password, internal_password from res_users where id=%s', (res.id,)) result = self.env.cr.fetchone() username = res.login password = res.password params = { 'name': res.name, 'active': res.active, 'login': res.login, 'email': res.login, 'tz': res.tz, 'cust_email_creation': True, } try: common = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/common'.format(url), verbose=False, context=ssl._create_unverified_context()) uid = common.authenticate(db, username, password, {}) models = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/object'.format(url), verbose=False, context=ssl._create_unverified_context()) new_instance_user = models.execute_kw(db, uid, password, 'res.users', 'create', [uid, params]) models.execute_kw(db, uid, password, 'res.users', 'api_set_password', [result, new_instance_user]) except Exception: pass return res
def action_ack_api(self): # 1. make connection to Dealer dealer_vqir_id = self.dealer_vqir_id db = self.db url = self.url username = self.username password = self.password # attempt to connect logger.info("URL: " + url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) vqir_state_logs = "Document:" + self.name + "\n" + \ "Acknowledged by: " + self.env.user.name + "\n" + \ "Acknowledged at: " + datetime.datetime.now().strftime("%m/%d/%Y") + "\n" + \ "Acknowledgement notes: " + (self.name or '') + "\n" + \ "--------------------------------------------------\n" self.write({ 'vqir_state': 'ack', 'vqir_state_logs': str(self.vqir_state_logs or '') }) cur_stamp = fields.datetime.now() if models: logger.info("Models: " + str(models)) mod_out = models.execute_kw( db, uid, password, 'fos.vqir', 'write', [[ self.dealer_vqir_id, ], { 'vqir_state': 'ack', 'vqir_state_logs': str(self.vqir_state_logs or ''), "ack_date": cur_stamp }]) for line in self.fmpi_vqir_parts_and_jobs_line: pj_approved_amount = models.execute_kw( db, uid, password, 'fos.vqir.parts.and.jobs', 'write', [[ line.dealer_pj_id, ], { 'approved_amount': line.approved_amount, 'job_approved_amount': line.job_approved_amount }]) self.write({'vqir_state': 'ack', "ack_date": cur_stamp})
def invoice_gen(self): url = 'http://localhost:9999' db = 'test_1' username = '******' password = '******' common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) line_id = models.execute_kw( db, uid, password, 'account.move', 'create', [{ "name": "session instructor invoice", "date": '2020-10-30', "ref": "session", "state": "draft", "type": "out_invoice", "type_name": "Invoice", "invoice_payment_state": "paid", "invoice_date": '2020-10-30', "invoice_date_due": "2020-11-30", "amount_total_signed": 100, "partner_id": self.instructor_id.id, "commercial_partner_id": self.instructor_id.id, }]) self.write({'is_paid': True})
def fill_asset_details(self): server_connection_id = self.env['server.connection'].search([('active', '=', True)]) url = server_connection_id.url db = server_connection_id.db_name common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) print('==========models================', models) uid = self.env.user.id password = self.env.user.password id = models.execute_kw(db, 2, "admin", 'account.asset.asset', 'create', [{"name": self.item_id.name,"serial_number": self.serial_number,"category_id":1,"value":1}]) print('==========asset_data================', id) self.coe_asset_id = id asset_id = id key = ",jy`\;4Xpe7%KKL$.VNJ'.s6)wErQa" connection_rec = self.env['server.connection'].search([], limit=1) if not connection_rec: raise UserError(_('No Server Configuration Found !')) encoded_jwt = jwt.encode({'token': self.env.user.token}, key) action = { 'name': connection_rec.name, 'type': 'ir.actions.act_url', 'url': str(connection_rec.url).strip() + "/asset/indent?login="******"&password="******"utf-8")) + "&menu_id=" + str(asset_id), 'target': 'new', } return action
def action_sync_service_history(self): # set connection parameters to FMPI url = self.api_host.strip() db = self.fmpi_pgn username = self.api_user password = self.api_pass # attempt to connect logger.info("Connecting to " + url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) if not models: raise exceptions.except_orm( _('Models: Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return d_ids = self.env['fmpi.service.history'].search([(1, "=", 1)]).ids if d_ids: s_ids = "'" + str(d_ids).replace("[", "(").replace("]", ")") + "'" logger.info("s_ids = " + s_ids) rec = models.execute_kw(db, uid, password, 'fmpi.service.history', 'search', [['id', 'not in', s_ids]]) if rec: for r in rec: logger.info("FMPI Record ID:" + str(r.id))
def action_proc(self): fos_parts_po_id = self.fos_parts_po_id db = self.db url = self.url username = self.username password = self.password # attempt to connect logger.info("Connecting to "+url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm(_('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) if models: logger.info("Models: " + str(models)) mod_out = models.execute_kw(db, uid, password, 'fos.parts.po', 'write', [[self.fos_parts_po_id,], {'state': 'proc'}]) #if mod_out: # logger.info("Mod_Out:" + str(mod_out)) # for line in self.order_line: # logger.info("Product ID:" + str(line.assigned_product_id.id)) # is_updated = models.execute_kw(db, uid, password, 'fos.parts.po.line', 'write', # [[line.fos_parts_po_line_id,], # { # 'assigned_product_id': line.assigned_product_id.id, # 'assigned_product_name': line.assigned_product_name, # 'assigned_description': line.assigned_description, # 'assigned_order_qty': line.assigned_order_qty, # 'assigned_price_unit': line.assigned_price_unit # }]) self.write({'state': 'proc'})
def _create_demo_images(self, demo_module): self.ensure_one() db, uid, password, models = self._get_xmlrpc_object(self.name) images = models.execute_kw(db, uid, password, 'ir.module.module', 'get_demo_images', [demo_module['id']]) return images
def _create_demo_images(self, demo_module): self.ensure_one() db, uid, password, models = self._get_xmlrpc_object(self.name) images = models.execute_kw(db, uid, password, 'ir.module.module', 'get_demo_images', [demo_module['id']]) return images
def create_demo_templates(self): plan_obj = self.env['saas_portal.plan'] for record in self: demo_plan_ids = plan_obj.search([('server_id', '=', record.id), ('template_id.state', '=', 'draft')]) for plan in demo_plan_ids: plan.with_context({'skip_sync_server': True}).create_template() addons = plan.demo_plan_module_ids.mapped('technical_name') addons.extend(plan.demo_plan_hidden_module_ids.mapped('technical_name')) payload = {'install_addons': addons} plan.template_id.upgrade(payload=payload) record.action_sync_server() # after installing demo modules: make `owner_template` user a member of all the admin's security groups db, uid, password, models = plan.template_id._get_xmlrpc_object() admin_groups = models.execute_kw(db, uid, password, 'res.users', 'search_read', [[['id', '=', SI]]], {'fields': ['groups_id']}) owner_user_id = models.execute_kw(db, uid, password, 'res.users', 'search', [[['login', '=', 'owner_template']]]) models.execute_kw(db, uid, password, 'res.users', 'write', [owner_user_id, {'groups_id': [(6, 0, admin_groups[0]['groups_id'])]}]) # configure outgoing mail service for using `postfix` docker container mail_server_id = models.execute_kw(db, uid, password, 'ir.mail_server', 'search', [[]], {'limit': 1}) models.execute_kw(db, uid, password, 'ir.mail_server', 'write', [mail_server_id, {'name': 'postfix', 'smtp_host': 'postfix'}]) return True
def create_demo_templates(self): plan_obj = self.env['saas_portal.plan'] for record in self: demo_plan_ids = plan_obj.search([('server_id', '=', record.id), ('template_id.state', '=', 'draft')]) for plan in demo_plan_ids: plan.with_context({'skip_sync_server': True}).create_template() addons = plan.demo_plan_module_ids.mapped('technical_name') addons.extend(plan.demo_plan_hidden_module_ids.mapped('technical_name')) payload = {'install_addons': addons} plan.template_id.upgrade(payload=payload) record.action_sync_server() # after installing demo modules: make `owner_template` user a member of all the admin's security groups db, uid, password, models = plan.template_id._get_xmlrpc_object() admin_groups = models.execute_kw(db, uid, password, 'res.users', 'search_read', [[['id', '=', SI]]], {'fields': ['groups_id']}) owner_user_id = models.execute_kw(db, uid, password, 'res.users', 'search', [[['login', '=', 'owner_template']]]) models.execute_kw(db, uid, password, 'res.users', 'write', [owner_user_id, {'groups_id': [(6, 0, admin_groups[0]['groups_id'])]}]) # configure outgoing mail service for using `postfix` docker container mail_server_id = models.execute_kw(db, uid, password, 'ir.mail_server', 'search', [[]], {'limit': 1}) models.execute_kw(db, uid, password, 'ir.mail_server', 'write', [mail_server_id, {'name': 'postfix', 'smtp_host': 'postfix'}]) return True
def getUserFromDb(fullname, models, common, db, uid, password): # Search for user with firstname and lastname users = models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[['name', 'ilike', fullname]]], { 'fields': ['name'], 'limit': 5 }) return users
def updateUserLike(users_list, like, post, models, common, db, uid, password): # Check if like already exists print('updateUserLike') for user in users_list: count = models.execute_kw( db, uid, password, 'customer.facebook.like', 'search_count', [[['post_url', 'ilike', post['permalink_url']], ['liker_id', 'ilike', like['id']]]]) print post['permalink_url'] if count == 0: id = models.execute_kw(db, uid, password, 'customer.facebook.like', 'create', [{ 'post_url': post['permalink_url'], 'liker_id': like['id'], 'customer_id': user['id'], 'like_type': like['type'] }])
def updateUserComment(users_list, comment, post, models, common, db, uid, password): # Check if comment already exists print('updateUserComment') for user in users_list: count = models.execute_kw( db, uid, password, 'customer.facebook.comment', 'search_count', [[['post_url', 'ilike', post['permalink_url']], ['comment_id', '=', comment['id']]]]) # check if like already exists if count == 0: id = models.execute_kw(db, uid, password, 'customer.facebook.comment', 'create', [{ 'post_url': post['permalink_url'], 'comment_url': comment['permalink_url'], 'comment_id': comment['id'], 'liker_id': comment['from']['id'], 'customer_id': user['id'], 'message_str': comment['message'] }])
def action_cancel(self): if self.state in ["proc", "forpo"]: dealer_id = self.company_id.dealer_id.id url = self.company_id.api_host.strip() db = self.company_id.fmpi_pgn username = self.company_id.api_user password = self.company_id.api_pass # attempt to connect logger.info("Connecting to " + url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) fmpi_ids = models.execute_kw(db, uid, password, 'fmpi.parts.so', 'search_read', [[['dealer_id', '=', dealer_id], ['fos_parts_po_id', '=', self.id]]], { 'limit': 1, 'fields': 'id' }) if fmpi_ids: for id in fmpi_ids: is_updated = models.execute_kw(db, uid, password, 'fmpi.parts.so', 'write', [[id['id']], { 'state': 'cancel' }]) if is_updated: self.write({'state': 'cancel'}) else: self.write({'state': 'cancel'})
def nasabah(self, **kw): xmlrpclib = xmlrpc.client url, db, username, password = '******', http.request.env.cr.dbname, kw.get( 'username'), kw.get('password') models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) try: uid = common.authenticate(db, username, password, {}) res = models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[['id', '=', uid]]], { 'fields': ['id', 'name'], 'limit': 1 }) return res except Exception as e: return {'Error': 'Invalid Request', 'e': e}
def odoo_execute_kw(model, method, *args, **kwargs): log_transmission( "XMLRPC DB={} URL={}".format(params.DB, params.URL), json.dumps([method, args, kwargs]), ) try: common = _client.ServerProxy("{}/xmlrpc/2/common".format( params.URL)) uid = common.authenticate(params.DB, secrets.USERNAME, secrets.PASSWORD, {}) models = _client.ServerProxy("{}/xmlrpc/2/object".format( params.URL)) except OSError: raise RetryableJobError("Error on connecting to external Odoo") res = models.execute_kw(params.DB, uid, secrets.PASSWORD, model, method, args, kwargs) log("Response: %s" % res, level="debug") return res
def action_dis_api(self): # 1. make connection to Dealer dealer_vqir_id = self.dealer_vqir_id db = self.db url = self.url username = self.username password = self.password # attempt to connect common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) vqir_state_logs = "Document:" + self.name + "\n" + \ "Disapproved by: " + self.env.user.name + "\n" + \ "Disapproved at: " + datetime.datetime.now().strftime("%m/%d/%Y") + "\n" + \ "Disapproved notes: " + (self.name or '') + "\n" + \ "--------------------------------------------------\n" self.write({ 'vqir_state': 'disapproved', 'vqir_state_logs': str(self.vqir_state_logs or '') }) cur_stamp = fields.datetime.now() if models: logger.info("Models: " + str(models)) mod_out = models.execute_kw( db, uid, password, 'fos.vqir', 'write', [[ self.dealer_vqir_id, ], { 'vqir_state': 'disapproved', 'vqir_state_logs': str(self.vqir_state_logs or ''), "disapproved_date": cur_stamp }]) self.write({ 'vqir_state': 'disapproved', "disapproved_date": cur_stamp })
def partner_sync_button(self): dbodoo = "gp_pruebas" userodoo = "serin" passodoo = "ic2015$$" urlodoo = "51.91.158.27" common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(urlodoo)) uid = common.authenticate(dbodoo, userodoo, passodoo, {}) models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(urlodoo)) for partner in self: partner.id_remoto = models.execute_kw(dbodoo, uid, passodoo, 'res.partner', 'create', [{ 'name':partner.name, #'parent_id':partner.parent_id, #'type':partner.type, 'vat':partner.vat, #'street':partner.street, #'city':partner.city, #'state_id':partner.state_id, #'zip':partner.zip, #'country_id':partner.country_id, #'function':partner.function, #'phone':partner.phone, #'mobile':partner.mobile, 'email':partner.email, #'website':partner.website, #'title':partner.title, #'lang':partner.lang, #'customer':partner.customer, #'user_id':partner.user_id, #'opt_out':partner.opt_out, #'message_bounce':partner.message_bounce, #'supplier':partner.supplier, #'ref':partner.ref, #'company_id':partner.company_id, }])
def get_analytic_tracking_data(self): result = '' for cust in self: url = cust.instance_url db = cust.domain username = '******' password = '******' common = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/common'.format(url), verbose=False, context=ssl._create_unverified_context()) uid = common.authenticate(db, username, password, {}) models = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/object'.format(url), verbose=False, context=ssl._create_unverified_context()) data = models.execute_kw(db, uid, password, 'analytic.tracking', 'search_read', [[]], {'fields': ['name', 'value']}) result += db + ' ' for analytic_matrix in data: result += analytic_matrix['name'] + ':' + analytic_matrix[ 'value'] + ',' result += '\n' raise UserError(result)
def action_sync(self): try: xmlrpc.client.ServerProxy(self.url) url, db, username, password = self.url, self.database, self.username, self.password common = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) models = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/object'.format(url)) product_obj = self.env['product.template'] attribute_obj = self.env['product.attribute'] tmpl_attribute_line_obj = self.env[ 'product.template.attribute.line'] attribute_value_obj = self.env['product.attribute.value'] warehouse = self.env['stock.warehouse'].search( [('company_id', '=', self.env.company.id)], limit=1) db_products = models.execute_kw( db, uid, password, 'product.template', 'search_read', [[['description_pickingin', '=', 'koxul']]]) if db_products: for db_product in db_products: values = { 'name': db_product.get('name'), 'type': db_product.get('type'), 'lst_price': db_product.get('lst_price'), 'default_code': db_product.get('default_code'), 'description': db_product.get('description'), 'price': db_product.get('price'), 'standard_price': db_product.get('standard_price'), 'volume': db_product.get('volume'), 'volume_uom_name': db_product.get('volume_uom_name'), 'weight': db_product.get('weight'), 'weight_uom_name': db_product.get('weight_uom_name'), 'uom_name': db_product.get('uom_name'), 'barcode': db_product.get('barcode'), 'image_1920': db_product.get('image_1920'), 'description_sale': db_product.get('description_sale'), 'is_published': db_product.get('is_published'), 'description_pickingin': db_product.get('description_pickingin'), } sync_unique_id = str(self.id) + str(db_product.get('id')) product_tmpl_id = product_obj.search([ ('product_qnique_id', '=', sync_unique_id) ]) if not product_tmpl_id: product_tmpl_id = product_obj.create(values) product_tmpl_id.product_qnique_id = sync_unique_id product_tmpl_id.store_id = self.id else: product_tmpl_id.write(values) product_tmpl_id.list_price = db_product.get('list_price') db_tmpl_attribute_line = db_product.get( 'valid_product_template_attribute_line_ids') if not db_tmpl_attribute_line: varient_id = self.env['product.product'].search([ ('product_tmpl_id', '=', product_tmpl_id.id) ]) if varient_id and db_product.get('qty_available'): self.env['stock.quant'].with_context( inventory_mode=True).create({ 'product_id': varient_id.id, 'location_id': warehouse.lot_stock_id.id, 'inventory_quantity': db_product.get('qty_available'), }) product_tmpl_id.product_template_image_ids.unlink() db_tmpl_image_ids = db_product.get( 'product_template_image_ids') for image in db_tmpl_image_ids: db_tmpl_image_id = models.execute_kw( db, uid, password, 'product.image', 'search_read', [[['id', '=', image]]]) if db_tmpl_image_id: product_tmpl_id.write({ 'product_template_image_ids': [(0, 0, { 'name': db_tmpl_image_id[0].get('name'), 'image_1920': db_tmpl_image_id[0].get('image_1920') })] }) product_tmpl_id.attribute_line_ids.unlink() if db_tmpl_attribute_line: for tmpl_attribute_line in db_tmpl_attribute_line: db_tmpl_line = models.execute_kw( db, uid, password, 'product.template.attribute.line', 'search_read', [[['id', '=', tmpl_attribute_line]]]) if db_tmpl_line: db_att_name = db_tmpl_line[0].get( 'attribute_id') self_attribute = attribute_obj.search([ ('name', '=', db_att_name[1]) ]) if not self_attribute: self_attribute = attribute_obj.create( {'name': db_att_name[1]}) db_att_value_ids = [] for value_id in db_tmpl_line[0].get( 'value_ids'): db_att_value = models.execute_kw( db, uid, password, 'product.attribute.value', 'search_read', [[['id', '=', value_id]]]) if db_att_value: self_att_value = attribute_value_obj.search( [('name', '=', db_att_value[0].get('name'))]) if self_att_value: db_att_value_ids.append( self_att_value.id) if not self_att_value: self_att_value = attribute_value_obj.create( { 'name': db_att_value[0].get( 'name'), 'attribute_id': self_attribute.id, }) db_att_value_ids.append( self_att_value.id) tmpl_attribute_line_obj.create({ 'product_tmpl_id': product_tmpl_id.id, 'attribute_id': self_attribute.id, 'value_ids': [(6, 0, db_att_value_ids)] }) db_product_varients = models.execute_kw( db, uid, password, 'product.product', 'search_read', [[['product_tmpl_id', '=', db_product.get('id')]]]) for varient_rec in db_product_varients: self_varients = self.env['product.product'].search( [('partner_ref', '=', varient_rec.get('partner_ref'))]) update_varients = self_varients.filtered( lambda x: x.partner_ref == varient_rec.get( 'partner_ref') and x.product_tmpl_id.id == product_tmpl_id.id) if not update_varients: varient_ref = varient_rec.get( 'partner_ref').split('] ')[1] update_varients = self_varients.filtered( lambda x: x.partner_ref == varient_ref and x.product_tmpl_id.id == product_tmpl_id.id) update_varients.update({ 'name': varient_rec.get('name'), 'type': varient_rec.get('type'), 'price': varient_rec.get('price'), 'lst_price': varient_rec.get('lst_price'), 'default_code': varient_rec.get('default_code'), 'code': varient_rec.get('code'), 'barcode': varient_rec.get('barcode'), 'standard_price': varient_rec.get('standard_price'), 'volume': varient_rec.get('volume'), 'weight': varient_rec.get('weight'), 'description': varient_rec.get('description'), 'list_price': varient_rec.get('list_price'), 'volume_uom_name': varient_rec.get('volume_uom_name'), 'weight_uom_name': varient_rec.get('weight_uom_name'), 'image_variant_1920': varient_rec.get('image_variant_1920'), 'description_sale': db_product.get('description_sale'), 'is_published': db_product.get('is_published'), 'description_pickingin': db_product.get('description_pickingin'), }) for varient in varient_rec.get( 'product_template_attribute_value_ids'): att_value = models.execute_kw( db, uid, password, 'product.template.attribute.value', 'search_read', [[['id', '=', varient]]]) self_att_val = self.env[ 'product.template.attribute.value'].search( [('product_tmpl_id', '=', product_tmpl_id.id), ('name', '=', att_value[0].get('name')), ('display_name', '=', att_value[0].get('display_name'))]) if self_att_val: self_att_val.price_extra = att_value[ 0].get('price_extra') if varient_rec.get('qty_available'): self.env['stock.quant'].with_context( inventory_mode=True).create({ 'product_id': update_varients.id, 'location_id': warehouse.lot_stock_id.id, 'inventory_quantity': varient_rec.get('qty_available'), }) except: raise AccessError(_("[Errno 111] Connection refused"))
def sync_units(self): url = self.fmpi_host.strip() db = self.fmpi_pgn username = self.fmpi_pgu password = self.fmpi_pgp # attempt to connect logger.info("Connecting to " + url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) # get entire units from product_template fmpi_pts = models.execute_kw(db, uid, password, 'product.template', 'search_read', [[('sub_type', '=', 'units')]], {'fields': ['id', 'write_date']}) if fmpi_pts: dealer_pt_obj = self.env['product.template'] for fmpi_pt in fmpi_pts: logger.info("Searching FMPI ID " + str(fmpi_pt['id']) + " from " + str(self.env.cr.dbname)) dealer_pts = self.env['product.template'].search([ ('fmpi_product_id', 'in', [fmpi_pt['id']]) ]) if not dealer_pts: logger.info("New Template from FMPI...") fmpi_pt_full_detail = models.execute_kw( db, uid, password, 'product.template', 'search_read', [[['id', '=', fmpi_pt['id']]]]) if fmpi_pt_full_detail: values = { 'name': fmpi_pt_full_detail[0]['name'], 'description': fmpi_pt_full_detail[0]['description'], 'description_sale': fmpi_pt_full_detail[0]['description_sale'], 'description_purchase': fmpi_pt_full_detail[0]['description_purchase'], 'type': fmpi_pt_full_detail[0]['type'], 'list_price': fmpi_pt_full_detail[0]['list_price'], 'standard_price': fmpi_pt_full_detail[0]['dnp'] or 0, 'sub_type': fmpi_pt_full_detail[0]['sub_type'], 'categ_id': self.units_categ_id.id, 'volume': fmpi_pt_full_detail[0]['volume'], 'weight': fmpi_pt_full_detail[0]['weight'], 'sale_ok': fmpi_pt_full_detail[0]['sale_ok'], 'purchase_ok': fmpi_pt_full_detail[0]['purchase_ok'], 'active': fmpi_pt_full_detail[0]['active'], 'default_code': fmpi_pt_full_detail[0]['default_code'] or '', 'sale_delay': fmpi_pt_full_detail[0]['sale_delay'], 'tracking': fmpi_pt_full_detail[0]['tracking'], 'description_picking': fmpi_pt_full_detail[0]['description_picking'] or '', 'description_pickingout': fmpi_pt_full_detail[0]['description_pickingout'] or '', 'description_pickingin': fmpi_pt_full_detail[0]['description_pickingin'] or '', 'service_type': fmpi_pt_full_detail[0]['service_type'] or '', 'sale_line_warn': fmpi_pt_full_detail[0]['sale_line_warn'] or '', 'sale_line_warn_msg': fmpi_pt_full_detail[0]['sale_line_warn_msg'] or '', 'expense_policy': fmpi_pt_full_detail[0]['expense_policy'] or '', 'invoice_policy': fmpi_pt_full_detail[0]['invoice_policy'] or '', 'purchase_method': fmpi_pt_full_detail[0]['purchase_method'] or '', 'purchase_line_warn': fmpi_pt_full_detail[0]['purchase_line_warn'] or '', 'purchase_line_warn_msg': fmpi_pt_full_detail[0]['purchase_line_warn_msg'] or '', 'isc': fmpi_pt_full_detail[0]['isc'] or 0, 'fob_php': fmpi_pt_full_detail[0]['fob_php'] or 0, 'fob_usd': fmpi_pt_full_detail[0]['fob_usd'] or 0, 'fob_rmb': fmpi_pt_full_detail[0]['fob_rmb'] or 0, 'dnp': 0, 'loc1': fmpi_pt_full_detail[0]['loc1'] or '', 'loc2': fmpi_pt_full_detail[0]['loc2'] or '', 'loc3': fmpi_pt_full_detail[0]['loc3'] or '', 'loc4': fmpi_pt_full_detail[0]['loc4'] or '', 'loc5': fmpi_pt_full_detail[0]['loc5'] or '', 'loc6': fmpi_pt_full_detail[0]['loc6'] or '', 'loc7': fmpi_pt_full_detail[0]['loc7'] or '', 'loc8': fmpi_pt_full_detail[0]['loc8'] or '', 'loc9': fmpi_pt_full_detail[0]['loc9'] or '', 'model': fmpi_pt_full_detail[0]['model'] or '', 'model_code': fmpi_pt_full_detail[0]['model_code'] or '', 'inner_code': fmpi_pt_full_detail[0]['inner_code'] or '', 'segment': fmpi_pt_full_detail[0]['segment'] or '', 'fmpi_product_write_date': fmpi_pt_full_detail[0]['write_date'], 'no_of_hours': fmpi_pt_full_detail[0]['no_of_hours'] or 0, 'run_by_sync': True, 'fmpi_product': True, 'fmpi_product_id': fmpi_pt_full_detail[0]['id'] } self.env['product.template'].create(values) else: for dealer_pt in dealer_pts: logger.info("Checking Unit: " + dealer_pt.name) if fmpi_pt['write_date'] == dealer_pt[0][ 'fmpi_product_write_date']: logger.info("Nothing changed on ID " + str(fmpi_pt['id']) + " skipping...") else: # update dealer's product_template logger.info("FMPI's " + str(fmpi_pt['id']) + " has changed. Updating...") # get full details from FMPI fmpi_pt_full_detail = models.execute_kw( db, uid, password, 'product.template', 'search_read', [[['id', '=', dealer_pt[0]['fmpi_product_id']]] ]) if fmpi_pt_full_detail: values = { 'name': fmpi_pt_full_detail[0]['name'], 'description': fmpi_pt_full_detail[0]['description'], 'description_sale': fmpi_pt_full_detail[0]['description_sale'], 'description_purchase': fmpi_pt_full_detail[0] ['description_purchase'], 'type': fmpi_pt_full_detail[0]['type'], 'list_price': fmpi_pt_full_detail[0]['list_price'], 'sub_type': fmpi_pt_full_detail[0]['sub_type'], 'categ_id': self.units_categ_id.id, 'standard_price': fmpi_pt_full_detail[0]['dnp'] or 0, 'volume': fmpi_pt_full_detail[0]['volume'], 'weight': fmpi_pt_full_detail[0]['weight'], 'sale_ok': fmpi_pt_full_detail[0]['sale_ok'], 'purchase_ok': fmpi_pt_full_detail[0]['purchase_ok'], 'active': fmpi_pt_full_detail[0]['active'], 'default_code': fmpi_pt_full_detail[0]['default_code'] or '', 'sale_delay': fmpi_pt_full_detail[0]['sale_delay'], 'tracking': fmpi_pt_full_detail[0]['tracking'], 'description_picking': fmpi_pt_full_detail[0] ['description_picking'] or '', 'description_pickingout': fmpi_pt_full_detail[0] ['description_pickingout'] or '', 'description_pickingin': fmpi_pt_full_detail[0] ['description_pickingin'] or '', 'service_type': fmpi_pt_full_detail[0]['service_type'] or '', 'sale_line_warn': fmpi_pt_full_detail[0]['sale_line_warn'] or '', 'sale_line_warn_msg': fmpi_pt_full_detail[0] ['sale_line_warn_msg'] or '', 'expense_policy': fmpi_pt_full_detail[0]['expense_policy'] or '', 'invoice_policy': fmpi_pt_full_detail[0]['invoice_policy'] or '', 'purchase_method': fmpi_pt_full_detail[0]['purchase_method'] or '', 'purchase_line_warn': fmpi_pt_full_detail[0] ['purchase_line_warn'] or '', 'purchase_line_warn_msg': fmpi_pt_full_detail[0] ['purchase_line_warn_msg'] or '', 'isc': fmpi_pt_full_detail[0]['isc'] or 0, 'fob_php': fmpi_pt_full_detail[0]['fob_php'] or 0, 'fob_usd': fmpi_pt_full_detail[0]['fob_usd'] or 0, 'fob_rmb': fmpi_pt_full_detail[0]['fob_rmb'] or 0, 'dnp': 0, 'loc1': fmpi_pt_full_detail[0]['loc1'] or '', 'loc2': fmpi_pt_full_detail[0]['loc2'] or '', 'loc3': fmpi_pt_full_detail[0]['loc3'] or '', 'loc4': fmpi_pt_full_detail[0]['loc4'] or '', 'loc5': fmpi_pt_full_detail[0]['loc5'] or '', 'loc6': fmpi_pt_full_detail[0]['loc6'] or '', 'loc7': fmpi_pt_full_detail[0]['loc7'] or '', 'loc8': fmpi_pt_full_detail[0]['loc8'] or '', 'loc9': fmpi_pt_full_detail[0]['loc9'] or '', 'model': fmpi_pt_full_detail[0]['model'] or '', 'model_code': fmpi_pt_full_detail[0]['model_code'] or '', 'inner_code': fmpi_pt_full_detail[0]['inner_code'] or '', 'segment': fmpi_pt_full_detail[0]['segment'] or '', 'fmpi_product_write_date': fmpi_pt_full_detail[0]['write_date'], 'no_of_hours': fmpi_pt_full_detail[0]['no_of_hours'] or 0, 'run_by_sync': True, 'fmpi_product': True } dealer_pt.write(values)
def write(self, vals): res = super(ResUsers, self).write(vals) if not self.env.context.get('from_partner'): for user in self: if user.partner_id: if user.user_role: user.partner_id.with_context(from_user=True).write({ 'user_role': user.user_role }) if user.active is False: user.partner_id.with_context(from_user=True).write({ 'active': False }) else: user.partner_id.with_context(from_user=True).write({ 'active': True }) if user.state == 'new': user.partner_id.with_context(from_user=True).write({ 'res_user_state': 'Pending' }) elif user.state == 'active': user.partner_id.with_context(from_user=True).write({ 'res_user_state': 'Active' }) if 'active' in vals or 'name' in vals: parent_company = user.partner_id.parent_id if parent_company.subscription_company: url = parent_company.instance_url db = parent_company.database_id.name username = user.login password = user.password params = { 'name': user.name, 'active': user.active, } try: common = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/common'.format(url), verbose=False, context=ssl._create_unverified_context()) uid = common.authenticate(db, username, password, {}) models = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/object'.format(url), verbose=False, context=ssl._create_unverified_context()) models.execute_kw(db, uid, password, 'res.users', 'write', [uid, params]) except Exception: pass if 'password' in vals: parent_company = user.partner_id.parent_id if parent_company.subscription_company: url = parent_company.instance_url db = parent_company.database_id.name username = user.login password = user.password try: common = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/common'.format(url), verbose=False, context=ssl._create_unverified_context()) uid = common.authenticate(db, username, password, {}) models = xmlrpc.client.ServerProxy( '{}/xmlrpc/2/object'.format(url), verbose=False, context=ssl._create_unverified_context()) self.env.cr.execute( 'select password, internal_password from res_users where id=%s', (user.id,)) result = self.env.cr.fetchone() models.execute_kw(db, uid, password, 'res.users', 'api_set_password', [result, uid]) except Exception: pass return res
def update_repositories(self): for record in self: db, uid, password, models = record._get_xmlrpc_object(record.name) ids = models.execute_kw(db, uid, password, 'saas_server.repository', 'search', [[]],) models.execute_kw(db, uid, password, 'saas_server.repository', 'update', [ids]) return True
def restart_server(self): for record in self: db, uid, password, models = record._get_xmlrpc_object(record.name) models.execute_kw(db, uid, password, 'saas_server.client', 'restart_server', []) return True
def dit_show_likes(self): # Generates a random name between 9 and 15 characters long and writes it to the record. print 'hello =======================' api_key = 'Your_Api_key_Here' # Database connection url = 'http://localhost:8069' db = 'db_name' username = '******' password = '******' common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) graph = facebook.GraphAPI(access_token=api_key, version='2.9') posts = self.getPosts(25, graph) print 'posts' if 'data' in posts: for post in posts['data']: print post['reactions']['data'] for reaction in post['reactions']['data']: print reaction if 'name' in reaction: users_list = getUserFromDb(reaction['name'], models, common, db, uid, password) updateUserLike(users_list, reaction, post, models, common, db, uid, password) for comment in post['comments']['data']: if 'message' in comment: if 'id' in comment: if 'permalink_url' in comment: if 'from' in comment: users_list = getUserFromDb( comment['from']['name'], models, common, db, uid, password) updateUserComment(users_list, comment, post, models, common, db, uid, password) print 'reading comments' records = models.execute_kw( db, uid, password, 'customer.facebook.comment', 'search_read', [[]], {'fields': ['comment_id', 'post_url', 'liker_id']}) rec = {} for record in records: print record['comment_id'] comment_id = record['comment_id'] rec = models.execute_kw( db, uid, password, 'customer.facebook.like', 'search_read', [[['post_url', '=', record['post_url']], ['liker_id', 'like', record['liker_id']]]], {'fields': ['liker_id', 'like_type', 'post_url']}) print 'copuuuuuuuuuuuuuuuuuuuuunt' print rec if rec: models.execute_kw(db, uid, password, 'customer.facebook.comment', 'write', [ record['id'], { 'liked': True, 'like_type': rec[0]['like_type'] } ]) obj_comm = {} print 'try' try: obj_comm = graph.get_object(comment_id) except Exception as e: print('Exception!!!') print e finally: if 'id' not in obj_comm: # comment deleted : Update database models.execute_kw(db, uid, password, 'customer.facebook.comment', 'write', [record['id'], { 'deleted': True }]) print 'reading comments finished' return { "name": "facebook", "type": "ir.actions.act_window", "res_model": "customer.facebook.like", "views": [[False, "form"], [False, "tree"]], "view_mode": "form,tree", }
def restart_server(self): for record in self: db, uid, password, models = record._get_xmlrpc_object(record.name) models.execute_kw(db, uid, password, 'saas_server.client', 'restart_server', []) return True
def action_confirm(self): partner_obj = self.env['res.partner'] partner_id = partner_obj.search([ ('name', '=', 'UNITED ASIA AUTOMOTIVE GROUP, INC.') ]).id no_error = True if partner_id: po_id = self.env['purchase.order'].create({ 'partner_id': partner_id, 'po_type': 'parts', 'date_planned': fields.datetime.now(), 'notes': self.name + "\n" + (self.notes or ""), 'origin': self.name }) if po_id: for line in self.order_line: po_line_id = self.env['purchase.order.line'].create({ 'order_id': po_id.id, 'fu_id': line.fu_id.id, 'product_id': line.assigned_product_id, 'name': line.assigned_description, 'product_qty': line.order_qty, 'price_unit': line.assigned_price_unit, 'date_planned': fields.datetime.now(), 'product_uom': line.product_id.product_tmpl_id.uom_po_id.id, 'eta': line.eta }) fpos = po_line_id.order_id.fiscal_position_id po_line_id.taxes_id = fpos.map_tax( po_line_id.product_id.supplier_taxes_id) logger.info("Estimated Time" + str(line.eta)) if not po_line_id: no_error = False else: no_error = False else: no_error = False if no_error: # create sale order to fmpi dealer_id = self.company_id.dealer_id.id url = self.company_id.fmpi_host.strip() db = self.company_id.fmpi_pgn username = self.company_id.fmpi_pgu password = self.company_id.fmpi_pgp # attempt to connect logger.info("Connecting to " + url) common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: raise exceptions.except_orm( _('Remote Authentication Failed'), _(url + " failed to authenticate " + username)) return models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) # check existence of dealer's name as res_partner from fmpi database res_partner_name = self.company_id.dealer_id.name.strip() [partner_ids ] = models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[['name', '=', res_partner_name]]], { 'limit': 1, 'fields': ['id'] }) #fmpi_partner_id = 0 if partner_ids: fmpi_partner_id = partner_ids['id'] else: fmpi_partner_id = models.execute_kw( db, uid, password, 'res.partner', 'create', [{ 'name': res_partner_name, 'customer': True, }]) if fmpi_partner_id: logger.info("Partner ID: " + str(fmpi_partner_id)) so_id = models.execute_kw( db, uid, password, 'sale.order', 'create', [{ 'partner_id': fmpi_partner_id, 'so_type': 'parts', 'note': self.name + "\n" + (self.notes or ""), 'origin': self.name }]) logger.info("Sale Order ID: " + str(so_id)) if so_id: line_ids = models.execute_kw( db, uid, password, 'fmpi.parts.so.line', 'search_read', [[['fmpi_parts_so_id', '=', self.fmpi_parts_so_id]]]) if line_ids: for line_id in line_ids: fmpi_parts_so_lines = models.execute_kw( db, uid, password, 'fmpi.parts.so.line', 'search_read', [[['id', '=', line_id['id']]]]) #for line in fmpi_parts_so_lines: values = { 'order_id': so_id, 'charged_to': 'customer', 'part_number': (fmpi_parts_so_lines[0] ['assigned_product_id'][0]), 'product_id': (fmpi_parts_so_lines[0] ['assigned_product_id'][0]), 'name': (fmpi_parts_so_lines[0]['assigned_description'] ), 'product_uom_qty': (fmpi_parts_so_lines[0]['order_qty']), 'price_unit': (fmpi_parts_so_lines[0]['assigned_price_unit'] ), 'fu_id': (fmpi_parts_so_lines[0]['fu_id'][0] if fmpi_parts_so_lines[0]['fu_id'] else 0) } models.execute_kw(db, uid, password, 'sale.order.line', 'create', [values]) models.execute_kw(db, uid, password, 'fmpi.parts.so', 'write', [[self.fmpi_parts_so_id], { 'state': 'confirm', 'sale_order_id': so_id }]) else: raise exceptions.except_orm(_('Remote Action Failed'), _("Cannot create Partner Profile")) self.write({'state': 'confirm', 'purchase_order_id': po_id.id})