Skip to Content
Menu
This question has been flagged
1 Reply
2997 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"?>
<openerp>
<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"/>
</record>
</data>
</openerp>

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):
slots_obj=self.pool.get('golf.slots')
def dates():
start_date=datetime.date.today()
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)
l=[]
while start_time <= end_time:
l.append(start_time)
start_time+=datetime.timedelta(minutes=10)
return l
for date in dates():
_logger.info('Mark')
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!

Avatar
Discard
Best Answer

Try use @api.model instead @api.multi

Avatar
Discard
Related Posts Replies Views Activity
1
Feb 21
3098
3
Jun 20
3815
0
Jun 20
1747
0
Feb 16
2849
0
Aug 23
1829