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

debugging python code

By
Anuradha
on 8/17/13, 2:41 AM 3,119 views
I have been trying different debugging methods but everything fails.How can i print a variable or msg in log.

i am using tail -f /var/log/openerp/openerp-server.log& for log

my code is 
import logging
from openerp.osv import fields, osv
import time
print "a"*1000

_logger = logging.getLogger(__name__)
class calldata_print_report_wiz(osv.osv_memory):
    _name = "calldata.print.report.wiz"

    def _sel_func(self, cr, uid,context=None):

     print "hello"*100
     obj = self.pool.get('calldata1')
     ids = obj.search(cr, uid, [])
     res = obj.read(cr, uid, ids, ['Caller'], context)
     _logger.debug('Create a %s with vals %s', self._name, res)
     res =[r['Caller'] for r in res]
     return res

    _columns = {
        'date_start': fields.date('Date Start', required=True),
        'date_end': fields.date('Date End', required=True),
#        'Callers':fields.many2one(
 #       'calldata1',

  #   'Callers',
   #     selection=_sel_func
    #    )
       'caller_id':fields.selection(_sel_func, string='Caller'),
   }
    _defaults = {
        'date_start': lambda *a: time.strftime('%Y-%m-%d'),
        'date_end': lambda *a: time.strftime('%Y-%m-%d'),


     }

    def print_report(self, cr, uid, ids, context=None):
      import pdb
      pdb.set_trace()
       import netsvc
       netsvc.Logger().notifyChannel('calldetails1', netsvc.LOG_DEBUG, "Hello")

      if context is None:
            context = {}

      datas = {'ids': context.get('active_ids', [])}
      res = self.read(cr, uid, ids, ['date_start', 'date_end', 'Caller_id'], context=context)
      res = res and res[0] or {}
      datas['form'] = res
      return {
            'type': 'ir.actions.report.xml',
            'report_name':'call',
           }
calldata_print_report_wiz()

Any one please help?

0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2060
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 8/17/13, 6:16 PM

Put the _logging declaration inside the function you want to log and start/stop the server. That will make the log messages start to appear

Also start the server in debug mode or change the logging from .debug to .info

Yes finally it worked thanks alot patently.

Anuradha
on 8/19/13, 1:40 AM
0
nazarii
On 8/17/13, 6:59 AM

There could be several reasons:

  1. Have you restarted the server to apply new print statements?
  2. Be sure you are reading correct log file(perhaps you specified another one when started the server adding -c or config?). If you see current time reading your log the file you are reading is correct.
  3. Why are you launching reading the file as background process? You don't need '&' at the end of command.
  4. Go to Settings --> Configuration --> Database structure --> Objects and check whether there is such a model calldata.print.report.wiz in your database, if not - you forgot to include you file in __init_ section of module. Besides there is no reason to use pdb module in you code as it wouldn't work while you are only reading the file. Cheers.

yes i restarted the server. i restarted server using this command sudo /etc/init.d/openerp restart --debug .there exists calldata.print.report.wiz table in my database.Still why its not showing my print statement result :( ? my configuration file for open erp is /etc/openerp/openerp-server.conf
[options] ; This is the password that allows database operations: ; admin_passwd = admin db_host = False db_port = False db_user = openerp db_password = False

Anuradha
on 8/17/13, 8:14 AM

Append following line to conf file: logfile = /var/log/openerp/openerp-server.log and restart the server.

nazarii
on 8/17/13, 8:37 AM

changed configuration and restarted . still no change :(.

Anuradha
on 8/17/13, 8:48 AM

Hm, is there any output in console after running tail -f /var/log/openerp/openerp-server.log and accessing server throw web browser?

nazarii
on 8/17/13, 8:57 AM

yes it shows errors if any,login info etc

Anuradha
on 8/17/13, 8:58 AM

Ok, let's try the last thing - insert in your code next method: def init(self, cr): print "Hello World"*100 and restart the server. If it will not print - your module is not updating, otherwise try to use 'caller_id' as functional field, not selection.

nazarii
on 8/17/13, 9:22 AM

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

0 follower(s)

Stats

Asked: 8/17/13, 2:41 AM
Seen: 3119 times
Last updated: 3/16/15, 8:10 AM