# -*- coding: utf-8 -*-
from datetime import datetime

from openerp import api, fields, models, _

class TimeFrame(models.Model):
    
    _name = "time.frame"

    _order = "delivery_date, id"
        
    @api.onchange('delivery_date')
    def onchange_delivery_date(self):
        if self.delivery_date:
            self.name = datetime.strptime(self.delivery_date, "%Y-%m-%d").strftime('%A %d %B %Y')
    
    name = fields.Char(string="Order closing date")
    start = fields.Datetime(string="Start", required=True)
    end = fields.Datetime(string="End", required=True)
    delivery_date = fields.Date(string="Delivery date", required=True)
    sale_orders = fields.One2many('sale.order','time_frame_id', string="Sale orders")
    state = fields.Selection([('draft','Draft'),
                              ('validated','Validated'),
                              ('open','Open'),
                              ('cancel','Cancelled'),
                              ('closed','Closed')], default="draft",string="State")
    
    @api.one
    def action_validate(self):
        self.write({'state':'validated'})
    
    @api.one
    def action_cancel(self):
        self.write({'state':'cancel'})
    
    @api.one
    def action_open(self):
        self.write({'state':'open'})
        
    @api.one
    def action_close(self):
        self.write({'state':'closed'})

    @api.one
    def action_draft(self):
        self.write({'state':'draft'})
@@ -744,16 +744,31 @@
  orders%22
+, readonly=True
 )%0D%0A    s

put sale_orders field readonly as it has no means to be created from there