Search This Blog

Monday, 22 April 2013

Steps for How to create simple webkit report Demo Module in Openerp

Sample module for  webkit report on purchase Order  (OpenERP- 7.0)


Module Name :   webkit_report_purchase_order

Requrired things to implement Webkit report

 1) Download webkit to pdf library file from below link and set the system parameter.

   The file is for linux and 32 bit.
 
     Click here to Download   for Linux 32 bits.
     Click here to Download   for Linux 64 bits.

 If you have another system configuration than you can find your specific file   from below link.

http://code.google.com/p/wkhtmltopdf/downloads/list

If your file is downloaded than set the path of your file inside the system parameter for that follow this menu structure

Setting >> Technical >> Parameters >> System Parameters

Create new record inside the System parameter.

Here you will ask for two fields Key and value :

Key  : webkit_path
Value : set full  path of your downloaded lib file (wkhtmltopdf) .

File & Directory Structure inside the module :


>>webkit_report_purchase_order
     >>report
          >>__init__.py
          >>purchase_webkit.py
          >>purchase_rep_webkit.mako

     >>__init__.py
     >>__openerp__.py
     >>report_view.xml


Code and Description of each files :

1) webkit_report_purchase_order/__init__.py

 * Code :
    import report


* Descriptoin :

     Simply initalize the report direcotry.

2) webkit_report_purchase_order/__openerp__.py

  * Code :

       {
             "name": "Report Webkit 7",
             "version": "1.0",
            "depends": ["purchase","report_webkit"],
            "author": "Serpent Consulting Services",
             "category": "Purchase",
            "description": """
               This module is providing webkit report for purchase order
             """,
              'update_xml': ["report_view.xml"],
              'installable': True,
              'application':True,
              'auto_install':False,
     }

   * Descriptoin :

      The openep is the Main cofig. file in module if you are not defining openerp file you will not able to see your module while you updating module list.

Inside the dependency you must give the dependancy of atleast two  modules

    i) report_webkit :
       which is the core module for webkit report . you must give the dependency of this module.

   ii) purchase:

      The module name , which contain model on which you are going to generating report .

      Here i have used purchase.order model , which defined inside the purchase module. like wise on whatever model you are going to create report you must give that module name.

  
3)  webkit_report_purchase_order/report_view.xml

  * Code :


        <?xml version="1.0" encoding="UTF-8"?>

        <openerp>
   
                 <data>
                         <record id="purchase_rep_webk_head" model="ir.header_webkit">
                           <field name="footer_html"><![CDATA[
            <html>
                <body>
                    <center>Serpent Consuting Services</center>
                </body>
            </html>]]>
            </field>
            <field name="orientation">Portrait</field>
            <field name="format">A4</field>
            <field name="html"><![CDATA[
                <html>

                    <body style="border:0; margin:15;" onload="subst()">
                        <table class="header" style="border-bottom: 0px solid black; width: 100%">
                            <tr>
                                <td style="text-align:left; font-size:15px; font-weight: bold;"><span style="text-transform:uppercase; font-size:12px;">Heading 1</td>
                            </tr>
                            <tr>
                                <td style="text-align:left; font-size:12px; font-weight: bold;"><span style="text-transform:uppercase; font-size:12px;">Heading 2</td>
                            </tr>
                        </table> ${_debug or ''|n} </body>
                </html>]]>
                </field>
                <field eval="20" name="margin_top"/>
                <field eval="10" name="margin_bottom"/>
                <field name="css"><![CDATA[
   
                    body {
                        font-family:Arial;
                        font-size:12;
                    }
                   
                    .cell{
                        border-spacing: 0;
                        border-collapse: collapse;
                        border-style:solid;
                        border: 1px solid grey;
                        font-size:10px;
                        text-align:center;
                    }
                ]]>
                          </field>
                          <field name="name">Purchase Webkit Header</field>
                      </record>
              </data>

             <data>
                      <report auto="False"
                        id="purchase_rep_webkit_view_id"
                        model="purchase.order"
                        name="purchase.rep.webkit"
                        file="report_webkit_7/report/purchase_rep_webkit.mako"
                        string="Purchase Extended Webkit"
                        report_type="webkit"
                       webkit_header ="purchase_rep_webk_head" />
            </data>

        </openerp>


 *  Description : 

    This xml file contain the xml id for the report and Header record.

    Inside the header record you can define you Custom Header & Footer
   Css and All the configuration of your Report Page.

