From e36c9b537cced9c25042e3c46c9141fc98879498 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 28 Mar 2018 16:57:56 +0200 Subject: [PATCH 01/13] =?UTF-8?q?Cr=C3=A9ation=20du=20module=20resource=20?= =?UTF-8?q?pack=20basique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_resource_pack/__init__.py | 19 ++ golem_resource_pack/__manifest__.py | 31 ++++ golem_resource_pack/models/__init__.py | 19 ++ .../models/golem_resource_pack.py | 30 ++++ .../views/golem_resource_pack_views.xml | 166 ++++++++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 golem_resource_pack/__init__.py create mode 100644 golem_resource_pack/__manifest__.py create mode 100644 golem_resource_pack/models/__init__.py create mode 100644 golem_resource_pack/models/golem_resource_pack.py create mode 100644 golem_resource_pack/views/golem_resource_pack_views.xml diff --git a/golem_resource_pack/__init__.py b/golem_resource_pack/__init__.py new file mode 100644 index 0000000..1fced20 --- /dev/null +++ b/golem_resource_pack/__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 models diff --git a/golem_resource_pack/__manifest__.py b/golem_resource_pack/__manifest__.py new file mode 100644 index 0000000..1d76008 --- /dev/null +++ b/golem_resource_pack/__manifest__.py @@ -0,0 +1,31 @@ +# -*- 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 . + +{ + 'name': 'GOLEM resources pack', + 'summary': 'GOLEM resources pack', + 'description': ''' GOLEM resources pack ''', + 'version': '10.0.0.0.0', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_resource'], + 'data': ['views/golem_resource_pack_views.xml'] +} diff --git a/golem_resource_pack/models/__init__.py b/golem_resource_pack/models/__init__.py new file mode 100644 index 0000000..35a9273 --- /dev/null +++ b/golem_resource_pack/models/__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_resource_pack diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py new file mode 100644 index 0000000..4fdc9ba --- /dev/null +++ b/golem_resource_pack/models/golem_resource_pack.py @@ -0,0 +1,30 @@ +# -*- 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 Resource Packs """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourcePack(models.Model): + """ GOLEM Resource Pack Model """ + _name = 'golem.resource.pack' + _description = 'GOLEM Resource Pack Model' + + name = fields.Char()#compute='_compute_name', store=True) diff --git a/golem_resource_pack/views/golem_resource_pack_views.xml b/golem_resource_pack/views/golem_resource_pack_views.xml new file mode 100644 index 0000000..465a589 --- /dev/null +++ b/golem_resource_pack/views/golem_resource_pack_views.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.40.1 From 24d08c0774bd19b1c2be16b76378d77c14007b06 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 28 Mar 2018 18:03:17 +0200 Subject: [PATCH 02/13] Ajout des champs et design views --- golem_resource_pack/__manifest__.py | 2 +- golem_resource_pack/models/__init__.py | 3 +- .../models/golem_resource_pack.py | 8 +++ .../models/golem_resource_reservation.py | 31 ++++++++++ .../views/golem_resource_pack_views.xml | 60 +++++++------------ 5 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 golem_resource_pack/models/golem_resource_reservation.py diff --git a/golem_resource_pack/__manifest__.py b/golem_resource_pack/__manifest__.py index 1d76008..1d5a6e6 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.0', + 'version': '10.0.0.0.1', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/golem_resource_pack/models/__init__.py b/golem_resource_pack/models/__init__.py index 35a9273..ea2f68b 100644 --- a/golem_resource_pack/models/__init__.py +++ b/golem_resource_pack/models/__init__.py @@ -16,4 +16,5 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from . import golem_resource_pack +from . import golem_resource_pack, \ + golem_resource_reservation diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py index 4fdc9ba..028c7af 100644 --- a/golem_resource_pack/models/golem_resource_pack.py +++ b/golem_resource_pack/models/golem_resource_pack.py @@ -28,3 +28,11 @@ class GolemResourcePack(models.Model): _description = 'GOLEM Resource Pack Model' name = fields.Char()#compute='_compute_name', store=True) + reservation_ids = fields.One2many('golem.resource.reservation', 'pack_id') + + note = fields.Text(help='Notes, optional subject for the reservation, reason') + + 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) diff --git a/golem_resource_pack/models/golem_resource_reservation.py b/golem_resource_pack/models/golem_resource_reservation.py new file mode 100644 index 0000000..bf4c7c6 --- /dev/null +++ b/golem_resource_pack/models/golem_resource_reservation.py @@ -0,0 +1,31 @@ +# -*- 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 Resource Reservation """ + +from math import modf +from datetime import timedelta +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourceReservation(models.Model): + """ GOLEM Resource Reservation Model """ + _inherit = 'golem.resource.reservation' + + pack_id = fields.Many2one('golem_resource_reservation', 'Reservation Pack') diff --git a/golem_resource_pack/views/golem_resource_pack_views.xml b/golem_resource_pack/views/golem_resource_pack_views.xml index 465a589..6b0b0ad 100644 --- a/golem_resource_pack/views/golem_resource_pack_views.xml +++ b/golem_resource_pack/views/golem_resource_pack_views.xml @@ -35,29 +35,24 @@ along with this program. If not, see . --> - + - - - - - - - - - - - - - - - - - - + + + + + -
+ - --> + + res_model="golem.resource.pack" view_mode="tree,form" /> Date: Thu, 29 Mar 2018 15:05:48 +0200 Subject: [PATCH 03/13] Ajout de fonction de confirmation de pack --- golem_resource_pack/__manifest__.py | 2 +- golem_resource_pack/models/golem_resource_pack.py | 11 +++++++++++ .../views/golem_resource_pack_views.xml | 11 ++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/golem_resource_pack/__manifest__.py b/golem_resource_pack/__manifest__.py index 1d5a6e6..81dd541 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.1', + 'version': '10.0.0.0.2', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py index 028c7af..ff77af1 100644 --- a/golem_resource_pack/models/golem_resource_pack.py +++ b/golem_resource_pack/models/golem_resource_pack.py @@ -36,3 +36,14 @@ class GolemResourcePack(models.Model): string='User', default=lambda self: self.env.user) partner_id = fields.Many2one('res.partner', string='On behalf of', required=True, index=True) + state = fields.Selection([('canceled', 'Canceled'), + ('draft', 'Draft'), + ('confirmed', 'Confirmed'), + ('validated', 'Validated'), + ('rejected', 'Rejected')], + default='draft') + + @api.multi + def state_confirm(self): + for pack in self: + pack.reservation_ids.state_confirm() diff --git a/golem_resource_pack/views/golem_resource_pack_views.xml b/golem_resource_pack/views/golem_resource_pack_views.xml index 6b0b0ad..526c5a7 100644 --- a/golem_resource_pack/views/golem_resource_pack_views.xml +++ b/golem_resource_pack/views/golem_resource_pack_views.xml @@ -52,10 +52,10 @@ along with this program. If not, see . golem.resource.pack
- - --> + + - + + groups="golem_base.group_golem_manager" /> -- 2.40.1 From 1afbe75845269e2f0bfcc422cbb2ada714142f5b Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Fri, 30 Mar 2018 02:10:54 +0200 Subject: [PATCH 05/13] =?UTF-8?q?Ajout=20de=20securit=C3=A9=20et=20coloris?= =?UTF-8?q?ation=20de=20la=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_resource_pack/__manifest__.py | 5 +++-- golem_resource_pack/security/ir.model.access.csv | 3 +++ golem_resource_pack/views/golem_resource_pack_views.xml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 golem_resource_pack/security/ir.model.access.csv diff --git a/golem_resource_pack/__manifest__.py b/golem_resource_pack/__manifest__.py index 81dd541..344d218 100644 --- a/golem_resource_pack/__manifest__.py +++ b/golem_resource_pack/__manifest__.py @@ -20,12 +20,13 @@ 'name': 'GOLEM resources pack', 'summary': 'GOLEM resources pack', 'description': ''' GOLEM resources pack ''', - 'version': '10.0.0.0.2', + 'version': '10.0.0.0.3', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', 'application': True, 'installable': True, 'depends': ['golem_resource'], - 'data': ['views/golem_resource_pack_views.xml'] + 'data': ['views/golem_resource_pack_views.xml', + 'security/ir.model.access.csv'] } diff --git a/golem_resource_pack/security/ir.model.access.csv b/golem_resource_pack/security/ir.model.access.csv new file mode 100644 index 0000000..796d31b --- /dev/null +++ b/golem_resource_pack/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_golem_resource_pack_user,Access GOLEM Resource Pack User,model_golem_resource_pack,golem_base.group_golem_user,1,0,0,0 +access_golem_resource_pack_manager,Access GOLEM Resource Pack Manager,model_golem_resource_pack,golem_base.group_golem_manager,1,1,1,1 diff --git a/golem_resource_pack/views/golem_resource_pack_views.xml b/golem_resource_pack/views/golem_resource_pack_views.xml index 52ffcda..dfe9db0 100644 --- a/golem_resource_pack/views/golem_resource_pack_views.xml +++ b/golem_resource_pack/views/golem_resource_pack_views.xml @@ -39,7 +39,7 @@ along with this program. If not, see . GOLEM Resource Pack Tree golem.resource.pack - + -- 2.40.1 From 36058fe1419432c9c9448a271bab7fba4ecccaa4 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Fri, 30 Mar 2018 11:49:58 +0200 Subject: [PATCH 06/13] =?UTF-8?q?Cr=C3=A9ation=20de=20module=20pack=5Facco?= =?UTF-8?q?unt=20:=20structure=20de=20mod=C3=A8le=20et=20vue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_resource_pack_account/__init__.py | 19 ++++++++ golem_resource_pack_account/__manifest__.py | 32 ++++++++++++++ .../models/__init__.py | 19 ++++++++ .../models/golem_resource_pack.py | 44 +++++++++++++++++++ .../models/golem_resource_reservation.py | 31 +++++++++++++ .../security/ir.model.access.csv | 3 ++ .../views/golem_resource_pack_views.xml | 44 +++++++++++++++++++ 7 files changed, 192 insertions(+) create mode 100644 golem_resource_pack_account/__init__.py create mode 100644 golem_resource_pack_account/__manifest__.py create mode 100644 golem_resource_pack_account/models/__init__.py create mode 100644 golem_resource_pack_account/models/golem_resource_pack.py create mode 100644 golem_resource_pack_account/models/golem_resource_reservation.py create mode 100644 golem_resource_pack_account/security/ir.model.access.csv create mode 100644 golem_resource_pack_account/views/golem_resource_pack_views.xml diff --git a/golem_resource_pack_account/__init__.py b/golem_resource_pack_account/__init__.py new file mode 100644 index 0000000..1fced20 --- /dev/null +++ b/golem_resource_pack_account/__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 models diff --git a/golem_resource_pack_account/__manifest__.py b/golem_resource_pack_account/__manifest__.py new file mode 100644 index 0000000..3fc337f --- /dev/null +++ b/golem_resource_pack_account/__manifest__.py @@ -0,0 +1,32 @@ +# -*- 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 . + +{ + 'name': 'GOLEM resources pack invoicing', + 'summary': 'GOLEM resources pack invoicing', + 'description': ''' GOLEM resources pack invoicing ''', + 'version': '10.0.0.0.0', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_resource_pack', 'account'], + 'data': ['views/golem_resource_pack_views.xml'] + #'security/ir.model.access.csv'] +} diff --git a/golem_resource_pack_account/models/__init__.py b/golem_resource_pack_account/models/__init__.py new file mode 100644 index 0000000..35a9273 --- /dev/null +++ b/golem_resource_pack_account/models/__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_resource_pack diff --git a/golem_resource_pack_account/models/golem_resource_pack.py b/golem_resource_pack_account/models/golem_resource_pack.py new file mode 100644 index 0000000..d6c411c --- /dev/null +++ b/golem_resource_pack_account/models/golem_resource_pack.py @@ -0,0 +1,44 @@ +# -*- 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 Resource Pack Invoicing """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourcePack(models.Model): + """ GOLEM Resource Pack invoice extention """ + _inherit = 'golem.resource.pack' + + invoice_id = fields.Many2one('account.invoice', string="Invoice") + + invoice_state = fields.Selection(related='invoice_id.state', store=True, + copy=False) + invoice_amount_total = fields.Monetary(related='invoice_id.amount_total') + currency_id = fields.Many2one(related='invoice_id.currency_id') + + @api.multi + def create_invoice(self): + """ create invoice """ + pass + + @api.multi + def show_invoice(self): + """ show invoice """ + pass diff --git a/golem_resource_pack_account/models/golem_resource_reservation.py b/golem_resource_pack_account/models/golem_resource_reservation.py new file mode 100644 index 0000000..bf4c7c6 --- /dev/null +++ b/golem_resource_pack_account/models/golem_resource_reservation.py @@ -0,0 +1,31 @@ +# -*- 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 Resource Reservation """ + +from math import modf +from datetime import timedelta +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourceReservation(models.Model): + """ GOLEM Resource Reservation Model """ + _inherit = 'golem.resource.reservation' + + pack_id = fields.Many2one('golem_resource_reservation', 'Reservation Pack') diff --git a/golem_resource_pack_account/security/ir.model.access.csv b/golem_resource_pack_account/security/ir.model.access.csv new file mode 100644 index 0000000..796d31b --- /dev/null +++ b/golem_resource_pack_account/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_golem_resource_pack_user,Access GOLEM Resource Pack User,model_golem_resource_pack,golem_base.group_golem_user,1,0,0,0 +access_golem_resource_pack_manager,Access GOLEM Resource Pack Manager,model_golem_resource_pack,golem_base.group_golem_manager,1,1,1,1 diff --git a/golem_resource_pack_account/views/golem_resource_pack_views.xml b/golem_resource_pack_account/views/golem_resource_pack_views.xml new file mode 100644 index 0000000..7fc88f3 --- /dev/null +++ b/golem_resource_pack_account/views/golem_resource_pack_views.xml @@ -0,0 +1,44 @@ + + + + + + + GOLEM Resource Pack Account extentionForm + golem.resource.pack + + + + + + + + + + + + + + -- 2.40.1 From fdf556a8d86d49dc7edef12b003435dd0539aad0 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Fri, 30 Mar 2018 17:27:40 +0200 Subject: [PATCH 07/13] Fonction de facturation --- golem_resource_pack_account/__manifest__.py | 4 +- .../models/golem_resource_pack.py | 37 +++++++++++++++++-- .../views/golem_resource_pack_views.xml | 16 +++++++- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/golem_resource_pack_account/__manifest__.py b/golem_resource_pack_account/__manifest__.py index 3fc337f..05c4042 100644 --- a/golem_resource_pack_account/__manifest__.py +++ b/golem_resource_pack_account/__manifest__.py @@ -20,13 +20,13 @@ 'name': 'GOLEM resources pack invoicing', 'summary': 'GOLEM resources pack invoicing', 'description': ''' GOLEM resources pack invoicing ''', - 'version': '10.0.0.0.0', + 'version': '10.0.0.0.1', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', 'application': True, 'installable': True, - 'depends': ['golem_resource_pack', 'account'], + 'depends': ['golem_resource_pack', 'golem_resource_account'], 'data': ['views/golem_resource_pack_views.xml'] #'security/ir.model.access.csv'] } diff --git a/golem_resource_pack_account/models/golem_resource_pack.py b/golem_resource_pack_account/models/golem_resource_pack.py index d6c411c..fc80578 100644 --- a/golem_resource_pack_account/models/golem_resource_pack.py +++ b/golem_resource_pack_account/models/golem_resource_pack.py @@ -32,13 +32,42 @@ class GolemResourcePack(models.Model): copy=False) invoice_amount_total = fields.Monetary(related='invoice_id.amount_total') currency_id = fields.Many2one(related='invoice_id.currency_id') + is_products_set = fields.Boolean(compute="compute_is_products_set") + + @api.multi + def compute_is_products_set(self): + for pack in self: + product_list = list(map(lambda x: x.resource_product_id, pack.reservation_ids)) + if len(filter(lambda x: x.id == False, product_list)) > 0: + pack.is_products_set = False + else: + pack.is_products_set = True @api.multi def create_invoice(self): - """ create invoice """ - pass + """ Invoice creation """ + for pack in self: + pack.reservation_ids.check_before_invoicing() + inv_obj = self.env['account.invoice'] + partner_id = pack.partner_id + invoice_id = inv_obj.create({ + 'origin': pack.name, + 'type': 'out_invoice', + 'reference': False, + 'account_id': partner_id.property_account_receivable_id.id, + 'partner_id': partner_id.id + }) + pack.invoice_id = invoice_id.id + pack.reservation_ids.create_invoice_line(invoice_id) @api.multi def show_invoice(self): - """ show invoice """ - pass + """ Redirects to linked invoice """ + self.ensure_one() + pack = self[0] + if pack.invoice_id: + return {'type': 'ir.actions.act_window', + 'res_model': 'account.invoice', + 'res_id': pack.invoice_id.id, + 'view_mode': 'form', + 'view_id': self.env.ref('account.invoice_form').id} diff --git a/golem_resource_pack_account/views/golem_resource_pack_views.xml b/golem_resource_pack_account/views/golem_resource_pack_views.xml index 7fc88f3..6d37fcd 100644 --- a/golem_resource_pack_account/views/golem_resource_pack_views.xml +++ b/golem_resource_pack_account/views/golem_resource_pack_views.xml @@ -18,21 +18,33 @@ along with this program. If not, see . --> + + + GOLEM Resource Pack Account extention Tree + golem.resource.pack + + + + + + + - GOLEM Resource Pack Account extentionForm + GOLEM Resource Pack Account extention Form golem.resource.pack + -- 2.40.1 From 1415b0306fefbe660e6a5bf428ade5fb6089471a Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Fri, 30 Mar 2018 19:03:57 +0200 Subject: [PATCH 08/13] =?UTF-8?q?am=C3=A9lioration=20de=20vue=20et=20raiso?= =?UTF-8?q?n=20de=20rejection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_resource_pack/__init__.py | 2 +- golem_resource_pack/__manifest__.py | 3 +- .../models/golem_resource_pack.py | 38 +++++++--- .../views/golem_resource_pack_views.xml | 70 ++----------------- golem_resource_pack/wizard/__init__.py | 19 +++++ .../wizard/golem_pack_rejection.py | 38 ++++++++++ .../wizard/golem_pack_rejection_views.xml | 41 +++++++++++ 7 files changed, 133 insertions(+), 78 deletions(-) create mode 100644 golem_resource_pack/wizard/__init__.py create mode 100644 golem_resource_pack/wizard/golem_pack_rejection.py create mode 100644 golem_resource_pack/wizard/golem_pack_rejection_views.xml 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 + +
+ + + + +
+
+
+
+
+
+
-- 2.40.1 From a0fc41cbccc7e0f3f13e9a4f1ad8e68e14ad1d2b Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Sat, 31 Mar 2018 00:33:26 +0200 Subject: [PATCH 09/13] ajout des tests pack --- golem_resource_pack/tests/__init__.py | 19 +++ .../tests/test_golem_resource_pack.py | 145 ++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 golem_resource_pack/tests/__init__.py create mode 100644 golem_resource_pack/tests/test_golem_resource_pack.py diff --git a/golem_resource_pack/tests/__init__.py b/golem_resource_pack/tests/__init__.py new file mode 100644 index 0000000..cbb2d37 --- /dev/null +++ b/golem_resource_pack/tests/__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 test_golem_resource_pack diff --git a/golem_resource_pack/tests/test_golem_resource_pack.py b/golem_resource_pack/tests/test_golem_resource_pack.py new file mode 100644 index 0000000..e824749 --- /dev/null +++ b/golem_resource_pack/tests/test_golem_resource_pack.py @@ -0,0 +1,145 @@ +# -*- 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 Resource Pack testing """ + +import logging +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError +_LOGGER = logging.getLogger(__name__) + + +class TestGolemResourcePack(TransactionCase): + """ GOLEM Resource Reservation testing """ + + def setUp(self, *args, **kwargs): + """ Bootstrap Resource Reservation """ + super(TestGolemResourcePack, self).setUp(*args, **kwargs) + + self.resource = self.env['golem.resource'].create({ + 'name': 'Resource', + 'avaibility_start': '2018-01-01', + 'avaibility_stop': '2020-01-01', + 'availibility_24_7': True + }) + self.resource_val = self.env['golem.resource'].create({ + 'name': 'Resource to validate', + 'avaibility_start': '2018-01-01', + 'avaibility_stop': '2020-01-01', + 'validation_required': True, + 'availibility_24_7': True + }) + + self.partner = self.env['res.partner'].create({'firstname': 'John', + 'lastname': 'DOE', + 'is_company': False}) + + reservation_obj = self.env['golem.resource.reservation'] + self.reservation_1 = reservation_obj.create({ + 'resource_id': self.resource.id, + 'date_start': '2018-02-05 11:00:00', + 'date_stop': '2018-02-05 12:00:00', + 'partner_id': self.partner.id + }) + self.reservation_2 = reservation_obj.create({ + 'resource_id': self.resource.id, + 'date_start': '2018-02-06 11:00:00', + 'date_stop': '2018-02-06 12:00:00', + 'partner_id': self.partner.id + }) + self.reservation_3 = reservation_obj.create({ + 'resource_id': self.resource_val.id, + 'date_start': '2018-02-05 11:00:00', # is monday + 'date_stop': '2018-02-05 12:00:00', + 'partner_id': self.partner.id + }) + self.pack_obj = self.env['golem.resource.pack'] + self.pack_data = { + 'partner_id': self.partner.id + } + + + def test_pack_basic(self): + """ Test pack bases """ + pack = self.pack_obj.create(self.pack_data) + self.assertFalse(pack.reservation_ids) + self.assertFalse(self.reservation_1.pack_id) + pack.reservation_ids = [(4, self.reservation_1.id, 0), + (4, self.reservation_2.id, 0)] + self.assertEqual(pack.reservation_ids[0].state, "draft") + self.assertEqual(self.reservation_1.pack_id.id, pack.id) + self.assertEqual(pack.state, "draft") + self.assertEqual(pack.reservation_count, 2) + #confirm pack ==> all validated + pack.state_confirm()#no validation required + self.assertEqual(pack.reservation_ids[0].state, "validated") + self.assertEqual(pack.state, "validated") + #pack draft ==> all draft + pack.state_draft() + self.assertEqual(pack.reservation_ids[0].state, "draft") + self.assertEqual(pack.state, "draft") + # confirm pack and draft reservation ==> pack draft + pack.state_confirm() + pack.reservation_ids[0].state_draft() + self.assertEqual(pack.reservation_ids[0].state, "draft") + self.assertEqual(pack.state, "draft") + #confirm reservation ==> pack validated + 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)] + self.assertFalse(pack.reservation_ids) + self.assertEqual(pack.reservation_count, 0) + + + def test_pack_validation(self): + """ Test pack validation """ + pack = self.pack_obj.create(self.pack_data) + self.assertFalse(pack.reservation_ids) + self.assertFalse(self.reservation_1.pack_id) + pack.reservation_ids = [(4, self.reservation_1.id, 0), + (4, self.reservation_3.id, 0)] + self.assertEqual(pack.reservation_ids[0].state, "draft") + self.assertEqual(self.reservation_1.pack_id.id, pack.id) + self.assertEqual(pack.state, "draft") + pack.state_confirm()#validation required + self.assertEqual(pack.state, "confirmed") + pack.state_validated() + self.assertEqual(pack.state, "validated") + self.assertEqual(pack.reservation_ids[0].state, "validated") + self.assertEqual(pack.reservation_ids[1].state, "validated") + + def test_pack_rejection(self): + """ test pack rejection """ + pack = self.pack_obj.create(self.pack_data) + self.assertFalse(pack.reservation_ids) + self.assertFalse(self.reservation_1.pack_id) + pack.reservation_ids = [(4, self.reservation_1.id, 0), + (4, self.reservation_3.id, 0)] + self.assertEqual(pack.reservation_ids[0].state, "draft") + self.assertEqual(self.reservation_1.pack_id.id, pack.id) + self.assertEqual(pack.state, "draft") + pack.state_confirm()#validation required + rej_wizard = self.env['golem.pack.rejection.wizard'].create({ + 'pack_id': pack.id, + 'reason' : 'reason1' + }) + rej_wizard.reject() + self.assertEqual(pack.state, "rejected") + self.assertEqual(self.reservation_3.state, "rejected") + self.assertEqual(pack.rejection_reason, 'reason1') -- 2.40.1 From 66c01206f0ff4dcc5d570e062b5d225ab56e4440 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Sat, 31 Mar 2018 02:47:05 +0200 Subject: [PATCH 10/13] contrainte sur les clients multiples --- golem_resource_pack/models/golem_resource_pack.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py index 69fda75..279aac2 100644 --- a/golem_resource_pack/models/golem_resource_pack.py +++ b/golem_resource_pack/models/golem_resource_pack.py @@ -109,8 +109,13 @@ class GolemResourcePack(models.Model): for pack in self: pack.name = u'{}/{}'.format(pack.partner_id.name, pack.create_date) + @api.multi + @api.constrains('reservation_ids') + def check_reservation_partner(self): + 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')) - #@api.constrains('reservation_ids.state') @api.multi @api.depends('reservation_ids') def _compute_pack_state(self): -- 2.40.1 From 9961933f9618541cc50f2ae209d131c5e87a9baa Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Sat, 31 Mar 2018 17:17:08 +0200 Subject: [PATCH 11/13] refactoration de code --- .../models/golem_resource_pack.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py index 279aac2..fa176e5 100644 --- a/golem_resource_pack/models/golem_resource_pack.py +++ b/golem_resource_pack/models/golem_resource_pack.py @@ -30,19 +30,21 @@ class GolemResourcePack(models.Model): name = fields.Char(compute='_compute_name', store=True) reservation_ids = fields.One2many('golem.resource.reservation', 'pack_id', - readonly=True, states={'draft': [('readonly', False)]}, - track_visibility='onchange') + readonly=True, track_visibility='onchange', + states={'draft': [('readonly', False)], + False : [('readonly', False)]}) note = fields.Text(help='Notes, optional subject for the reservation, reason', - readonly=True, states={'draft': [('readonly', False)]}, - track_visibility='onchange') + track_visibility='onchange',readonly=True, + states={'draft': [('readonly', False)], + False : [('readonly', False)]}) 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, readonly=True, - states={'draft': [('readonly', False)]}, - track_visibility='onchange') + partner_id = fields.Many2one('res.partner', string='On behalf of', required=True, + index=True, track_visibility='onchange', readonly=True, + states={'draft': [('readonly', False)], + False : [('readonly', False)]}) state = fields.Selection([('canceled', 'Canceled'), ('draft', 'Draft'), ('confirmed', 'Confirmed'), -- 2.40.1 From 7223afa48649271ce9cd7e62dc91d3a42f97975b Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Sun, 1 Apr 2018 02:02:22 +0200 Subject: [PATCH 12/13] Ajout des tests pour facturation des packs --- .../models/golem_resource_pack.py | 27 ++++- .../security/ir.model.access.csv | 3 - .../__init__.py} | 15 +-- .../tests/test_golem_pack_invoice.py | 114 ++++++++++++++++++ 4 files changed, 137 insertions(+), 22 deletions(-) delete mode 100644 golem_resource_pack_account/security/ir.model.access.csv rename golem_resource_pack_account/{models/golem_resource_reservation.py => tests/__init__.py} (67%) create mode 100644 golem_resource_pack_account/tests/test_golem_pack_invoice.py diff --git a/golem_resource_pack_account/models/golem_resource_pack.py b/golem_resource_pack_account/models/golem_resource_pack.py index fc80578..c541dad 100644 --- a/golem_resource_pack_account/models/golem_resource_pack.py +++ b/golem_resource_pack_account/models/golem_resource_pack.py @@ -32,21 +32,38 @@ class GolemResourcePack(models.Model): copy=False) invoice_amount_total = fields.Monetary(related='invoice_id.amount_total') currency_id = fields.Many2one(related='invoice_id.currency_id') - is_products_set = fields.Boolean(compute="compute_is_products_set") + is_products_set = fields.Boolean(compute="_compute_is_products_set") @api.multi - def compute_is_products_set(self): + def _compute_is_products_set(self): + """ compute is_products_set """ for pack in self: - product_list = list(map(lambda x: x.resource_product_id, pack.reservation_ids)) - if len(filter(lambda x: x.id == False, product_list)) > 0: + if len(filter(lambda x: x.resource_product_id.id is False, pack.reservation_ids)) \ + > 0: pack.is_products_set = False else: pack.is_products_set = True + @api.multi + def chek_pack_to_invoice(self): + """ chek pack before invoicing """ + for pack in self: + if pack.state != 'validated': + raise ValidationError(_('The current pack is not validated, please validate ' + 'it before creating invoice')) + elif not pack.is_products_set: + raise ValidationError(_('You can not create an invoice for a pack without ' + 'linked product on every resource reserved.')) + elif pack.invoice_id.id: + raise ValidationError(_('You can not create an invoice as there ' + 'is already one.')) + + @api.multi def create_invoice(self): """ Invoice creation """ for pack in self: + pack.chek_pack_to_invoice() pack.reservation_ids.check_before_invoicing() inv_obj = self.env['account.invoice'] partner_id = pack.partner_id @@ -56,7 +73,7 @@ class GolemResourcePack(models.Model): 'reference': False, 'account_id': partner_id.property_account_receivable_id.id, 'partner_id': partner_id.id - }) + }) pack.invoice_id = invoice_id.id pack.reservation_ids.create_invoice_line(invoice_id) diff --git a/golem_resource_pack_account/security/ir.model.access.csv b/golem_resource_pack_account/security/ir.model.access.csv deleted file mode 100644 index 796d31b..0000000 --- a/golem_resource_pack_account/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_golem_resource_pack_user,Access GOLEM Resource Pack User,model_golem_resource_pack,golem_base.group_golem_user,1,0,0,0 -access_golem_resource_pack_manager,Access GOLEM Resource Pack Manager,model_golem_resource_pack,golem_base.group_golem_manager,1,1,1,1 diff --git a/golem_resource_pack_account/models/golem_resource_reservation.py b/golem_resource_pack_account/tests/__init__.py similarity index 67% rename from golem_resource_pack_account/models/golem_resource_reservation.py rename to golem_resource_pack_account/tests/__init__.py index bf4c7c6..69aaa1d 100644 --- a/golem_resource_pack_account/models/golem_resource_reservation.py +++ b/golem_resource_pack_account/tests/__init__.py @@ -15,17 +15,4 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - -""" GOLEM Resource Reservation """ - -from math import modf -from datetime import timedelta -from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError - - -class GolemResourceReservation(models.Model): - """ GOLEM Resource Reservation Model """ - _inherit = 'golem.resource.reservation' - - pack_id = fields.Many2one('golem_resource_reservation', 'Reservation Pack') +from . import test_golem_pack_invoice diff --git a/golem_resource_pack_account/tests/test_golem_pack_invoice.py b/golem_resource_pack_account/tests/test_golem_pack_invoice.py new file mode 100644 index 0000000..29961a5 --- /dev/null +++ b/golem_resource_pack_account/tests/test_golem_pack_invoice.py @@ -0,0 +1,114 @@ +# -*- 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 Resource Reservation testing """ + +import logging +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError +_LOGGER = logging.getLogger(__name__) + + +class TestGolemResourcePack(TransactionCase): + """ GOLEM Resource Pack testing """ + + def setUp(self, *args, **kwargs): + """ Bootstrap Resource Reservation """ + super(TestGolemResourcePack, self).setUp(*args, **kwargs) + # set product + self.product = self.env['product.template'].create({ + 'name': 'Product', + 'categ_id': self.env.ref('product.product_category_all').id, + 'list_price': 7.0, + 'type': 'service', + 'uom_id': self.env.ref('product.product_uom_hour').id, + 'uom_po_id': self.env.ref('product.product_uom_hour').id, + 'property_account_income_id': self.env.ref('l10n_fr.pcg_706').id + }) + #set resources + self.resource_1 = self.env['golem.resource'].create({ + 'name': 'Resource1', + 'product_tmpl_id': self.product.id, + 'avaibility_start': '2018-01-01', + 'avaibility_stop': '2020-01-01', + 'availibility_24_7': True + }) + self.resource_2 = self.env['golem.resource'].create({ + 'name': 'Resource2', + 'avaibility_start': '2018-01-01', + 'avaibility_stop': '2020-01-01', + 'availibility_24_7': True + }) + + #set partners + self.partner_1 = self.env['res.partner'].create({'firstname': 'John', + 'lastname': 'DOE', + 'is_company': False}) + self.partner_2 = self.env['res.partner'].create({'firstname': 'John2', + 'lastname': 'DOE2', + 'is_company': False}) + + # set reservations + self.reservation_1 = self.env['golem.resource.reservation'].create({ + 'resource_id': self.resource_1.id, + 'date_start': '2018-02-05 11:00:00', + 'date_stop': '2018-02-05 12:00:00', + 'partner_id': self.partner_1.id + }) + self.reservation_2 = self.env['golem.resource.reservation'].create({ + 'resource_id': self.resource_1.id, + 'date_start': '2018-02-06 11:00:00', + 'date_stop': '2018-02-06 12:00:00', + 'partner_id': self.partner_1.id + }) + + #set pack env + self.pack_obj = self.env['golem.resource.pack'] + self.pack_data = { + 'partner_id': self.partner_1.id, + 'reservation_ids': [(4, self.reservation_1.id, 0), + (4, self.reservation_2.id, 0)]} + + + def test_pack_invoice_basic(self): + """ Test pack invoice basic """ + pack = self.pack_obj.create(self.pack_data) + pack.state_confirm() + pack.create_invoice() + self.assertTrue(pack.invoice_id.id) + self.assertEqual(pack.invoice_state, 'draft') + + def test_unallowed_pack_invoice(self): + """ Test unallowed pack invoice cases """ + pack = self.pack_obj.create(self.pack_data) + with self.assertRaises(ValidationError) as err: + pack.create_invoice() + self.assertIn(u'current pack is not validated', err.exception.args[0]) + self.reservation_2.write({'resource_id': self.resource_2.id})#no product linked + pack.state_confirm() + with self.assertRaises(ValidationError) as err: + pack.create_invoice() + self.assertIn(u'linked product on every resource', err.exception.args[0]) + pack.state_draft() + self.reservation_2.write({'resource_id': self.resource_1.id})# with product linked + pack.state_confirm() + pack.create_invoice() + self.assertTrue(pack.invoice_id.id) + with self.assertRaises(ValidationError) as err: + pack.create_invoice() + self.assertIn(u'can not create an invoice as there', err.exception.args[0]) -- 2.40.1 From b105d877459897a138101e3fd01e0a85ec1fb192 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Mon, 16 Apr 2018 18:04:05 +0200 Subject: [PATCH 13/13] code refactoring --- golem_resource_pack/models/golem_resource_pack.py | 4 +++- golem_resource_pack/models/golem_resource_reservation.py | 5 +---- golem_resource_pack/tests/test_golem_resource_pack.py | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/golem_resource_pack/models/golem_resource_pack.py b/golem_resource_pack/models/golem_resource_pack.py index fa176e5..ad51f7e 100644 --- a/golem_resource_pack/models/golem_resource_pack.py +++ b/golem_resource_pack/models/golem_resource_pack.py @@ -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')) diff --git a/golem_resource_pack/models/golem_resource_reservation.py b/golem_resource_pack/models/golem_resource_reservation.py index bf4c7c6..2644175 100644 --- a/golem_resource_pack/models/golem_resource_reservation.py +++ b/golem_resource_pack/models/golem_resource_reservation.py @@ -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): diff --git a/golem_resource_pack/tests/test_golem_resource_pack.py b/golem_resource_pack/tests/test_golem_resource_pack.py index e824749..1cc5274 100644 --- a/golem_resource_pack/tests/test_golem_resource_pack.py +++ b/golem_resource_pack/tests/test_golem_resource_pack.py @@ -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) -- 2.40.1