I am extending a module to allow an openerp scheduler to call a method automatically once a day.
The module I extend is account_followup
, which allows to send mails in order to remind overdue payments to customers.
The action of sending reminder emails in the native module is done by clicking on a button in a wizard.
My extension is creating a cron job that calls the method which is called when the user click on the wizard button.
Here are the technicals details of my cron job:
object
:account_followup.print
(there is a table in DB corresponding to this model)method
:do_process
arguments
:[[1]]
(this value is part of my problem we'll see below why)
And below is the the begining of the do_process
method :
def do_process(self, cr, uid, ids, context=None):
if context is None:
context = {} # this is the case when call from cron job
#Get partners
tmp = self._get_partners_followp(cr, uid, ids, context=context)
The local scope variables change depending on the origin the method is called from :
Called from the cron job,
context
is empty, andids
variable is equal toarguments
field.Called by the user clicking on the button,
context
contains usual informations (lang
,tz
,uid
) andids
which is the record just newly created in DB tableaccount_followup_print
. Thisids
is then used by the method_get_partners_followp
which fetch the record newly created in tableaccount_followup_print
thanks toids
.
My problem is that I don't understand in case 2, how the record is created whilst the method do_process
is called directly from the click event (see below the xml view code).
<button name="do_process" string="Send emails and generate letters" type="object" class="oe_highlight"/>
My cron job call the same do_process
method but an error is thrown cause no record matches with "static" id from the field arguments
:
2014-03-14 11:37:40,654 31224 ERROR openerp_dev openerp.addons.base.ir.ir_cron: Call of self.pool.get('account_followup.print').do_process(cr, uid, *([1],)) failed in Job 15
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20140210_002654-py2.7.egg/openerp/addons/base/ir/ir_cron.py", line 136, in _callback
method(cr, uid, *args)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20140210_002654-py2.7.egg/openerp/addons/cap_account_followup/wizard/account_followup_print.py", line 231, in do_process
tmp = self._get_partners_followp(cr, uid, ids, context=context)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20140210_002654-py2.7.egg/openerp/addons/cap_account_followup/wizard/account_followup_print.py", line 306, in _get_partners_followp
fup_id = 'followup_id' in context and context['followup_id'] or data.followup_id.id
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20140210_002654-py2.7.egg/openerp/osv/orm.py", line 499, in __getattr__
raise AttributeError(e)
AttributeError: 'Field followup_id not found in browse_record(account_followup.print, 1)'
And finally, I can show as well the call stack that are different between case 1 and case 2 :
1.
addons/base/ir/ir_cron.py", line 136, in _callback
method(cr, uid, *args)
addons/cap_account_followup/wizard/account_followup_print.py", line 229, in do_process
2.
addons/web/session.py", line 89, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
osv/osv.py", line 190, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
osv/osv.py", line 132, in wrapper
return f(self, dbname, *args, **kwargs)
osv/osv.py", line 199, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
osv/osv.py", line 187, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
addons/cap_account_followup/wizard/account_followup_print.py", line 229, in do_process
I d'ont know if my problem is cleary exposed, let me know if it is blurry.
Thank you for your help
Cheers