Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
10528 Weergaven

I'm trying to run a scheduled task on Odoo v8. The task is started correctly without any problem, but the cron method is called using the legacy API.


That means I need to always pass the cr, uid, context vars when calling a method. It also means I don't have access to certains var such as self.env, self,._ds, ...


How does someone create a scheduled task and call it with the new API (v8)?


Here is the cron record

<record id="ir_cron_generate_periodic_invoices" model="ir.cron">
<field name="name">Generate Periodic Invoices from Contract</field>
<field eval="True" name="active"/>
<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 name="doall" eval="False"/>
<field name="model">account.analytic.account</field>
<field name="function">_cron_periodic_create_invoice</field>
<field name="args">()</field>
</record>

And here is the object

class account_analytic_account(models.Model):
_inherit = "account.analytic.account"

def _cron_periodic_create_invoice(self,cr, uid, context=None):
self._periodic_create_invoice()

def _periodic_create_invoice(self):
# Do something here ...
Avatar
Annuleer
Beste antwoord

Hi,

You may try like this:

class account_analytic_account(models.Model):
_inherit = "account.analytic.account"

@api.model
def _cron_periodic_create_invoice(self):
self._periodic_create_invoice()

@api.multi
def _periodic_create_invoice(self):
# Do something here ...

Hope this helps

Avatar
Annuleer

using @api.model works

Beste antwoord

For me below code is working

@api.model

def _cron_periodic_create_invoice(self):

self.search([])._periodic_create_invoice()

@api.multi

def _periodic_create_invoice()

Best Thanks,

Ankit H  Gandhi.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
jan. 20
15665
2
apr. 24
24358
0
mrt. 15
2989
1
feb. 18
10820
0
jun. 16
4148