abstract_event.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. # @authors: Alexander Ezquevo <alexander@acysos.com>
  3. # Copyright (C) 2015 Acysos S.L.
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import models, fields, api
  6. EVENT_STATES = [
  7. ('draft', 'Draft'),
  8. ('validated', 'Validated'),
  9. ]
  10. class AbstractEvent(models.Model):
  11. _name = 'farm.event'
  12. _auto = False
  13. animal_type = fields.Selection([
  14. ('male', 'Male'), ('female', 'Female'),
  15. ('individual', 'Individual'), ('group', 'Group'),
  16. ], string="Animal Type", select=True)
  17. specie = fields.Many2one(comodel_name='farm.specie', string='Specie',
  18. select=True, default='get_specie')
  19. farm = fields.Many2one(comodel_name='stock.location', string='Farm',
  20. domain=[('usage', '=', 'view'), ])
  21. job_order = fields.Many2one(comodel_name='farm.event.order',
  22. string='Order')
  23. animal = fields.Many2one(comodel_name='farm.animal', string='Animal',
  24. select=True)
  25. animal_group = fields.Many2one(comodel_name='farm.animal.group',
  26. string='Group')
  27. lot = fields.Many2one(comodel_name='stock.production.lot', string='Lot',
  28. compute='get_lot')
  29. timestamp = fields.Datetime(string='Date & Time', required=True,
  30. default=fields.Datetime.now())
  31. employee = fields.Many2one(comodel_name='res.users', String='Employee',
  32. help='Employee that did the job.')
  33. notes = fields.Text(string='Notes')
  34. state = fields.Selection(string='State', selection=EVENT_STATES,
  35. default='draft')
  36. @api.one
  37. def get_lot(self):
  38. if self.animal_type == 'group':
  39. for lot in self.animal_group.lot:
  40. self.lot = lot.lot
  41. else:
  42. self.lot = self.animal.lot.lot
  43. @api.one
  44. def confirm(self):
  45. self.state = 'validated'
  46. return True
  47. @api.one
  48. @api.onchange('timestamp')
  49. def set_defaults(self):
  50. if len(self.job_order) > 0:
  51. self.specie = self.job_order.specie
  52. self.animal_type = self.job_order.animal_type
  53. self.farm = self.job_order.farm
  54. else:
  55. for animal in self.animal:
  56. self.specie = animal.specie
  57. self.animal_type = animal.type
  58. self.farm = animal.location.location_id
  59. for animal in self.animal_group:
  60. self.specie = animal.specie
  61. self.animal_type = animal.type
  62. self.farm = animal.location.location_id
  63. class ImportedEventMixin(models.Model):
  64. _name = 'farm.event.import.mixin'
  65. _inherit = {'farm.event': 'AbstractEvent_id'}
  66. imported = fields.Boolean(string='Imported', default=False)