odoo_dev 开发培训作业:图书管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3KB

  1. from xmlrpc import client
  2. server_url = 'http://localhost:9999'
  3. db_name = 'library_13'
  4. username = 'user2'
  5. password = '098iop'
  6. common = client.ServerProxy('%s/xmlrpc/2/common' % server_url)
  7. user_id = common.authenticate(db_name, username, password, {})
  8. models = client.ServerProxy('%s/xmlrpc/2/object' % server_url)
  9. if user_id:
  10. # create new books
  11. create_data = [
  12. {'name': 'Book 1', 'date_release': '2019-01-26'},
  13. {'name': 'Book 3', 'date_release': '2019-02-12'},
  14. {'name': 'Book 3', 'date_release': '2019-05-08'},
  15. {'name': 'Book 7', 'date_release': '2019-05-14'}
  16. ]
  17. books_ids = models.execute_kw(db_name, user_id, password, 'library.book', 'create', [create_data])
  18. print("Books created:", books_ids)
  19. # # Write in existing book record
  20. book_to_write = books_ids[1] # We will use ids of recently created books
  21. write_data = {'name': 'Books 2'}
  22. written = models.execute_kw(db_name, user_id, password, 'library.book', 'write', [book_to_write, write_data])
  23. print("Books written:", written)
  24. # Delete the book record
  25. books_to_delete = books_ids[2:] # We will use ids of recently created books
  26. deleted = models.execute_kw(db_name, user_id, password, 'library.book', 'unlink', [books_to_delete])
  27. print('Books unlinked:', deleted)
  28. else:
  29. print('Wrong credentials')
上海开阖软件有限公司 沪ICP备12045867号-1