pregnancy_diagnosis_event.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. from openerp.exceptions import Warning
  7. class PregnancyDiagnosisEvent(models.Model):
  8. _name = 'farm.pregnancy_diagnosis.event'
  9. _inherit = {'farm.event': 'AbstractEvent_id'}
  10. _auto = True
  11. result = fields.Selection([
  12. ('negative', 'Negative'), ('positive', 'Positive'),
  13. ('nonconclusive', 'Non conclusive'),
  14. ('not-pregnant', 'Observed not Pregnant'), ],
  15. string='Result',
  16. required=True, default='positive')
  17. female_cycle = fields.Many2one(comodel_name='farm.animal.female_cycle',
  18. string='Female Cycle')
  19. @api.one
  20. def confirm(self):
  21. if not self.is_compatible():
  22. raise Warning(
  23. _("Only females can be diagnosed"))
  24. if not self.is_ready():
  25. raise Warning(
  26. _("Only mated females can be diagnosed"))
  27. self.female_cycle = self.animal.current_cycle
  28. self.animal.update_state()
  29. self.animal.current_cycle.update_state(self)
  30. super(PregnancyDiagnosisEvent, self).confirm()
  31. def is_compatible(self):
  32. if self.animal_type == 'female':
  33. return True
  34. else:
  35. return False
  36. def is_ready(self):
  37. if self.animal.current_cycle.state == 'mated':
  38. return True
  39. else:
  40. return False