Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3532 Lượt xem

Iam currently creating a module and can get it working as Iam finding the developer manual wording hard to follow. basically i have a class called Products.py and I have a Webcall.py class that makes a GET request to my localhost to return to a json object. the json returns fine when I test the class. but when I try to run the whole module nothing happens. I want the module to prepopulate the database of products on load of the module, with the data from the GET request. Once this is done i want this data diplayed in a simple tree view. I have checked the server log but it does flag any errors. below is my Products.py module.

from openerp.osv import osv,fields
import WebCall

class Products(osv.Model):
    _name = "products.products",
    _columns = {
        "name": fields.text("Prod Name", size=100),
        "code": fields.text("Code"),
        "sku": fields.text("SKU"),
        "description": fields.text("Description"),
        "salepricewithvat": fields.float("Sale Price + VAT"),
        "group": fields.float("Group"),
        "id": fields.text("ID"),
        "applicationid": fields.text("App ID"),



    }
    _defaults = {}


    def init(self,cr):

        webcall = WebCall("my web url goes here!!")
        webcall.makecall()

        if webcall.checkrequest():
            print "test"
        else:
            webcall.createdict()
            self.uploaddictionary(webcall.dict["Resources"])

     def uploaddictionary(self, dictionary):

        for item in dictionary:
            self.create(item)

then i have the WebCall.py class which is just a regular python class

import json import urllib2 import exceptions

class WebCall(object):


 def __init__(self,url):
    self.url = url
    self.attdictionary = {}
    self.errors=[]
    self.response =""
    self.dict=""


 def makecall(self):

    request = urllib2.Request(self.url)

    try:
        self.response = urllib2.urlopen(request,  timeout=10)
    except urllib2.HTTPError, error :
        self.errors.append(error.code)
    except urllib2.URLError, error :
        self.errors.append(error.reason)
    except IOError,  error:
        self.errors.append(error.errno)

    return self.response


 def  checkrequest(self):
    return len(self.errors) > 0


 def createdict(self):

     if self.dict  == "":
         self.dict = json.load(self.response)

     return self.dict

then I have the .xml view file. I think this is where i have the issue because I dont really understand how to use the view correctly yet.

<?xml version="1.0"?>
  <openerp>
    <data>

    <record id="products_tree" model="ir.ui.view">
    <field name = "name">products.products.treeview</field>
    <field name= "model"> products.products</field>
    <field name="arch" type="xml">
    <tree string="prods" version="7.0">
        <field name="Name"   />
        <field  name="Code" />
        <field  name="SKU" />
        <field  name="Description" />
        <field   name="Sale Price + VAT" />
        <field   name="Group" />
        <field   name="ID" />
        <field   name="Application ID" />
     </tree>
    </field>
    </record>


    <record   model="ir.actions.act_window"
       id="myaction">
        <field name="name">products.products.action</field>
        <field name="res_model">products.products</field>
        <field name="view_type">tree</field>
        <field name="view_mode">form,tree</field>

    </record>



    <menuitem id="main_item"  name="List Of Products"/>
    <menuitem id="main_item_child"   name="Products" parent="main_item"/>
    <menuitem id="main_item_option"   name="Products List" parent="main_item_child" action="myaction" />

        </data>
  </openerp>

the module just doesnt display in installed modules Ive looked a the .log file and this is what is returned in the latest log

2014-03-15 20:26:35,809 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:35] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:36,368 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:36] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:36,719 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:36] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:38,190 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:38] "POST /web/dataset/search_read HTTP/1.1" 200 - 2014-03-15 20:26:51,002 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:51] "POST /web/dataset/search_read HTTP/1.1" 200 - 2014-03-15 20:26:52,608 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:52] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:53,191 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:53] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:53,627 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:53] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:54,153 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:54] "POST /web/dataset/call_kw HTTP/1.1" 200 - 2014-03-15 20:26:55,871 2872 INFO absyla werkzeug: 127.0.0.1 - - [15/Mar/2014 20:26:55] "POST /web/dataset/search_read HTTP/1.1" 200 -

so essentially it doesnt show me that there is an error? Iam kind of lost with this so if anyone can help Id really appreciate it

Ảnh đại diện
Huỷ bỏ

What about your __init__.py and __openerp__.py files ?

Tác giả

didnt think the were as important TBH. here they are though

Tác giả

{ 'name': 'Plugin', 'version': '1.0.0', 'author': 'me', 'description': ' Plugin written in python', 'category': 'plugin', 'website': '', 'depends': ['base'], 'data': ['Products_view.xml'], 'demo':[], 'installable': True,

}
Tác giả

import Products,WebCall

Tác giả

above are the __init__.py and __openerp__.py files. honestly i dont think thats where the issue is