我想使用 API xml rpc 在 odoo 11 中创建雇主休假(假期(,以便稍后将其与我的移动应用程序连接,但仍然出现错误。我试图更改这些字段,因为它们出现在 odoo 的叶子模块中:
描述,离开类型,开始日期,开始日期,雇主ID
这是代码:
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()
当我运行代码时,出现此错误:
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)'>
试试这个(去掉方括号(:
# 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)
最后这段代码对我有用,一切都很好,但错误在于我如何在此处插入数据
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()