car_services.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, fields, api, tools
  3. from openerp.exceptions import ValidationError
  4. class CarService(models.Model):
  5. _name = 'car.service'
  6. name=fields.Char('Nombre', compute='_get_vehicle_name', store=True)
  7. model=fields.Char('Modelo')
  8. year=fields.Integer('Año')
  9. color=fields.Char('Color')
  10. number=fields.Char('Número de chapa')
  11. logo = fields.Binary('Logo File')
  12. partner_id = fields.Many2one(
  13. 'res.partner',
  14. string='Cliente',
  15. ondelete='restrict'
  16. )
  17. description = fields.Text('Description', translate=True)
  18. policy = fields.Boolean()
  19. policy_number =fields.Char('Número de chapa')
  20. agent_id = fields.Many2one(
  21. 'res.partner',
  22. string='Agente',
  23. ondelete='restrict'
  24. )
  25. secure_id = fields.Many2one(
  26. 'res.partner',
  27. string='Aseguradora',
  28. ondelete='restrict'
  29. )
  30. odometer = fields.Float('Odometro')
  31. car_value = fields.Float('Valor del vehiculo')
  32. transmission = fields.Selection([('manual','Manual'), ('automatic','Automatico')], string="Tipo de transmision")
  33. fuel_type = fields.Selection([('gasoline','Gasolina'), ('diesel','Diesel'), ('electric','Electrico'), ('hybrid','Hibrido')], string="Tipo de combustible")
  34. seats = fields.Integer('Nro. de asientos')
  35. doors = fields.Integer('Nro. de puertas')
  36. car_brand_id = fields.Many2one(
  37. 'car.brand',
  38. string='Marca'
  39. )
  40. @api.one
  41. @api.constrains('number')
  42. def _controla_chapa(self):
  43. part_obj = self.env['car.service'].search([('number','=',self.number)])
  44. if len(part_obj) > 1:
  45. raise ValidationError('La chapa del vehículo debe ser único')
  46. @api.one
  47. @api.depends('car_brand_id','model','number')
  48. def _get_vehicle_name(self):
  49. self.name = self.car_brand_id.name + ' / ' + self.model + ' / ' + self.number
  50. class CarBrand(models.Model):
  51. _name = 'car.brand'
  52. name = fields.Char('Brand Name', required=True)
  53. description = fields.Text('Description', translate=True)
  54. logo = fields.Binary('Logo File')
  55. car_ids = fields.One2many(
  56. 'car.service',
  57. 'car_brand_id',
  58. )
  59. car_count = fields.Integer(
  60. string='Numero de autos',
  61. compute='_get_car_count',
  62. )
  63. @api.one
  64. @api.depends('car_ids')
  65. def _get_car_count(self):
  66. self.car_count = len(self.car_ids)