4) webkit_report_purchase_order/report/__init__.py

  * Code :

  import purchase_webkit

 * Description :

  This init file initalize the your parser class file.

5) webkit_report_purchase_order/report/purchase_rep_webkit.mako

Code :

`<html>
<head>
<style>
${css}
</style>
</head>

<body>
           %for obj in objects:

<table width="100%" border="0" class="cell_extended">
            <tr class ="table_parent_data">
               <td width="5%" align="center" >
                   <small>Description</small>
               </td>
               <td width="5%" align="left" class="head_bottom_border">
                   <small>Taxes</small>  
               </td>
               <td width="40%" align="center" >
                   <small><b> Date Req.</small>  
               </td>
               <td width="40%" align="right" >
                   <small><b>Qty</b></small>  
               </td>
               <td width="5%" align="left" class="head_bottom_border">
                   <small>Unit Price</small>  
               </td>
               <td width="5%" align="center">
                   <small>Net Price</small>  
               </td>
       </tr>
                  %for line in obj.order_line:
                   <tr class ="table_parent_data">
                <td width="5%" align="center" >
                    ${ line.name or ''}
                </td>
                <td width="5%" align="left" class="head_bottom_border">
                    ${ ', '.join(map(lambda x: x.name, line.taxes_id)) }  
                </td>
                <td width="40%" align="center" >
                    ${ formatLang( line.date_planned, date=True) }
                </td>
                <td width="40%" align="right" >
                    ${ formatLang(line.product_qty )  line.product_uom.name }  
                </td>
                <td width="5%" align="left" class="head_bottom_border">
                    ${formatLang(line.price_unit, digits=get_digits(dp='Product Price') ) }  
                </td>
                <td width="5%" align="center">
                    ${ formatLang(line.price_subtotal, digits=get_digits(dp='Account'), currency_obj=o.pricelist_id.currency_id ) }
                </td>
        </tr>
             %endfor
         </table>
       %endfor

Description :

I just did sample code for purchase or mako file you can customize by your own. this is the sample how you can code in mako template file.
You can easily write your python code in mako template file.


6)  webkit_report_purchase_order/report/purchase_webkit.py

Code :

      from openerp.report import report_sxw

      class purchase_webkit_report(report_sxw.rml_parse):
            def __init__(self, cr, uid, name, context):
       
        super(purchase_webkit_report, self).__init__(cr, uid, name, context=context)

        report_sxw.report_sxw('report.purchase.rep.webkit','purchase.order','addons/webkit_report_purchase_order/report/purchase_rep_webkit.mako',parser=purchase_webkit_report) 

* Descriptoin :


Note :  This file is not necessary but whenever you want to use your own user define method on the report you can define inside this parser class file.



If you have any query or doubt you can ask me on comment.

Monday, 4 March 2013

Dictionary Sort by Key in Python

You can easily  sort your dictionary by using collections class in python
Either your key is string or integer, you can sort it.


E.g : Sort Dictionary by key (key in string format)

import collections

dict_data = {'a': 'Anil', 'p': 'pinal', 'c': 'chintan', 'z': 'zinal', 'b': 'Bonil','A':'Atul','h':'Haridk','d':'Dhanvit'}

sorted_dict = collections.OrderedDict(sorted(dict_data.items()))

print "Sorted Dict :::",sorted_dict

O/p : Sorted Dict::: OrderedDict([('A', 'Atul'), ('a', 'Anil'), ('b', 'Bonil'), ('c', 'chintan'), ('d', 'Dhanvit'), ('h', 'Haridk'), ('p', 'pinal'), ('z', 'zinal')])

Returns list of tuples

Same way you can sort your dictionary having integer key.

 dict_data = {2:3, 1:89, 4:5, 3:0}
 
 sorted_dict = collections.OrderedDict(sorted(dict_data.items()))
 
 print "Sorted Dict :::",sorted_dict 

Thursday, 28 February 2013

Convert Jalali Date to Gregorian and Gregorian to Jalali Using Python

You are required to download the jdatetime library

you can download from here

Download jdatetime library from here

Click Here Download



Install this library in your system :.

Extract the library folder and reach inside that library folder in command prompt and install .

- apt get install setup.py

Try this script :

from jdatetime import JalaliToGregorian, GregorianToJalali


gregorian_date_obj = JalaliToGregorian(1391,02,21)


gregorian_date =gregorian_date_obj.getGregorianList()

print " gregorian_date  :::::::",gregorian_date


same way you can use the ,


jalali_date_obj =  GregorianToJalali(2012,1,31)


jalali_date = jalali_date_obj.getJalaliList()


print  "jalali_date :::::::::::::",jalali_date







Thursday, 22 November 2012

ACCESSING DATA FROM SERVER USING XMLRPC [OPENERP, PYTHON]

 Simple demo.py file for accessing data from server using xml rpc.



import xmlrpclib
import base64
import csv

server = '127.0.0.1'   (server IP address)
port = '8080'             (server port Number)
username = 'username'
password = 'pwd'
dbname = 'test61'     (Database Name from which you access the data)

url = 'http://' + server + ':' + port

common = xmlrpclib.ServerProxy(url + '/xmlrpc/common')

uid = common.login(dbname, username, password)

object = xmlrpclib.ServerProxy(url + '/xmlrpc/object')

so_ids = object.execute(dbname, uid, password, 'sale.order','search',[])

print "sale order ids ::::::::",so_ids

Password contain atleast alpha,symbol & digit [Python]]

This program is check that password must contain , alpha,number & digits

   test = "anilasdfasdfl234234234@@@@"
   new = tuple(test)
   data = list(new)
   is_symb =False
   is_digit = False
   is_alpha = False

   for d in data :
      if d.isdigit():
          is_digit = True
      if d.isalpha():
          is_alpha = True
      if not d.isdigit() and not d.isalpha():
          is_symb = True
          break

  if is_symb == True and is_digit == True and is_alpha == True:
      print "password matched::::"
  else :
      print "password dosen't match..."
       

Monday, 17 September 2012

Use of 'attrs' property of field in OpenERP

Attrs property of field in OpenERP

If you want to change the access and visibility of field at run time at that time you can use 'attr' property of fields

The 'attrs' property has mainly three attributes here is the examples.

Eg.

In .py File

    class account_invoice(osv.osv)
           
            _name=''account.invoice"

            _columns = {
                                 'type':fields.selection([('retail','Retail'),('tax','Tax'),('labour',Labour)],"Invoice Type"),
                                  'frieght':field.float('Frieght'),
             }
    account_invoice()

In .xml File


<field name="frieght" attrs="{"invisible":'['|'('type','=','retail')]}"/>
- The field will be invisible if type equal to retail.

<field name="frieght" attrs="{"readonly":'['|'('type','=','tax')]}"/>
- The field will be readonly if type equal tax

<field name="frieght" attrs="{"required":'['|'('type','=','retail')]}"/>
-The field will become required if type equal labour.




Sunday, 16 September 2012

Using 'Child_of' operator In 'Parent-Child Relationship In Search view of Openerp module

If You Want to Search the All child Record Related to that text which had Written on Search Box..

follow the Following Step..

1)  That module must have a parent field in that form view When ever you crating Record for Any objects..

for eg.

If you want to search all semester which are belong /child to that semester which you had wrote in search menu..


module

class standard_standard(osv.osv)

name = 'standard.standard'

columns = {
                  'name':fields('sem',char=64),
                  parent_id.fields.many2one('standard.standard',"Parent Semester"),
}

standard_standard()




You have used that moudle as semster in you student profile

standard_id =fields.many2one ('standard.standard',Semester)



Now only one thing you have to set on you search view

<field name="standard_id" operator="child_of" />

Thats It.

Now you can easily get  you all record belong to that parent which had selected at creation of record.

Thank you