diff --git a/golem_resource_pack/__init__.py b/golem_resource_pack/__init__.py
index 1fced20..f95e908 100644
--- a/golem_resource_pack/__init__.py
+++ b/golem_resource_pack/__init__.py
@@ -16,4 +16,4 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-from . import models
+from . import models, wizard
diff --git a/golem_resource_pack/__manifest__.py b/golem_resource_pack/__manifest__.py
index 344d218..7bfea4b 100644
--- a/golem_resource_pack/__manifest__.py
+++ b/golem_resource_pack/__manifest__.py
@@ -20,7 +20,7 @@
'name': 'GOLEM resources pack',
'summary': 'GOLEM resources pack',
'description': ''' GOLEM resources pack ''',
- 'version': '10.0.0.0.3',
+ 'version': '10.0.0.0.4',
'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3',
@@ -28,5 +28,6 @@
'installable': True,
'depends': ['golem_resource'],
'data': ['views/golem_resource_pack_views.xml',
+ 'wizard/golem_pack_rejection_views.xml',
'security/ir.model.access.csv']
}
diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py
index 9a1b0a1..69fda75 100644
--- a/golem_resource_pack/models/golem_resource_pack.py
+++ b/golem_resource_pack/models/golem_resource_pack.py
@@ -26,25 +26,39 @@ class GolemResourcePack(models.Model):
""" GOLEM Resource Pack Model """
_name = 'golem.resource.pack'
_description = 'GOLEM Resource Pack Model'
+ _inherit = 'mail.thread'
name = fields.Char(compute='_compute_name', store=True)
- reservation_ids = fields.One2many('golem.resource.reservation', 'pack_id')
+ reservation_ids = fields.One2many('golem.resource.reservation', 'pack_id',
+ readonly=True, states={'draft': [('readonly', False)]},
+ track_visibility='onchange')
-
- note = fields.Text(help='Notes, optional subject for the reservation, reason')
+ note = fields.Text(help='Notes, optional subject for the reservation, reason',
+ readonly=True, states={'draft': [('readonly', False)]},
+ track_visibility='onchange')
user_id = fields.Many2one('res.users', required=True, index=True, readonly=True,
string='User', default=lambda self: self.env.user)
partner_id = fields.Many2one('res.partner', string='On behalf of',
- required=True, index=True)
+ required=True, index=True, readonly=True,
+ states={'draft': [('readonly', False)]},
+ track_visibility='onchange')
state = fields.Selection([('canceled', 'Canceled'),
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('validated', 'Validated'),
('rejected', 'Rejected')],
- default='draft', compute="_compute_pack_state")
+ default='draft', compute="_compute_pack_state",
+ track_visibility='onchange')
reservation_count = fields.Integer(compute="_compute_reservation_count",
string="Reservation count")
+ rejection_reason = fields.Text(readonly=True, track_visibility='onchange')
+
+ @api.multi
+ @api.constrains('partner_id')
+ def set_reservation_partner(self):
+ for pack in self:
+ pack.reservation_ids.write({'partner_id': pack.partner_id.id})
@api.multi
@api.depends('reservation_ids')
@@ -78,11 +92,15 @@ class GolemResourcePack(models.Model):
@api.multi
def state_rejected(self):
- """ pack rejected """
- for pack in self:
- for reservation in pack.reservation_ids:
- if reservation.state == "confirmed":
- reservation.write({'state' :'rejected'})
+ """ Wizard call for pack reject """
+ self.ensure_one()
+ pack_id = self[0]
+ return {'name' : _('Please enter the rejection reason'),
+ 'type' : 'ir.actions.act_window',
+ 'res_model' : 'golem.pack.rejection.wizard',
+ 'context': {'default_pack_id': pack_id.id},
+ 'view_mode': 'form',
+ 'target': 'new'}
@api.depends('partner_id')
diff --git a/golem_resource_pack/views/golem_resource_pack_views.xml b/golem_resource_pack/views/golem_resource_pack_views.xml
index dfe9db0..37d929d 100644
--- a/golem_resource_pack/views/golem_resource_pack_views.xml
+++ b/golem_resource_pack/views/golem_resource_pack_views.xml
@@ -18,22 +18,6 @@ along with this program. If not, see .
-->
-
-
-
-
GOLEM Resource Pack Tree
@@ -76,66 +60,20 @@ along with this program. If not, see .
+
-
+
-
-
-
diff --git a/golem_resource_pack/wizard/__init__.py b/golem_resource_pack/wizard/__init__.py
new file mode 100644
index 0000000..6fa8cf7
--- /dev/null
+++ b/golem_resource_pack/wizard/__init__.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2018 Youssef El Ouahby
+# Copyright 2018 Fabien Bourgeois
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+from . import golem_pack_rejection
diff --git a/golem_resource_pack/wizard/golem_pack_rejection.py b/golem_resource_pack/wizard/golem_pack_rejection.py
new file mode 100644
index 0000000..2dcb6d8
--- /dev/null
+++ b/golem_resource_pack/wizard/golem_pack_rejection.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2018 Youssef El Ouahby
+# Copyright 2018 Fabien Bourgeois
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+""" GOLEM Resources Pack management """
+
+from odoo import models, fields, api
+
+class GolemReservationRejectionWizard(models.TransientModel):
+ """GOLEM Resource wizard : refusal reason for a pack """
+ _name = "golem.pack.rejection.wizard"
+
+ pack_id = fields.Many2one('golem.resource.pack', required=True)
+ reason = fields.Text(required=True)
+
+ @api.multi
+ def reject(self):
+ """ Sets pack status to rejected and add reason """
+ self.ensure_one()
+ rejection = self[0]
+ for reservation in rejection.pack_id.reservation_ids:
+ if reservation.state == "confirmed":
+ reservation.write({'state' :'rejected'})
+ rejection.pack_id.write({'rejection_reason': rejection.reason})
diff --git a/golem_resource_pack/wizard/golem_pack_rejection_views.xml b/golem_resource_pack/wizard/golem_pack_rejection_views.xml
new file mode 100644
index 0000000..b0b01ec
--- /dev/null
+++ b/golem_resource_pack/wizard/golem_pack_rejection_views.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+ GOLEM Pack Rejection Wizard Form
+ golem.pack.rejection.wizard
+
+
+
+
+
+