[IMP]GOLEM Activity Queue : usage of constrains instead of write, and few enhancements in onchange logic
This commit is contained in:
parent
b5e7a52789
commit
225ea78f4c
@ -20,7 +20,7 @@
|
|||||||
'name': 'GOLEM activity queues',
|
'name': 'GOLEM activity queues',
|
||||||
'summary': 'GOLEM activity queues',
|
'summary': 'GOLEM activity queues',
|
||||||
'description': ''' GOLEM activity queue management ''',
|
'description': ''' GOLEM activity queue management ''',
|
||||||
'version': '10.0.1.1.4',
|
'version': '10.0.1.1.5',
|
||||||
'category': 'GOLEM',
|
'category': 'GOLEM',
|
||||||
'author': 'Youssef El Ouahby, Fabien Bourgeois',
|
'author': 'Youssef El Ouahby, Fabien Bourgeois',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
@ -39,7 +39,8 @@ class GolemActivity(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
""" Override method write to delete record from queue if they register in activity"""
|
""" Override method write to delete record from queue if they register
|
||||||
|
in activity (only for manual queue processing) """
|
||||||
res = super(GolemActivity, self).write(vals)
|
res = super(GolemActivity, self).write(vals)
|
||||||
registration_vals = vals.get('activity_registration_ids')
|
registration_vals = vals.get('activity_registration_ids')
|
||||||
if registration_vals:
|
if registration_vals:
|
||||||
@ -52,10 +53,7 @@ class GolemActivity(models.Model):
|
|||||||
('member_id', '=', mem_id)]
|
('member_id', '=', mem_id)]
|
||||||
queue = self.env['golem.activity.queue'].search(domain)
|
queue = self.env['golem.activity.queue'].search(domain)
|
||||||
if queue:
|
if queue:
|
||||||
# remove registration
|
|
||||||
queue.unlink()
|
queue.unlink()
|
||||||
# self.activity_queue_ids = [(2, queue.id, False)]
|
|
||||||
self.automated_register_from_queue()
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@ -93,14 +91,16 @@ class GolemActivity(models.Model):
|
|||||||
self.env['golem.activity.registration'].create(values)
|
self.env['golem.activity.registration'].create(values)
|
||||||
queue.unlink()
|
queue.unlink()
|
||||||
|
|
||||||
@api.multi
|
@api.constrains('activity_queue_ids', 'activity_registration_ids',
|
||||||
|
'places_remain', 'queue_allowed', 'queue_activity_number',
|
||||||
|
'auto_registration_from_queue')
|
||||||
def automated_register_from_queue(self):
|
def automated_register_from_queue(self):
|
||||||
"""automated registration from queue"""
|
"""automated registration from queue"""
|
||||||
for record in self:
|
for activity in self:
|
||||||
if (record.places_remain and record.queue_allowed and
|
if (activity.places_remain and activity.queue_allowed and
|
||||||
record.queue_activity_number > 0 and
|
activity.queue_activity_number > 0 and
|
||||||
record.auto_registration_from_queue):
|
activity.auto_registration_from_queue):
|
||||||
record.register_from_queue()
|
activity.register_from_queue()
|
||||||
|
|
||||||
@api.depends('activity_queue_ids')
|
@api.depends('activity_queue_ids')
|
||||||
def _compute_queue_activity_number(self):
|
def _compute_queue_activity_number(self):
|
||||||
@ -108,12 +108,12 @@ class GolemActivity(models.Model):
|
|||||||
for activity in self:
|
for activity in self:
|
||||||
activity.queue_activity_number = len(activity.activity_queue_ids)
|
activity.queue_activity_number = len(activity.activity_queue_ids)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@api.onchange('activity_registration_ids')
|
@api.onchange('activity_registration_ids')
|
||||||
def _check_registration_number(self):
|
def _check_registration_number(self):
|
||||||
for activity in self:
|
for activity in self:
|
||||||
places_remain = activity.places - activity.places_used
|
# Needed to ensure that we are negative in places
|
||||||
if places_remain == 0 and activity.queue_allowed:
|
activity._compute_places_remain()
|
||||||
|
if activity.places_remain < 0 and activity.queue_allowed:
|
||||||
message = _('No remaining place for the activity : {}, please'
|
message = _('No remaining place for the activity : {}, please'
|
||||||
' discard changes and register in the queue.')
|
' discard changes and register in the queue.')
|
||||||
return {
|
return {
|
||||||
@ -122,7 +122,7 @@ class GolemActivity(models.Model):
|
|||||||
'message': message.format(activity.name),
|
'message': message.format(activity.name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elif places_remain > 0 and activity.queue_activity_number > 0:
|
elif activity.places_remain > 0 and activity.queue_activity_number > 0:
|
||||||
if activity.auto_registration_from_queue:
|
if activity.auto_registration_from_queue:
|
||||||
warning_message = _('There is a free place for the activity'
|
warning_message = _('There is a free place for the activity'
|
||||||
' : {}, once you save it will be filled'
|
' : {}, once you save it will be filled'
|
||||||
|
@ -55,6 +55,7 @@ class TestGolemActivityQueue(TransactionCase):
|
|||||||
""" Test activity queue bases """
|
""" Test activity queue bases """
|
||||||
member1 = self.member1.create(self.data_member_1)
|
member1 = self.member1.create(self.data_member_1)
|
||||||
activity = self.activity.create(self.data_activity)
|
activity = self.activity.create(self.data_activity)
|
||||||
|
activity.auto_registration_from_queue = False
|
||||||
activity_queue = self.activity_queue.create({'activity_id': activity.id,
|
activity_queue = self.activity_queue.create({'activity_id': activity.id,
|
||||||
'member_id': member1.id})
|
'member_id': member1.id})
|
||||||
self.assertEqual(activity.activity_queue_ids[0], activity_queue)
|
self.assertEqual(activity.activity_queue_ids[0], activity_queue)
|
||||||
|
@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
<!-- Forms -->
|
<!-- Forms -->
|
||||||
<record id="golem_activity_form_inherit_golem_activity_queue"
|
<record id="golem_activity_form_inherit_golem_activity_queue"
|
||||||
model="ir.ui.view">
|
model="ir.ui.view">
|
||||||
<field name="name">Add the queue registration items to activity form</field>
|
<field name="name">Add the queue registration items to activity form</field>
|
||||||
<field name="model">golem.activity</field>
|
<field name="model">golem.activity</field>
|
||||||
<field name="inherit_id" ref="golem_activity.golem_activity_form" />
|
<field name="inherit_id" ref="golem_activity.golem_activity_form" />
|
||||||
@ -66,11 +66,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
attrs="{'invisible': [('queue_allowed', '=', False)]}"
|
attrs="{'invisible': [('queue_allowed', '=', False)]}"
|
||||||
confirm="Are you sure you want to remove queue from this activity ? This will delete all elements currently registred in"/>
|
confirm="Are you sure you want to remove queue from this activity ? This will delete all elements currently registred in"/>
|
||||||
<button name="auto_registration_toggle"
|
<button name="auto_registration_toggle"
|
||||||
string="Automated registration from queue" type="object"
|
string="Switch to automated registration from queue" type="object"
|
||||||
attrs="{'invisible': ['|', ('queue_allowed', '=', False),'&', ('queue_allowed', '=', True), ('auto_registration_from_queue', '=', True)]}"
|
attrs="{'invisible': ['|', ('queue_allowed', '=', False),'&', ('queue_allowed', '=', True), ('auto_registration_from_queue', '=', True)]}"
|
||||||
confirm="Are you sure you want to switch to automated registration from queue mode ?"/>
|
confirm="Are you sure you want to switch to automated registration from queue mode ?"/>
|
||||||
<button name="auto_registration_toggle"
|
<button name="auto_registration_toggle"
|
||||||
string="Manual registration from queue" type="object"
|
string="Switch to manual registration from queue" type="object"
|
||||||
attrs="{'invisible': ['|', ('queue_allowed', '=', False),'&', ('queue_allowed', '=', True), ('auto_registration_from_queue', '=', False)]}"
|
attrs="{'invisible': ['|', ('queue_allowed', '=', False),'&', ('queue_allowed', '=', True), ('auto_registration_from_queue', '=', False)]}"
|
||||||
confirm="Are you sure you want to switch to manual registration from queue mode ?"/>
|
confirm="Are you sure you want to switch to manual registration from queue mode ?"/>
|
||||||
</header>
|
</header>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user