Welcome to BACON:CONSULT‎ > ‎Services‎ > ‎odoo‎ > ‎OpenERP Developments‎ > ‎

xwPython

You can easily create interesting remote xwPython applications that interface to OpenERP using xwPython. This allows you to build your own client application. 

Here is an example that extracts the Bill of Materials (BOM) list. 

To get this demo working you'll need to install the manufacturing module into your OpenERP demo solution. Ensure to have the demo data loaded too so you can see the list of BOM and child boms. 


xwPython Example

# -*- coding: cp1252 -*-
import wx
import xmlrpclib

#sock = xmlrpclib.ServerProxy('http://<your server IP address:8069/xmlrpc/object')

uid = 1  #The first user is 'admin' with uid of 1 
pwd = 'admin' #default admin password on demo installations
dbname= '<your database name>'

text = []
child1 = []


class BOM_List_Frame(wx.Frame):
    def __init__(self, parent, id ):
       # ------------------------------------------------------------------
       # Reset all constants
       # ------------------------------------------------------------------

        y=50
        y2=0
        i=0
        childs=0

        
        wx.Frame.__init__(self, parent, -1,   title='BOM Report', size=(800,1000))
        panel = wx.Panel(self)
        panel.SetBackgroundColour("white")

        
        scroll = wx.ScrolledWindow(panel, -1)
        #scroll.SetScrollbars(1, 1, 600, 400)
        #self.button = wx.Button(self.scroll, -1, "Scroll Me", pos=(50, 20))
        #self.Bind(wx.EVT_BUTTON,  self.OnClickTop, self.button)
        #self.button2 = wx.Button(self.scroll, -1, "Scroll Back", pos=(500, 350))
        #self.Bind(wx.EVT_BUTTON, self.OnClickBottom, self.button2)

        
   




        status = self.CreateStatusBar()
        menubar = wx.MenuBar()
        first=wx.Menu()
        second=wx.Menu()
        first.Append (wx.NewId(),"Close", "This will close the window"  )
        first.Append (wx.NewId(),"Open...", "This will open the window"  )
        menubar.Append(first, "File")
        menubar.Append(second, "Edit")
        self.SetMenuBar(menubar)
        box=wx.MessageDialog(None,'Press OK to Continue. \n The form will then be created', 'Continue?', wx.OK)
        answer=box.ShowModal()
        box.Destroy()
        box2=wx.TextEntryDialog(None, "What product are you searching for?", "Product ID", "*")
        if box2.ShowModal()==wx.ID_OK:
            answer = box2.GetValue()
        
        

        # ------------------------------------------------------------------
        # find all products with a BOM i.e. where bom field != blank
        # ------------------------------------------------------------------
        args = [('bom_lines', '!=', '')]                                            #query clause
        ids = sock.execute(dbname, uid, pwd, 'mrp.bom', 'search', args)             #Query the mrp.bom model
        ids=sorted(ids)                                                             #sort these id's
        # ------------------------------------------------------------------
        # Print all found record ids as a summary
        # ------------------------------------------------------------------
        
        
        title=wx.StaticText(panel, -1, "Summary BOM List", (200, 0), (100, -1), wx.ALIGN_CENTER)
        title.SetBackgroundColour('blue')
        title.SetForegroundColour('white')

        # ------------------------------------------------------------------
        # Print a summary of all BOM ID's
        # ------------------------------------------------------------------

        text1='The following BOM Records have a BOM ID of = ' ,ids
        text1=str(text1)
        quote = wx.StaticText(panel, label=text1 + '\n', pos=(20, y))
        y=y+20
        ids2=[]
        
        # ------------------------------------------------------------------
        # Build a drop down menu
        # ------------------------------------------------------------------

        #bom_fields = ('name', 'product_id','bom_lines'  )
        bom_fields = ('name' ,)
        ListOfProducts2 = []
        for i in range(len(ids)):
            bom_id1 = sock.execute(dbname, uid, pwd, ('mrp.bom'), 'read', ids[i], bom_fields)
            ListOfProducts=bom_id1['name'], # this filters out the productId
            #ListOfProducts2=ListOfProducts2, ListOfProducts[1]
            print ListOfProducts      
        #ListOfProducts2 =str(ListOfProducts2 )
       
        #alist = sdf,ad,asdf
        a1 = ['Apples', 'Bananas', 'Strawberries', 'Watermelon',"Don't remember", 'None of the above']
        box3=wx.SingleChoiceDialog(None, "What product are you searching for?", "Product ID", ListOfProducts2  )
        if box3.ShowModal()==wx.ID_OK:
            answer = box3.GetStringSelection()
        


        # ------------------------------------------------------------------
        # Get the details of the child for each master bom record
        # Field Product ID returns the product ID and name of the product in tht product.product table
        # Which is useful to retrieve all    details of the parent and child BOM too.
        # ------------------------------------------------------------------
        bom_fields = ('name', 'product_id','bom_lines'  )
        bom_fields2 = ('name', 'product_id','bom_lines','product_qty' )

        for i in range(len(ids)):
           
            text2 = '-----------------------------------------------------------------------------'
            self.quote = wx.StaticText(panel, label= text2 + '\n', pos=(20, y))
            y=y+20 

            bom_id1 = sock.execute(dbname, uid, pwd, ('mrp.bom'), 'read', ids[i], bom_fields) 

            bom_id = str(bom_id1['id'])
            product_id = str(bom_id1['product_id'])
            bom_lines = str(bom_id1['bom_lines'])
          
                   
            self.quote = wx.StaticText(panel, label= 'Master BOM ID = ' + bom_id  + '\n' , pos=(20, y))
            y=y+20  
            self.quote = wx.StaticText(panel, label= 'Product ID= ' + product_id  + '\n' , pos=(20, y))
            y=y+20  
            quote = wx.StaticText(panel, label= 'BOM Lines= '+ bom_lines  + '\n' , pos=(20, y))
            y=y+20  
            text4 = []
            # ------------------------------------------------------------------
            # get childs boms and show these too
            # ------------------------------------------------------------------
            for child1 in bom_id1['bom_lines']:
                bom_child1 = sock.execute(dbname, uid, pwd, ('mrp.bom'), 'read', child1, bom_fields2)
                
                # Extract the parent BOM ID of this child to see if this also has a BOM    
                anewlist = bom_child1 ['product_id']
                text4 =  str(child1)
                text4= text4.strip()
                text5 =  str(anewlist [0])
                text5= text5.strip()
                text6 =  str(anewlist [1] )
                text6= text6.strip() 
                text7 =  str(bom_child1 ['product_qty'])
                text7= text7.strip() 
                self.quote = wx.StaticText(panel, label= '  **BOM Child ID= ' + text4.ljust(10) +  'Qty= '+ text7.ljust(10)+ 'Product_ID= ' +  text5.ljust(10) + 'Name= '  + text6.ljust(100)  + '\n', pos=(30, y))
                y=y+20 
        
        self.Show()

        def OnClickTop(self, event):
            self.scroll.Scroll(600, 400)
        
        def OnClickBottom(self, event):
            self.scroll.Scroll(1, 1)




if __name__=='__main__':
    app = wx.PySimpleApp()
    frame= BOM_List_Frame (parent=None, id=-1)
    frame.Show()
    app.MainLoop()

Subpages (1): xwPython and OpenERP
ċ
OpenERP wx Python Example - Creation of a Bom List_v1c
(7k)
Colin Bacon,
Oct 4, 2012, 8:54 AM
Comments