Search code examples
python-3.xapimobileodooxml-rpc

Odoo API using XML-RPC to create employers leaves


I want to create employers leaves (vacations) in odoo 11 using API xml rpc to connect it later with my mobile app but still errors appear to me. I tried to change these field cause they appears in leaves module in odoo :

description ,leaves type ,date of starting,date of starting,employer id

here is the code :

import xmlrpc.client
import datetime

class Odoo():
def __init__(self):

    self.DATA = "aziz" # db name
    self.USER = "admin" # email address
    self.PASS = "admin" # password
    self.PORT = "8069" # port
    self.URL  = "http://127.0.0.1" # base url
    self.URL_COMMON = "{}:{}/xmlrpc/2/common".format(
        self.URL, self.PORT)
    self.URL_OBJECT = "{}:{}/xmlrpc/2/object".format(
        self.URL, self.PORT)

def authenticateOdoo(self):
    self.ODOO_COMMON = xmlrpc.client.ServerProxy(self.URL_COMMON)
    self.ODOO_OBJECT = xmlrpc.client.ServerProxy(self.URL_OBJECT)
    self.UID = self.ODOO_COMMON.authenticate(
        self.DATA
        , self.USER
        , self.PASS
        , {})
def partnerAdd(self, partnerRow):
    partner_id = self.ODOO_OBJECT.execute_kw(
        self.DATA
        , self.UID
        , self.PASS
        , 'hr.holidays'
        , 'create'
        , partnerRow)
    return partner_id






def main():
od = Odoo()
od.authenticateOdoo()

# Examples:

# CREATE
partner_row = [{"name":"salami"
                    , "hr_holidays_status":"4"
                    , "date_from":"08/13/2018 12:45:30"
                    , "date_to":"08/17/2018 20:49:26"
                    , "employee_id":"1"}]
od.partnerAdd(partner_row)







if __name__ == '__main__':
main()

When I run code I have this error:

xmlrpc.client.Fault: <Fault 4: '("Database fetch misses ids ((\'1\',)) and     has extra ids ((1,)), may be caused by a type incoherence in a previous request", None)'>

Solution

  • finally this code works with me every thing was fine but the error was in how did I insert the data here

    def main():
    
        od = Odoo()
        od.authenticateOdoo()
    
        # Examples:
    
        # CREATE
        partner_row = [{"name":"holyeid"
                            , "holiday_status_id":int(1)
                            , "date_from":"2018-08-14 16:35:38"
                            , "date_to":"2018-08-16 16:35:38"
                            , "employee_id":int(1)
                            , 
                            }]
    
    
        od.partnerAdd(partner_row)
    
    
    
    if __name__ == '__main__':
        main()