import xmlrpc.client
import datetime
import json
import requests
class Odoo():
def __init__(self):
"""
create invoice
create invoice line
"""
self.DATA = "PetherSolution" # db name
self.USER = "demo" # email address
self.PASS = "demo" # password
self.PORT = "8069" # port
self.URL = "http://localhost" # 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
, 'res.partner'
, 'create'
, partnerRow)
return partner_id
def partnerCheck(self, partnerName):
odoo_filter = [[("name", "=", partnerName)]]
partner_id = self.ODOO_OBJECT.execute_kw(
self.DATA
, self.UID
, self.PASS
, 'res.partner'
, 'search'
, odoo_filter)
if partner_id :
return partner_id[0]
else :
return None
def invoiceAdd(self, invoiceNam):
invoice_id = self.ODOO_OBJECT.execute_kw(
self.DATA
, self.UID
, self.PASS
, 'account.move'
, 'create'
, invoiceNam
, 'invoice_open',
)
if invoice_id:
return invoice_id
else:
return None
def productAdd(self,productcolu):
product_id = self.ODOO_OBJECT.execute_kw(
self.DATA
, self.UID
, self.PASS
, 'product.product'
, 'create'
, productcolu)
return product_id
def main():
''' url_login ='https://api.testing.pethersolutions.com/ghi/c/ws/ws-login.php'
urlSub = 'https://api.testing.pethersolutions.com/ghi/reg/ws/'
payload = {'op':'login'
, 'user':'christian'
, 'pass' : 'christian123'
, 'orgid' : '1'
, 'mid' : 'undefined'
, 'midtype' : 'host'
, 'remHost' : '154.72.167.161'
, 'magik' : '1534110443'
}
r = requests.post(url_login, data=payload)
data = r.json() '''
od = Odoo()
od.authenticateOdoo()
productcolu = [{
'name': 'ABC1234',
'default_code': '123456789'
}]
product_id = od.productAdd(productcolu)
partner_id = od.partnerCheck("Azure Interior")
print(partner_id)
invoiceNam = [{
'partner_id' : partner_id
,'account_id' : '219'
}]
print(invoiceNam)
invoice_id = od.invoiceAdd(partner_id)
if __name__ == '__main__':
main()
here is my code, but it doesn't work and gives me this error
= dispatch(method, params)\n File "C:\\Program Files (x86)\\Odoo 13.0e\\server\\odoo\\service\\model.py", line 40, in dispatch\n res = fn(db, uid, *params)\n File "C:\\Program Files (x86)\\Odoo 13.0e\\server\\odoo\\service\\model.py", line 168, in execute_kw\n return execute(db, uid, obj, method, *args, **kw or {})\nTypeError: execute() argument after * must be an iterable, not int\n'>