abort_event.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 AbortEvent(models.Model):
  8. _name = 'farm.abort.event'
  9. _inherit = {'farm.event.import.mixin': 'ImportedEventMixin_id'}
  10. _auto = True
  11. female_cycle = fields.Many2one(
  12. comodel_name='farm.animal.female_cycle', string='Female Cycle')
  13. @api.one
  14. def confirm(self):
  15. if not self.is_compatible():
  16. raise Warning(
  17. _("Only females can abort"))
  18. if not self.is_ready():
  19. raise Warning(
  20. _("Only pregnat females can abort"))
  21. self.female_cycle = self.animal.current_cycle
  22. self.animal.update_state()
  23. self.animal.current_cycle.update_state(self)
  24. super(AbortEvent, self).confirm()
  25. def is_compatible(self):
  26. if self.animal_type == 'female':
  27. return True
  28. else:
  29. return False
  30. def is_ready(self):
  31. if self.animal.current_cycle.state == 'pregnat':
  32. return True
  33. else:
  34. return False