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

What was wrong in my cron creating fucntion?

By
vadivel
on 11/30/15, 5:07 AM 555 views

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

1

Axel Mendoza

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 11/30/15, 5:25 AM

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

1

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 11/30/15, 9:06 AM

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.

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

2 follower(s)

Stats

Asked: 11/30/15, 5:07 AM
Seen: 555 times
Last updated: 12/5/15, 3:01 AM