I have py script
# -*- coding: utf-8 -*-
from openerp import models, fields, api
from datetime import datetime, date
from openerp.tools.translate import _
class AddPriority(models.Model):
_name = 'account.invoice.priority'
_description = "Descriptions for new priority"
name = fields.Char('Name', size = 26, required=True, help='Name for new priority')
descript = fields.Text( 'Description', help='Descriptions for new priority')
class My_invoices(models.Model):
_inherit = 'account.invoice'
priority = fields.Many2one('account.invoice.priority', string='Priority', required=True, help='Select Priority', store=True)
delay = fields.Integer(string = 'Delay', readonly = True, help = 'Day Delay', compute='_delay', store=True )
@api.multi
@api.depends('date_due','delay')
def _delay(self):
if self.date_due != False:
day_delay = datetime.strptime(self.date_due, '%Y-%m-%d').date()
day_now = date.today()
day = str(day_delay - day_now)
day = day.replace('0:00:00','')
if 'day' in day:
day = day.replace(' day, ','')
if 'days'in day:
day = day.replace(' days, ','')
if day =='':
day = 0
else:
day = int(day)
self.delay = day
def my_up(self, cr, uid, context= None):
scheduler_line_obj = self.pool.get('account.invoice')
scheduler_line_ids = self.pool.get('account.invoice').search(cr, uid, [])
for scheduler_line_id in scheduler_line_ids :
scheduler_line =scheduler_line_obj.browse(cr, uid,scheduler_line_id ,context=context)
delay = scheduler_line.delay
scheduler_line_obj.write(cr, uid, scheduler_line_id, {'delay': (delay -1)}, context=context)
and xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="update_date_action" model="ir.cron">
<field name="name">Date for invoice priority</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'My_invoices'" name="model"/>
<field eval="'my_up'" name="function"/>
</record>
</data>
</openerp>
Cron was created but dont work. Why does nothing happen? where is my mistake?