Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3403 Widoki

HI friends, I tried to create a mail alert through cron function, when there is no timesheet(hr.analytic.timesheet) entries not entered by last 2 days means.Here i posted my code that didnt worked,

from openerp.osv import osv, fields
class timesheet_mail_cron(osv.osv):
_name='timesheet.mail.cron'
_description = "Cron for Timesheet"

def _cron_mail_timesheet(self, cr, uid, ids, context=None):
       today = fields.Date.from_string(fields.Date.today())
        timesheet_search = self.pool.get('hr.analytic.timesheet').search(cr, uid,[('date','<=', today )])
        print "timesheet search",timesheet_search
        timesheet = self.pool.get('hr.analytic.timesheet').browse(cr, uid, timesheet_search[0])
        print "timesheet",timesheet
        days = today - timesheet.date[0]
        print "days",days
       if days >= 2:
           template = self.pool.get('ir.model.data').get_object('asia_mail_alert_timesheet', 'email_timesheet_alert')
           template.send_mail(timesheet.id,force_send=True)
       return True

It throws error like -> TpeError: _cron_mail_timesheet() takes at least 4 arguments (3 given)

So plese anyone help me to resolve this issues.Thanks in advance

Awatar
Odrzuć
Najlepsza odpowiedź

Hi @vadivel

Cron functions doesn't get called with ids as arguments, if you wanna receive ids you need to pass it as args in the cron definition or maybe you use the function in others places, so you have two choices:

1- remove the ids argument

2- give ids argument a default value

Awatar
Odrzuć
Najlepsza odpowiedź

Dear vadivel,

@ Axel is right

You have two option for ids

First : Remove the ids

Second: Set the ids=None

like

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

or

def _cron_mail_timesheet(self, cr, uid, ids=None, context=None):

Thanks & Regards,

Ankit H Gandhi.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
mar 15
6171
1
gru 24
4081
0
lis 24
1669
2
lip 24
3410
0
kwi 24
2199