Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create web service in Odoo-9?

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.10k
    Comment on it

    In Odoo-9 you have to create module and xmlrpc folder in server and install the apache2 in your system.

    After this follow the step given below:

    Step1- First create apache2 for our system using the command show below

    sudo apt-get install apache2

     

    Step2- After this, create xmlrpc folder in this location Go to www ->  var ->  html and all .php file save here.

    Example:- Create feedback.php file configure it with odoo server like, database name and also create username and password of odoo server similar to feedback.php file. use this code given below

    <?php
    include("xmlrpc.inc");
    
    $user = "Your login name(admin)";
    $password = "Your Password (admin)";
    $db = "Your database Name(Test)";
    $serverUri = "http://localhost:8080/xmlrpc/";
    
    $client = new xmlrpc_client($serverUri . 'common');
    $msg = new xmlrpcmsg('login');
    $msg->addParam(new xmlrpcval('9_xmlrpc', "string"));
    $msg->addParam(new xmlrpcval('admin', "string"));
    $msg->addParam(new xmlrpcval('admin', "string"));
    $res = $client->send($msg);
    $val = $res->value();
    $id = $val->scalarval();
    
    $create_feedback_form = array(
      		'name' =>new xmlrpcval($_POST['name'],'string'),
      		'description' =>new xmlrpcval($_POST['description'],'string'),
    		'phone' =>new xmlrpcval($_POST['phone'],'string'),
    );
    
    $client = new xmlrpc_client($serverUri . 'object');
    $msg = new xmlrpcmsg('execute');
    $msg->addParam(new xmlrpcval('9_xmlrpc', "string"));
    $msg->addParam(new xmlrpcval('1', "int"));
    $msg->addParam(new xmlrpcval('admin', "string"));
    $msg->addParam(new xmlrpcval("feedback.form", "string"));
    $msg->addParam(new xmlrpcval("create", "string"));
    $msg->addParam(new xmlrpcval($create_feedback_form, "struct"));
    $res = $client->send($msg);	
    if($res){
    	echo 'Successfully Submited'; exit;	
    }
    ?>

     

    Step3- After this, create form and map this form to feedback.php in odoo.

    Use this code in .py file given below

    from openerp import api, fields, models, _
    
    class res_partner(models.Model):
        _inherit='res.partner'
                 
        business = fields.Many2one('nursery', string='BUSINESS CATEGORY')
        Contact = fields.Char(string='Contact Person')
    res_partner()
    class nursery(models.Model):
        _name = 'nursery'
        
        name = fields.Char(string='Name',size=30)
        
    nursery()

     

    Step4- Use this code to create form and save file name as I did, feedback_submission.php and put this file in odoo server module also pass the given link to open form in web service in browser and also map all field to relate .py file and feedback.php file.

     <form action="http://localhost/changes/feedback.php" method="POST">
      Customer phone number:<br>
      <input type="text" name="phone">
      <br>
      Customer name:<br>
      <input type="text" name="name">
      <br>
      description: <br>
       <input type="text" name="description" ><br><br>
      <input type="submit" value="Submit">
    </form> 
    
    
    http://localhost/xmlprc/feedback_submission.php

    I have attached full module below you can directly download ZIP file to use.

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: