I´m trying to extend calendar.event as prototype inheritance. It looks like it is trying to access the relationship with wrong fields. I gess I´m making some mistake with this type of inheritance.
My code is this.
# -*- coding: utf-8 -*-
'''
Created on 17 de dic. de 2015
@author: seba
'''
from openerp import models, fields, api
from openerp.exceptions import ValidationError
from datetime import date
import logging
_logger = logging.getLogger(__name__)
class turns_turn(models.Model):
_name = 'turns.turn'
_inherit = 'calendar.event'
court = fields.Many2one("turns.court","Cancha",required="True",help="La chancha que se vaya a ocupar en este turno")
cash_advance = fields.Float("Seña",required="True",default=0,help="Seña para reserva de cancha")
client = fields.Many2one("turns.client",string="Cliente",required = "True",help="El cliente al cual se le asigna el turno")
total_cost = fields.Float("Costo total",readonly=True,help="Costo total calculado como precio de cancha unitario x duración del turno")
state = fields.Selection([("reserva","Reserva de turnos"),
("canchatomada","Cancha Tomada"),
("turnocerrado","Turno Cerrado"),
],string="Estado")
_defaults = {
'state': 'reserva',
'name': 'turno',
'start': '2016-01-19 09:00:00',
'stop': '2016-01-19 09:00:00'
}
@api.model
@api.returns('self', lambda value:value.id)
def create(self, vals):
court_selected = self.env['turns.court'].search([('id','=',vals['court'])])
vals['total_cost'] = vals['duration'] * court_selected.court_unity_price
return models.Model.create(self, vals)
def name_get(self, cr, uid, ids, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
res = []
for record in self.browse(cr, uid, ids, context=context):
name = record.client
res.append((record.id, name))
return res
def take_court(self):
self.state = "canchatomada"