Exception = 'purchase.order' object has no attribute 'dbname'
Hi
i met this error message when i import a module to openerp
Exception = 'purchase.order' object has no attribute 'dbname'
can anyone help me solve this problems?
and what is 'dbname' actually?
Thanks OpenERP Community.
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- John Chen
- Solved:
- Last query:
- Last reply:
Revision history for this message
|
#1 |
Le 05/08/2011 09:16, John Chen a écrit :
> New question #167016 on OpenERP Web Client:
> https:/
>
> Hi
>
> i met this error message when i import a module to openerp
>
> Exception = 'purchase.order' object has no attribute 'dbname'
>
> can anyone help me solve this problems?
>
> and what is 'dbname' actually?
>
> Thanks OpenERP Community.
>
>
Which module you tried to install ?
--
Quentin THEURET
Revision history for this message
|
#2 |
i create a new module for automatic emailing system, but i met this error message when i process the button in purchase order form!
This error occurred when i pressed the approve button in purchase order.
i would like to create a button in purchase order, so when we finished approved the purchase order it will automatically send email and attached a purchase order report (.pdf) also send to the specific email address.
Thanks Quentin :D
Revision history for this message
|
#3 |
hi, this is my code :
def create_report(cr, uid, res_ids, report_name=False, file_name=False, context=None):
#if not report_name or not res_ids:
# return (False, Exception('Report name and Resources ids are required !!!'))
try:
service = netsvc.
raise osv.except_
#raise osv.except_
fp = open(ret_file_name, 'wb+');
except Exception,e:
raise osv.except_
print 'Exception in create report:',e
return (False, str(e))
return (True, ret_file_name)
When system run this function (create_report), error at line :
" service = netsvc.
i debug these line, system prompt msg : Exception = 'purchase.order' object has no attribute 'dbname'
Thanks Quentin :)
Revision history for this message
|
#4 |
Hi John,
Could be an error in a method definition. Typically, an OSV method definition looks like
method(self, cr, uid, ...)
dbname is a property of the database cursor 'cr', while 'self' refers to the osv instance which could very well be 'purchase.order'. Did you by any chance define a method with the 'self' and 'cr' arguments reverse?
Cheers,
Stefan.
Revision history for this message
|
#5 |
Hi John,
our postings have crossed but you did indeed forget the 'self' argument in the method definition.
Cheers,
Stefan.
Revision history for this message
|
#6 |
Le 05/08/2011 09:51, John Chen a écrit :
> Question #167016 on OpenERP Web Client changed:
> https:/
>
> Status: Answered => Open
>
> John Chen is still having a problem:
> i create a new module for automatic emailing system, but i met this
> error message when i process the button in purchase order form!
>
> This error occurred when i pressed the approve button in purchase order.
>
> i would like to create a button in purchase order, so when we finished
> approved the purchase order it will automatically send email and
> attached a purchase order report (.pdf) also send to the specific email
> address.
>
> Thanks Quentin :D
>
Try to define your method like this : def create_report(self, cr, uid,
res_ids, report_name=False, file_name=False, context=None)
As Stephan explain, the system try to call an attribute dbname on an osv
instance not on the database cursor, so if you change the definition of
your method and add 'self' before 'cr' the problem should be fixed.
--
Quentin THEURET
Revision history for this message
|
#7 |
Hi Stefan,
could you help me check is there any error method definition in the upper code?
Thanks Stefan
Revision history for this message
|
#8 |
My Source Code :
def wkf_confirm_
todo = []
for po in self.browse(cr, uid, ids, context=context):
if not po.order_line:
for line in po.order_line:
if line.state=
message = _("Purchase order '%s' is confirmed.") % (po.name,)
# current_name = self.name_get(cr, uid, ids)[0][1]
for id in ids:
return True
def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
#if not report_name or not res_ids:
# return (False, Exception('Report name and Resources ids are required !!!'))
try:
service = netsvc.
raise osv.except_
#raise osv.except_
fp = open(ret_file_name, 'wb+');
except Exception,e:
raise osv.except_
print 'Exception in create report:',e
return (False, str(e))
return (True, ret_file_name)
def _send_mails(self, cr, uid, ids, context):
import re
p = pooler.
user = p.get('
file_name = user.company_
# Create report to send as file attachments
report = self.create_
attach = report[0] and [report[1]] or []
username = "<email address hidden>"
passwd = "testing"
to = ['<email address hidden>']
cc = ['<email address hidden>']
msg = MIMEMultipart()
msg['From'] = username
msg['To'] = ', '.join(to)
msg['Cc'] = ', '.join(cc)
#part = MIMEBase(
server = smtplib.
#(cr, uid, smtpserver_id, email, data['form'
return True
Flows = wkf_confirm_order -> _send_emails -> create_report
Hi Stefan and Quentin
Could you help me on which part of the upper code should be adding a self?
I tried adding it but it still prompt an error message about dbname.
Thanks
Revision history for this message
|
#9 |
Le 05/08/2011 10:41, John Chen a écrit :
> Question #167016 on OpenERP Web Client changed:
> https:/
>
> John Chen gave more information on the question:
> My Source Code :
>
> def wkf_confirm_
> todo = []
> for po in self.browse(cr, uid, ids, context=context):
> if not po.order_line:
> raise osv.except_
> for line in po.order_line:
> if line.state=
> todo.append(
> message = _("Purchase order '%s' is confirmed.") % (po.name,)
> self.log(cr, uid, po.id, message)
> # current_name = self.name_get(cr, uid, ids)[0][1]
> self.pool.
>
> for id in ids:
> self.write(cr, uid, [id], {'state' : 'confirmed', 'validator' : uid})
> self._send_
> return True
>
> def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
> #if not report_name or not res_ids:
> # return (False, Exception('Report name and Resources ids are required !!!'))
> try:
> ret_file_name = '/tmp/EMPTY_
> service = netsvc.
> (result, format) = service.create(cr, uid, res_ids, {'model': 'purchase.order'}, context)
> raise osv.except_
> #(result, format) = service.create(cr, uid, res_ids, {'model': 'purchase.order'}, {})
> #raise osv.except_
> fp = open(ret_file_name, 'wb+');
> fp.write(result);
> fp.close();
> except Exception,e:
> raise osv.except_
> print 'Exception in create report:',e
> return (False, str(e))
> return (True, ret_file_name)
>
> def _send_mails(self, cr, uid, ids, context):
> import re
> p = pooler.
> user = p.get('
> file_name = user.company_
> # Create report to send as file attachments
> report = self.create_
> attach = report[0] and [report[1]] or []
>
> username = "<email address hidden>"
> passwd = "testing"
> to = ['<email address hidden>']
> cc = ['<email address hidden>']
> msg = MIMEMultipart()
> msg['From'] = username
> msg['To'] = ', '.join(to)
> msg['Cc'] = ', '.join(cc)
> msg['Subject'] = "test"
> msg.attach(
> #part = MIMEBase(
> #part.set_
> #Encoders.
> #part.add_
> #'attachment; filename="%s"' % os.path.
> #msg.attach(part)
> server = smtplib.
> server.ehlo()
> server.starttls()
> server.ehlo()
> server.
> #(cr, uid, smtpserver_id, email, data['form'
> server.
> server.close()
> return True
>
> Flows = wkf_confirm_order -> _send_emails -> create_report
>
> Hi Stefan and Quentin
> Could you help me on which part of the upper code should be adding a self?
>
> I tried adding it but it still prompt an error message about dbname.
>
> Thanks
>
In which line the server crashes ?
--
Quentin THEURET
Revision history for this message
|
#10 |
When system run this function (create_report), error at line :
" service = netsvc.
Thanks
Revision history for this message
|
#11 |
Le 05/08/2011 10:41, John Chen a écrit :
> Question #167016 on OpenERP Web Client changed:
> https:/
>
> John Chen gave more information on the question:
> My Source Code :
>
> def wkf_confirm_
> todo = []
> for po in self.browse(cr, uid, ids, context=context):
> if not po.order_line:
> raise osv.except_
> for line in po.order_line:
> if line.state=
> todo.append(
> message = _("Purchase order '%s' is confirmed.") % (po.name,)
> self.log(cr, uid, po.id, message)
> # current_name = self.name_get(cr, uid, ids)[0][1]
> self.pool.
>
> for id in ids:
> self.write(cr, uid, [id], {'state' : 'confirmed', 'validator' : uid})
> self._send_
> return True
>
> def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
> #if not report_name or not res_ids:
> # return (False, Exception('Report name and Resources ids are required !!!'))
> try:
> ret_file_name = '/tmp/EMPTY_
> service = netsvc.
> (result, format) = service.create(cr, uid, res_ids, {'model': 'purchase.order'}, context)
> raise osv.except_
> #(result, format) = service.create(cr, uid, res_ids, {'model': 'purchase.order'}, {})
> #raise osv.except_
> fp = open(ret_file_name, 'wb+');
> fp.write(result);
> fp.close();
> except Exception,e:
> raise osv.except_
> print 'Exception in create report:',e
> return (False, str(e))
> return (True, ret_file_name)
>
> def _send_mails(self, cr, uid, ids, context):
> import re
> p = pooler.
> user = p.get('
> file_name = user.company_
> # Create report to send as file attachments
> report = self.create_
> attach = report[0] and [report[1]] or []
>
> username = "<email address hidden>"
> passwd = "testing"
> to = ['<email address hidden>']
> cc = ['<email address hidden>']
> msg = MIMEMultipart()
> msg['From'] = username
> msg['To'] = ', '.join(to)
> msg['Cc'] = ', '.join(cc)
> msg['Subject'] = "test"
> msg.attach(
> #part = MIMEBase(
> #part.set_
> #Encoders.
> #part.add_
> #'attachment; filename="%s"' % os.path.
> #msg.attach(part)
> server = smtplib.
> server.ehlo()
> server.starttls()
> server.ehlo()
> server.
> #(cr, uid, smtpserver_id, email, data['form'
> server.
> server.close()
> return True
>
> Flows = wkf_confirm_order -> _send_emails -> create_report
>
> Hi Stefan and Quentin
> Could you help me on which part of the upper code should be adding a self?
>
> I tried adding it but it still prompt an error message about dbname.
>
> Thanks
>
self._send_
--
Quentin THEURET
Revision history for this message
|
#12 |
Le 05/08/2011 10:41, John Chen a écrit :
> Question #167016 on OpenERP Web Client changed:
> https:/
>
> John Chen gave more information on the question:
> My Source Code :
>
> def wkf_confirm_
> todo = []
> for po in self.browse(cr, uid, ids, context=context):
> if not po.order_line:
> raise osv.except_
> for line in po.order_line:
> if line.state=
> todo.append(
> message = _("Purchase order '%s' is confirmed.") % (po.name,)
> self.log(cr, uid, po.id, message)
> # current_name = self.name_get(cr, uid, ids)[0][1]
> self.pool.
>
> for id in ids:
> self.write(cr, uid, [id], {'state' : 'confirmed', 'validator' : uid})
> self._send_
> return True
>
> def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
> #if not report_name or not res_ids:
> # return (False, Exception('Report name and Resources ids are required !!!'))
> try:
> ret_file_name = '/tmp/EMPTY_
> service = netsvc.
> (result, format) = service.create(cr, uid, res_ids, {'model': 'purchase.order'}, context)
> raise osv.except_
> #(result, format) = service.create(cr, uid, res_ids, {'model': 'purchase.order'}, {})
> #raise osv.except_
> fp = open(ret_file_name, 'wb+');
> fp.write(result);
> fp.close();
> except Exception,e:
> raise osv.except_
> print 'Exception in create report:',e
> return (False, str(e))
> return (True, ret_file_name)
>
> def _send_mails(self, cr, uid, ids, context):
> import re
> p = pooler.
> user = p.get('
> file_name = user.company_
> # Create report to send as file attachments
> report = self.create_
> attach = report[0] and [report[1]] or []
>
> username = "<email address hidden>"
> passwd = "testing"
> to = ['<email address hidden>']
> cc = ['<email address hidden>']
> msg = MIMEMultipart()
> msg['From'] = username
> msg['To'] = ', '.join(to)
> msg['Cc'] = ', '.join(cc)
> msg['Subject'] = "test"
> msg.attach(
> #part = MIMEBase(
> #part.set_
> #Encoders.
> #part.add_
> #'attachment; filename="%s"' % os.path.
> #msg.attach(part)
> server = smtplib.
> server.ehlo()
> server.starttls()
> server.ehlo()
> server.
> #(cr, uid, smtpserver_id, email, data['form'
> server.
> server.close()
> return True
>
> Flows = wkf_confirm_order -> _send_emails -> create_report
>
> Hi Stefan and Quentin
> Could you help me on which part of the upper code should be adding a self?
>
> I tried adding it but it still prompt an error message about dbname.
>
> Thanks
>
self._send_
--
Quentin THEURET
Revision history for this message
|
#13 |
it prompt this error if we added self before cr
TypeError: _send_mails1() takes exactly 5 arguments (6 given)
I was editing it just now about the self in _send_mails1 and forgot to delete it. I guess the main problems is at create_report function
Revision history for this message
|
#14 |
The self argument is in the method definition but you do not pass it explicitely:
self._send_
Revision history for this message
|
#15 |
Unrelated, but file_name and context should be named arguments in
self.
otherwise you are passing it as the report_name and the file_name respectively, given
def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None)
Revision history for this message
|
#16 |
i don't quite get it. Could u give me an example which part and what changes should i apply
Thanks for your time Stefan.
Revision history for this message
|
#17 |
Hi John,
to help you solve the problem, I should point you to a couple of links I have found concerning these aspects of the Python programming language.
For a better notion of what 'self' is and how it should be used, have a look at this section of the classes tutorial. Reading the other parts would not hurt either of course but this section expands on my comment #14.
http://
Also, have a look at this overview of optional arguments and then compare your call to create_report to the definition of this method:
http://
Cheers,
Stefan.