Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Why my Module dont want start the Function

By
Patrick
on 12/1/16, 3:47 AM 71 views

Hello, my Module dont want start the Function if I klick on the "import" Button.
The Function of my Modul:
My Module import easyer Products, this Module needs only the EAN number.
The Module takes the EAN Number and make a GET Request to a Web API.
The Web API send the Infos about this Product back and my Module writes the Infos in the Database with the XMLRPC API.
But if i write the EAN Number and but the "Import" Button , nothing happens .
I tested it with a normal python Script and the Code under "headers = ...." is correct.
And if the Modul starts the Function how can I read the Value from the Fields?

The Code of my models.py:

# -*- encoding: utf-8 -*-
#Description: ITScope Modul für Odoo
#Dev: Patrick Mitteregger
from openerp import models, fields, api
from openerp.tools.translate import _
import httplib
import base64
import libxml2
import xmlrpclib
import urllib
url = 'http://odoo.blucon.net:8069'
username = ''
pwd = ''
dbname = 'Test'
sock_common = xmlrpclib.ServerProxy('{}/xmlrpc/common'.format(url))
login = sock_common.login(dbname,username,pwd)
sock = xmlrpclib.ServerProxy('{}/xmlrpc/object'.format(url))
product = 'product.product'
accountID = ""
apiKey = ""
ean = 0
class product_search(models.Model):
#########################################################################
        #Auswahl des Nutzers (Über Formular) auslesen und in Variablen speichern#
        #########################################################################
        _name = "itscope_modul.itscope_modul"
        eanumber = fields.Char('Eanumber',required=True)
        language = fields.Char('Language',default="de")
@api.multi
        def search_prod(self):
eanum = self.eanumber
        langu = self.language
#########################################################################
    #Mit der ItScope API verbinden und die Infos vom Produkt holen #
    #########################################################################
    headers = {'Authorization' : 'Basic %s' % base64.b64encode(accountID+ ':'+ apiKey), 'Accept-Language' : langu} url = "https://api.itscope.com/2.0" Get = "/products/ean/" + eanum + "/standard." + "xml"
    req = urllib2.Request(url + Get,headers=headers)
    response = urllib2.urlopen(req)
    itscope = response.read()
    xmlread = libxml2.parseDoc(itscope)
    # Antwort-XML Feld auswahl
    eancode = xmlread.xpathEval('/products/product/ean')
    prodname = xmlread.xpathEval('/products/product/supplierItems/supplierItem/productName')
    manuf = xmlread.xpathEval('/products/product/supplierItems/supplierItem/manufacturerName ')
    description = xmlread.xpathEval('/products/product/longDescription')
    pricelist = xmlread.xpathEval('/products/product/price')
#########################################################################
#Die Infos zum Produkt in die Datenbank eintragen #
#########################################################################
    product_colum={ 'barcode': eancode[0].content, 'name' : prodname[0].content, 'list_price' : pricelist[0].content, 'manufacture': manuf[0].content, 'description_sale' : description[0].content }
    prodimport = sock.execute(dbname,login,pwd,product,'create',product_colum)
    print "Produkt wurde erfolgreich eingetragen"
product_search()

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/1/16, 3:47 AM
Seen: 71 times
Last updated: 12/1/16, 3:50 AM