daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Nov 6th, 2018 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xmlrpc.client as xmlrpclib
  2. import ssl
  3.  
  4. ssl._create_default_https_context = ssl._create_unverified_context
  5.  
  6. host = self.env['ir.config_parameter'].sudo().get_param('wp_host')
  7. db = self.env['ir.config_parameter'].sudo().get_param('wp_db')
  8. user = self.env['ir.config_parameter'].sudo().get_param('wp_user')
  9. password = self.env['ir.config_parameter'].sudo().get_param('wp_password')
  10.  
  11. # when fail connect to WP Server, dont do anything
  12. try:
  13.     common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(host))
  14.     uid = common.authenticate(db, user, password, {})
  15.     models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(host))
  16. except:
  17.     raise UserError("Fail Connect Server")
  18.  
  19. #search company
  20. company = models.execute_kw(db, uid, password, 'res.company', 'search', [[['partner_wpd', '=', self.partner_id.id or self.invoice_ids[0].partner_id.id]]])
  21. if not company:
  22.     raise UserError('Company is not found in WP server')
  23. #search journal
  24. journal = models.execute_kw(db, uid, password, 'account.journal', 'search', [[['code', '=', 'KUDO'], ['company_id', '=', company[0]]]])
  25. if not journal:
  26.     raise UserError('Journal is not found in WP server')
  27. # create payment
  28. payment = models.execute_kw(db, uid, password, 'account.payment', 'create',[{
  29.     'payment_type': 'outbound',
  30.     'partner_type': 'supplier',
  31.     'partner_id': 5457,
  32.     'amount': rec.amount,
  33.     'journal_id': journal[0],
  34.     'payment_method_id': 1,
  35.     'company_id': company[0],
  36.     'currency_id': 13
  37. }])
  38. models.execute_kw(db, uid, password, 'account.payment', 'post',[payment])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top