diff --git a/golem_activity_registration_export/__init__.py b/golem_activity_registration_export/__init__.py new file mode 100644 index 0000000..8a69263 --- /dev/null +++ b/golem_activity_registration_export/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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 controllers, models diff --git a/golem_activity_registration_export/__openerp__.py b/golem_activity_registration_export/__openerp__.py new file mode 100644 index 0000000..6359c6c --- /dev/null +++ b/golem_activity_registration_export/__openerp__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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 Activity Member Registrations CSV exports', + 'summary': 'GOLEM Activities Member Registration CSV exports', + 'description': ''' Non-profit french MJC activities member registration + CSV exports. ATM only members per activity ''', + 'version': '0.1', + 'category': 'GOLEM', + 'author': 'Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': ['golem_activity_registration'], + 'data': ['views/golem_activity_view.xml'] +} diff --git a/golem_activity_registration_export/controllers/__init__.py b/golem_activity_registration_export/controllers/__init__.py new file mode 100644 index 0000000..7340779 --- /dev/null +++ b/golem_activity_registration_export/controllers/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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 controllers diff --git a/golem_activity_registration_export/controllers/controllers.py b/golem_activity_registration_export/controllers/controllers.py new file mode 100644 index 0000000..1106b67 --- /dev/null +++ b/golem_activity_registration_export/controllers/controllers.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +# copyright 2016 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 . + +import json +import openerp.http as http +from openerp.http import request +from openerp.addons.web.controllers.main import CSVExport + + +class ExportGolemActivityMembers(CSVExport): + + @http.route('/web/export/golem/activity_members', type='http', auth='user') + def export_csv_view(self, data): + data = json.loads(data) + FIELDS = ['number', 'lastname', 'firstname', 'contact_address', 'zip', + 'city', 'birthdate_date', 'email', 'phone', 'mobile'] + aid = data.get('activity_id') + a_model = request.env['golem.activity'] + activity = a_model.browse([aid]) + registrations = activity.activity_registration_ids + rows = [] + for r in registrations: + row = [] + for f in FIELDS: + value = r.member_id.__getattribute__(f) + row.append(value) + rows.append(row) + + return request.make_response( + self.from_data(FIELDS, rows), + headers=[('Content-Disposition', 'attachment; filename="%s"' + % self.filename('gollem.activity')), + ('Content-Type', self.content_type)]) diff --git a/golem_activity_registration_export/models/__init__.py b/golem_activity_registration_export/models/__init__.py new file mode 100644 index 0000000..8c9c259 --- /dev/null +++ b/golem_activity_registration_export/models/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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_activity_registration_export diff --git a/golem_activity_registration_export/models/golem_activity_registration_export.py b/golem_activity_registration_export/models/golem_activity_registration_export.py new file mode 100644 index 0000000..3460e73 --- /dev/null +++ b/golem_activity_registration_export/models/golem_activity_registration_export.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# copyright 2016 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 json import dumps +from openerp import models, api + + +class GolemActivity(models.Model): + _inherit = 'golem.activity' + + @api.multi + def do_export_csv(self): + """ Export basic data about members of the current activity to CSV """ + self.ensure_one() + data = dumps({'activity_id': self.id}) + url = '/web/export/golem/activity_members?data={}'.format(data) + print url + return {'type': 'ir.actions.act_url', 'url': url, 'target': 'self'} diff --git a/golem_activity_registration_export/views/golem_activity_view.xml b/golem_activity_registration_export/views/golem_activity_view.xml new file mode 100644 index 0000000..8122604 --- /dev/null +++ b/golem_activity_registration_export/views/golem_activity_view.xml @@ -0,0 +1,37 @@ + + + + + + + + Activity Registrations CSV Export + golem.activity + + + +