Advertisement
Guest User

Untitled

a guest
Nov 12th, 2017
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.38 KB | None | 0 0
  1. import xmlrpclib
  2. from datetime import datetime
  3.  
  4. # url = "http://localhost:8069"
  5. # db = "RAJO"
  6. # username = 'a'
  7. # password = 'a'
  8. url = "https://erp.atlantis-kw.com"
  9. db = "RAJO_TEST"
  10. username = 'api'
  11. password = 'api'
  12. common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
  13. uid = common.authenticate(db, username, password, {})
  14. models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
  15.  
  16.  
  17. class Partners():
  18.     def read(self):
  19.         # Read customers
  20.         model_name = 'res.partner'
  21.         partner_ids = models.execute_kw(db, uid, password, model_name, 'search', [[['customer', '=', True]]])
  22.         partner_records = models.execute_kw(db, uid, password, model_name, 'read', [partner_ids])
  23.         return partner_records
  24.  
  25.     def create(self):
  26.         # Create customer
  27.         model_name = 'res.partner'
  28.         vals = {
  29.             'name': "New Customer",
  30.         }
  31.         new_id = models.execute_kw(db, uid, password, model_name, 'create', [vals])
  32.         return new_id
  33.  
  34.     def update(self, id):
  35.         # Update customer
  36.         model_name = 'res.partner'
  37.         models.execute_kw(db, uid, password, model_name, 'write', [[id], {
  38.             'name': "Newer partner"
  39.         }])
  40.  
  41.  
  42. class Product():
  43.     # Read product
  44.     def read(self):
  45.         model_name = 'product.product'
  46.         product = models.execute_kw(db, uid, password, model_name, 'search_read', [[]], {'limit': 1})[0]
  47.  
  48.  
  49. class Candidate():
  50.     def read(self):
  51.         # # Read candidate
  52.         model_name = 'rajo.candidate'
  53.         candidate = models.execute_kw(db, uid, password, model_name, 'search_read', [[]], {'limit': 1})[0]
  54.  
  55.  
  56. class SaleOrder():
  57.     def read(self):
  58.         # Read sale order
  59.         model_name = 'sale.order'
  60.         order_ids = models.execute_kw(db, uid, password, model_name, 'search', [[]])
  61.         order_records = models.execute_kw(db, uid, password, model_name, 'read', [order_ids])
  62.  
  63.     def create(self, partner_id, candidate_id, line_name, product_id):
  64.         # Create sale order
  65.         model_name = 'sale.order'
  66.         vals = {
  67.             'origin': "A555",
  68.             'client_order_ref': "B555",
  69.             'partner_id': partner_id,  # api partner
  70.             'pricelist_id': 1,  # Public Pricelist (KWD)
  71.             'partner_invoice_id': partner_id,
  72.             'partner_shipping_id': partner_id,
  73.             'order_line': [(0, 0, {
  74.                 'name': line_name,
  75.                 'product_id': product_id,
  76.                 'product_uom_qty': 2,
  77.                 'qty_delivered': 2,
  78.                 'price_unit': 1000.00,
  79.                 'candidate_id': candidate_id,
  80.             })]
  81.         }
  82.         new_id = models.execute_kw(db, uid, password, model_name, 'create', [vals])
  83.         return new_id
  84.  
  85.  
  86. class Ticket():
  87.     def read(self):
  88.         # Read ticket
  89.         model_name = 'helpdesk.ticket'
  90.         tickets = models.execute_kw(db, uid, password, model_name, 'search_read', [[['partner_id', '=', partner['id']]]])
  91.  
  92.     def create(self, partner_id, candidate_id):
  93.         # Create ticket
  94.         model_name = 'helpdesk.ticket'
  95.         vals = {
  96.             'name': "Test ticket",
  97.             'partner_id': partner_id,
  98.             'candidate_id': candidate_id,
  99.         }
  100.         new_id = models.execute_kw(db, uid, password, model_name, 'create', [vals])
  101.         return new_id
  102.    
  103.  
  104. class Payment():
  105.     def create(self, sale_order_id):
  106.         # Create invoice and register payment
  107.         model_name = 'sale.order'
  108.         models.execute_kw(db, uid, password, model_name, 'action_confirm', [[sale_order_id]])
  109.         new_invoice_id = models.execute_kw(db, uid, password, model_name, 'action_invoice_create', [[sale_order_id]])
  110.         model_name = 'account.invoice'
  111.         models.execute_kw(db, uid, password, model_name, 'action_invoice_open', new_invoice_id)
  112.         ctx = {'active_model': 'account.invoice', 'active_ids': new_invoice_id}
  113.         vals = {
  114.             'payment_date': str(datetime.now()),
  115.             'journal_id': 7,  # Bank journal ID
  116.             'payment_method_id': 1,  # manual
  117.             'amount': 2000.00,
  118.         }
  119.         model_name = 'account.register.payments'
  120.         registered_payment_id = models.execute_kw(db, uid, password, model_name, 'create', [vals], {'context': ctx})
  121.         models.execute_kw(db, uid, password, model_name, 'create_payment', [[registered_payment_id]], {'context': ctx})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement