Odoo Help


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.


V9 Automated Actions wrong number of arguments

Matthew Smith
on 6/16/16, 1:39 PM 223 views

I'm new to Odoo and looking at setting up an instance with custom modules for my golf business. I also just want to learn how to develop for this system. I have to confess that learning the API has been difficult with available documentation, as I can't tell what examples are for instances pre-8.0 and what are for instances after. I'm also not sure if the method decorators are only meant to be used when configuring an old api call to the new system, or if they should be used all the time.

This is a pretty simple task that I'm trying to accomplish. I want an automated action to run every day that looks at records from a table and creates new ones. There should be a record for every time slot two weeks in advance. The first time the job is run, it would create two weeks' worth of records. Each time after that, it should only be creating records for the 14th day out. 

In golf/data/data.xml, I have:

<?xml version="1.0" encoding="UTF-8"?>
<data noupdate="1">
<record id="ir_cron_scheduler_slot_create" model="ir.cron">
<field name="name">Slot Creator</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="True" name="doall"/>
<field eval="'golf.slots'" name="model"/>
<field eval="'create_slots'" name="function"/>

In golf/models/models.py I have:

# -*- coding: utf-8 -*-
from openerp import models, fields, api
import datetime
import logging
_logger = logging.getLogger(__name__)
class Slot(models.Model):
_name = 'golf.slots'
name = fields.Char(string="Title", required=True)
slotDatetime = fields.Datetime(required=True)
status = fields.Char(string="Status", required=True)
def create_slots(self, cr, uid, content=None):
def dates():
end_date=start_date + datetime.timedelta(14)
for n in range ((end_date-start_date).days+1):
yield start_date + datetime.timedelta(n)
def times():
start_time = datetime.datetime(2016, 1, 1, 8, 00)
end_time = start_time + datetime.timedelta(hours=11)
while start_time <= end_time:
return l
for date in dates():
if slots_obj.search_count(cr, uid, [('slotDatetime', '=', date)]) == 0:
for time in self.times():
year = date.strftime('%Y')
month = date.strftime('%m')
day = date.strftime('%d')
hour = time.strftime('%H')
minute= time.strftime('%M')
nameString = date.strftime('%Y-%m-%d') + ' ' + time.strftime('%H:%M')
nameDT = datetime.datetime(year, month, day, hour, minute)
slots_obj.create(cr, uid, {'name': nameString, 'slotDatetime': nameDT, 'status': 'Open'})
_logger.info('create ' + nameString)

The module installs without error, and when I activate developer mode the Automated Action shows up in the list. When I execute it manually, nothing appears to happen (no records are created) and the log shows the following in the traceback:

2016-06-16 17:17:14,325 1104 ERROR odooTest openerp.addons.base.ir.ir_cron: Call of self.pool.get('golf.slots').create_slots(cr, uid, *()) failed in Job 6
Traceback (most recent call last):
File "/opt/odoo/openerp/addons/base/ir/ir_cron.py", line 129, in _callback
getattr(model, method_name)(cr, uid, *args)
TypeError: create_slots() takes exactly 1 argument (3 given)

I have tried changing the create_slots() method to only take (self) as an argument, I've tried preceding it with the @api.multi decorator, and I still get the same error.

I know the code is ugly right now, but at this stage it's just a proof of concept that I can get the model to execute the method properly. Any suggestions on how to get this working would be greatly appreciated, thanks!

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

1 follower(s)


Asked: 6/16/16, 1:39 PM
Seen: 223 times
Last updated: 6/16/16, 2:05 PM