code refactoring

This commit is contained in:
eloyoussef 2018-04-16 18:04:05 +02:00
parent 7223afa486
commit b105d87745
3 changed files with 5 additions and 7 deletions

View File

@ -35,7 +35,7 @@ class GolemResourcePack(models.Model):
False : [('readonly', False)]})
note = fields.Text(help='Notes, optional subject for the reservation, reason',
track_visibility='onchange',readonly=True,
track_visibility='onchange', readonly=True,
states={'draft': [('readonly', False)],
False : [('readonly', False)]})
@ -59,6 +59,7 @@ class GolemResourcePack(models.Model):
@api.multi
@api.constrains('partner_id')
def set_reservation_partner(self):
""" Set reservation partner """
for pack in self:
pack.reservation_ids.write({'partner_id': pack.partner_id.id})
@ -114,6 +115,7 @@ class GolemResourcePack(models.Model):
@api.multi
@api.constrains('reservation_ids')
def check_reservation_partner(self):
""" Check reservation partner """
for pack in self:
if len(filter(lambda x: x.partner_id == pack.partner_id, pack.reservation_ids)) < len(pack.reservation_ids):
raise ValidationError(_('Pack client should be the same for all reservations'))

View File

@ -18,10 +18,7 @@
""" GOLEM Resource Reservation """
from math import modf
from datetime import timedelta
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo import models, fields
class GolemResourceReservation(models.Model):

View File

@ -20,7 +20,6 @@
import logging
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
_LOGGER = logging.getLogger(__name__)
@ -102,7 +101,7 @@ class TestGolemResourcePack(TransactionCase):
pack.reservation_ids[0].state_confirm()
self.assertEqual(pack.reservation_ids[0].state, "validated")
self.assertEqual(pack.state, "validated")
pack.reservation_ids=[(5,0,0)]
pack.reservation_ids = [(5, 0, 0)]
self.assertFalse(pack.reservation_ids)
self.assertEqual(pack.reservation_count, 0)