From dade1dc948d02a39e6bb4d3b41f8ac2b95036d6c Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Fri, 27 Nov 2015 12:58:14 +0100 Subject: [PATCH 01/16] Add module event_product. --- event_product/README.rst | 119 ++++++++++++++++++++++ event_product/__init__.py | 5 + event_product/__openerp__.py | 26 +++++ event_product/exceptions.py | 33 ++++++ event_product/i18n/es.po | 92 +++++++++++++++++ event_product/models/__init__.py | 5 + event_product/models/event.py | 42 ++++++++ event_product/models/product.py | 81 +++++++++++++++ event_product/static/description/icon.png | Bin 0 -> 9455 bytes event_product/tests/__init__.py | 5 + event_product/tests/base.py | 25 +++++ event_product/tests/test_event.py | 53 ++++++++++ event_product/tests/test_product.py | 91 +++++++++++++++++ event_product/views/event.xml | 20 ++++ event_product/views/product.xml | 29 ++++++ 15 files changed, 626 insertions(+) create mode 100644 event_product/README.rst create mode 100644 event_product/__init__.py create mode 100644 event_product/__openerp__.py create mode 100644 event_product/exceptions.py create mode 100644 event_product/i18n/es.po create mode 100644 event_product/models/__init__.py create mode 100644 event_product/models/event.py create mode 100644 event_product/models/product.py create mode 100644 event_product/static/description/icon.png create mode 100644 event_product/tests/__init__.py create mode 100644 event_product/tests/base.py create mode 100644 event_product/tests/test_event.py create mode 100644 event_product/tests/test_product.py create mode 100644 event_product/views/event.xml create mode 100644 event_product/views/product.xml diff --git a/event_product/README.rst b/event_product/README.rst new file mode 100644 index 000000000..79e509472 --- /dev/null +++ b/event_product/README.rst @@ -0,0 +1,119 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============== +Event Products +============== + +This module extends the functionality of events and products to support +combining them and allow you to have a *catalog* of events that you organize. + +Those events in your catalog can have variants, and any event can be linked to +any product as long as: + +* The product's *Is an event* checkbox is enabled. +* The product's event type is empty, or matches the event's. + +Examples: + +* Wedding. + * Variants: + * Until 50 attendees. + * Until 100 attendees. + * In beach. + * In countryfield. +* Congress. + * Variants: + * Until 50 attendees. + * Until 100 attendees. +* Opening. + * Variants: + * 1 day. + * 2 days. + * 3 days. + +Usage +===== + +To create your *event products*, you need to: + +* Go to *Sales > Products > Products > Create*. +* Give it a name, such as *Wedding*. +* Enable *Is an event*. +* Choose event type in *Information > Type of Event* (or leave blank for + generic events). +* Press *Save*. + +To create variants for that, you need to: + +* Edit previous product. +* Go to *Variants* tab. +* Press *Add an Item*. +* Add your attribute and values as usual. + +To link an event to any of those variants, you need to: + +* Go to *Marketing > Events > Events > Create*. +* Set name, start and end dates. +* Choose the same *Type of Event* as when creating the product (unless you + left it blank, in which case you do not need this). +* Choose one of your variants in *Product*. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/199/8.0 + +Known issues / Roadmap +====================== + +* If you install this module, you will install *sale* too. If you do not want + to sale events, but just to handle internal ones, this can be disturbing + because you will be asked to configure accounting and you will install a lot + of dependencies. + + However, this happens because this module needs the ``event_type_id`` field + in products, which is added by the *event_sale* module, which installs + *sale*; so unless Odoo divides that module in smaller parts with smaller + dependencies, the only workaround is to give permissions to use *sale* to + nobody. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jairo Llopis + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/event_product/__init__.py b/event_product/__init__.py new file mode 100644 index 000000000..b180e1009 --- /dev/null +++ b/event_product/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/event_product/__openerp__.py b/event_product/__openerp__.py new file mode 100644 index 000000000..86a05cefe --- /dev/null +++ b/event_product/__openerp__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Event Products", + "summary": "Combine products and events", + "version": "8.0.1.0.0", + "category": "Event Management", + "website": "https://grupoesoc.es/", + "author": "Grupo ESOC Ingeniería de Servicios, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "event_sale", + ], + "data": [ + "views/event.xml", + "views/product.xml", + ] +} diff --git a/event_product/exceptions.py b/event_product/exceptions.py new file mode 100644 index 000000000..da6727714 --- /dev/null +++ b/event_product/exceptions.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import _, exceptions + + +class EventProductValidationError(exceptions.ValidationError): + """Base class for this module's validation errors.""" + def __init__(self, *args, **kwargs): + self._args, self._kwargs = args, kwargs + value = self._message() + super(EventProductValidationError, self).__init__(value) + + def _message(self): + """Format the message.""" + return self.__doc__.format(*self._args, **self._kwargs) + + +class EventAndTicketError(EventProductValidationError): + __doc__ = _("It cannot be a whole event and a ticket at the same time.") + + +class ProductIsNotEventError(EventProductValidationError): + __doc__ = _("Product {} is not for events.") + + +class ProductEventTypeError(EventProductValidationError): + __doc__ = _("Product is already used in some event with a different type.") + + +class TypeMismatchError(EventProductValidationError): + __doc__ = _("Product has type {product_type}, but event has {event_type}.") diff --git a/event_product/i18n/es.po b/event_product/i18n/es.po new file mode 100644 index 000000000..3422b189e --- /dev/null +++ b/event_product/i18n/es.po @@ -0,0 +1,92 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * event_product +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-27 12:27+0100\n" +"PO-Revision-Date: 2015-11-27 12:29+0100\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.8.5\n" +"Last-Translator: Jairo Llopis \n" +"Language: es_ES\n" + +#. module: event_product +#: model:ir.model,name:event_product.model_event_event +msgid "Event" +msgstr "Evento" + +#. module: event_product +#: field:product.product,event_ids:0 +msgid "Events" +msgstr "Eventos" + +#. module: event_product +#: field:event_product.product,id:0 +msgid "ID" +msgstr "" + +#. module: event_product +#: field:product.template,is_event:0 +msgid "Is an event" +msgstr "Es un evento" + +#. module: event_product +#: code:addons/event_product/exceptions.py:21 +#, python-format +msgid "It cannot be a whole event and a ticket at the same time." +msgstr "No puede ser un evento entero y un ticket para eventos a la vez." + +#. module: event_product +#: field:event.event,product_id:0 +#: model:ir.model,name:event_product.model_product_product +msgid "Product" +msgstr "Producto" + +#. module: event_product +#: model:ir.model,name:event_product.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: event_product +#: code:addons/event_product/exceptions.py:33 +#, python-format +msgid "Product has type {product_type}, but event has {event_type}." +msgstr "El producto es de tipo {product_type}, pero el evento de typo {event_type}." + +#. module: event_product +#: code:addons/event_product/exceptions.py:29 +#, python-format +msgid "Product is already used in some event with a different type." +msgstr "El producto ya se usa en algún evento con un tipo diferente." + +#. module: event_product +#: help:event.event,product_id:0 +msgid "Product of this event, if available." +msgstr "Producto de este evento, si está disponible." + +#. module: event_product +#: code:addons/event_product/exceptions.py:25 +#, python-format +msgid "Product {} is not for events." +msgstr "El producto {} no es para eventos." + +#. module: event_product +#: help:product.template,is_event:0 +msgid "This product defines a whole event (NOT an event ticket)." +msgstr "Este producto define un evento entero (NO un ticket para eventos)." + +#. module: event_product +#: view:product.template:event_product.product_template_form +msgid "" +"{\n" +" \"invisible\": [(\"event_ok\", \"=\", False),\n" +" (\"is_event\", \"=\", False)],\n" +" }" +msgstr "" diff --git a/event_product/models/__init__.py b/event_product/models/__init__.py new file mode 100644 index 000000000..a1bf029a8 --- /dev/null +++ b/event_product/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import event, product diff --git a/event_product/models/event.py b/event_product/models/event.py new file mode 100644 index 000000000..82a09b051 --- /dev/null +++ b/event_product/models/event.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models +from .. import exceptions as ex + + +class EventEvent(models.Model): + _inherit = "event.event" + + product_id = fields.Many2one( + "product.product", + "Product", + domain="""[("is_event", "=", True), + ("event_type_id", "in", (False, type))]""", + states={"done": [("readonly", True)]}, + help="Product of this event, if available.") + + @api.multi + @api.constrains("type", "product_id") + def _check_product_type(self): + """Ensure product and event types match.""" + for s in self: + if s.product_id: + if not s.product_id.is_event: + raise ex.ProductIsNotEventError(s.product_id.name) + if s.product_id.event_type_id not in (s.type, + self.env["event.type"]): + raise ex.TypeMismatchError( + product_type=s.product_id.event_type_id.name, + event_type=s.type.name) + + @api.multi + @api.onchange("type") + def _onchange_type_clear_product(self): + """Better have no product than have a wrong one.""" + for s in self: + try: + s._check_product_type() + except ex.TypeMismatchError: + s.product_id = False diff --git a/event_product/models/product.py b/event_product/models/product.py new file mode 100644 index 000000000..7f4c33c35 --- /dev/null +++ b/event_product/models/product.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models +from .. import exceptions as ex + + +class ProductBase(models.AbstractModel): + _name = "event_product.product" + + @api.multi + @api.constrains("event_ok", "is_event") + def _check_ticket_is_not_event(self): + """Ensure events are not tickets.""" + for s in self: + if s.event_ok and s.is_event: + raise ex.EventAndTicketError() + + @api.multi + @api.onchange("is_event") + def _onchange_is_event(self): + """Avoid conflicts between :attr:`~.event_ok` and :attr:`~.is_event`. + + Products cannot be an event and a ticket at the same time. + """ + for s in self: + if s.is_event: + s.event_ok = False + s.type = "service" + + +class ProductTemplate(models.Model): + _name = "product.template" + _inherit = ["product.template", ProductBase._name] + + is_event = fields.Boolean( + "Is an event", + help="This product defines a whole event (NOT an event ticket).") + + @api.multi + def onchange_event_ok(self, type, event_ok): + """Inverse of :meth:`~._onchange_is_event`. + + Cannot declare in ``event_product.product`` because it gets ignored. + """ + # TODO Merge with `_onchange_is_event` when core updates to new api + result = super(ProductTemplate, self).onchange_event_ok(type, event_ok) + if event_ok: + result.setdefault("value", dict()) + result["value"]["is_event"] = False + return result + + +class ProductProduct(models.Model): + _name = "product.product" + _inherit = ["product.product", ProductBase._name] + + event_ids = fields.One2many( + "event.event", + "product_id", + "Events") + + @api.multi + @api.constrains("is_event", "event_type_id", "event_ids") + def _check_event_type_consistent(self): + """Avoid changing type if it creates an inconsistency.""" + self.mapped("event_ids")._check_product_type() + + @api.multi + def onchange_event_ok(self, type, event_ok): + """Inverse of :meth:`~._onchange_is_event`. + + Cannot declare in ``event_product.product`` because it gets ignored. + """ + # TODO Merge with `_onchange_is_event` when core updates to new api + result = super(ProductProduct, self).onchange_event_ok(type, event_ok) + if event_ok: + result.setdefault("value", dict()) + result["value"]["is_event"] = False + return result diff --git a/event_product/static/description/icon.png b/event_product/static/description/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&t@y?5rvg<}E+GB}26NYPp4f2YFQrQtot5mn3wu_qprZ=>Ig-$ zbW26Ws~IgY>}^5w`vTB(G`PTZaDiGBo5o(tp)qli|NeV( z@H_=R8V39rt5J5YB2Ky?4eJJ#b`_iBe2ot~6%7mLt5t8Vwi^Jy7|jWXqa3amOIoRb zOr}WVFP--DsS`1WpN%~)t3R!arKF^Q$e12KEqU36AWwnCBICpH4XCsfnyrHr>$I$4 z!DpKX$OKLWarN7nv@!uIA+~RNO)l$$w}p(;b>mx8pwYvu;dD_unryX_NhT8*Tj>BTrTTL&!?O+%Rv;b?B??gSzdp?6Uug9{ zd@V08Z$BdI?fpoCS$)t4mg4rT8Q_I}h`0d-vYZ^|dOB*Q^S|xqTV*vIg?@fVFSmMpaw0qtTRbx} z({Pg?#{2`sc9)M5N$*N|4;^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/event_product/tests/__init__.py b/event_product/tests/__init__.py new file mode 100644 index 000000000..7effa0678 --- /dev/null +++ b/event_product/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_event, test_product diff --git a/event_product/tests/base.py b/event_product/tests/base.py new file mode 100644 index 000000000..46d81d68d --- /dev/null +++ b/event_product/tests/base.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +class BaseCase(object): + def setUp(self, *args, **kwargs): + result = super(BaseCase, self).setUp(*args, **kwargs) + + self.event_type_1 = self.env["event.type"].create({ + "name": "Test event type 1", + }) + self.event_type_2 = self.env["event.type"].create({ + "name": "Test event type 2", + }) + self.product = self.env["product.product"].create({ + "name": "Test product 1", + }) + self.event = self.env["event.event"].create({ + "name": "Test event 1", + "date_begin": "2015-11-26", + "date_end": "2015-11-30", + }) + + return result diff --git a/event_product/tests/test_event.py b/event_product/tests/test_event.py new file mode 100644 index 000000000..13c68b181 --- /dev/null +++ b/event_product/tests/test_event.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase +from .base import BaseCase +from .. import exceptions as ex + + +class EventEventCase(BaseCase, TransactionCase): + def setUp(self, *args, **kwargs): + result = super(EventEventCase, self).setUp(*args, **kwargs) + self.product.is_event = True + self.event_new = self.env["event.event"].new({ + "name": "Event 2", + "date_begin": "2015-11-26", + "date_end": "2015-11-30", + }) + return result + + def test_link_wrong_product(self): + """Cannot link a non-event product.""" + self.product.is_event = False + with self.assertRaises(ex.ProductIsNotEventError): + self.event.product_id = self.product + + def test_link_event_no_type(self): + """Cannot link to typed product if event has no type.""" + self.product.event_type_id = self.event_type_1 + with self.assertRaises(ex.TypeMismatchError): + self.event.product_id = self.product + + def test_link_product_no_type(self): + """Allow to link to a product with no type.""" + self.event.type = self.event_type_1 + self.event.product_id = self.product + + def test_link_wrong_product_type(self): + """Cannot link to a product with a wrong type.""" + self.product.event_type_id = self.event_type_1 + self.event.type = self.event_type_2 + with self.assertRaises(ex.TypeMismatchError): + self.event.product_id = self.product + + def test_onchange_type_remove_wrong_product(self): + """Onchange avoids conflict with wrong product type.""" + self.product.event_type_id = self.event_type_1 + self.event_new.type = self.event_type_1 + self.event_new._onchange_type_clear_product() + self.event_new.product_id = self.product + self.event_new.type = self.event_type_2 + self.event_new._onchange_type_clear_product() + self.assertFalse(self.event.product_id) diff --git a/event_product/tests/test_product.py b/event_product/tests/test_product.py new file mode 100644 index 000000000..78ddd0e5f --- /dev/null +++ b/event_product/tests/test_product.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase +from .base import BaseCase +from .. import exceptions as ex + + +class ProductTemplateCase(BaseCase, TransactionCase): + model = "product.template" + + def setUp(self, *args, **kwargs): + result = super(ProductTemplateCase, self).setUp(*args, **kwargs) + + self.product_new = self.env[self.model].new({ + "name": "Test product 1", + }) + + return result + + def test_is_event_disables_event_ok(self): + """Setting ``is_event`` disables ``event_ok``.""" + self.product_new.event_ok = True + self.product_new.update( + self.product_new.onchange_event_ok( + self.product_new.event_type_id, + self.product_new.event_ok).get("value", dict())) + self.product_new.is_event = True + self.product_new._onchange_is_event() + + self.assertTrue(self.product_new.is_event) + self.assertFalse(self.product_new.event_ok) + self.assertEqual(self.product_new.type, "service") + + def test_event_ok_disables_is_event(self): + """Setting ``event_ok`` disables ``is_event``.""" + self.product_new.is_event = True + self.product_new._onchange_is_event() + self.product_new.event_ok = True + self.product_new.update( + self.product_new.onchange_event_ok( + self.product_new.event_type_id, + self.product_new.event_ok).get("value", dict())) + + self.assertFalse(self.product_new.is_event) + self.assertTrue(self.product_new.event_ok) + self.assertEqual(self.product_new.type, "service") + + +class ProductProductCase(ProductTemplateCase): + model = "product.product" + + def _assign_type_and_event(self): + """Assign type to event and product, and link them.""" + self.product.event_type_id = self.event_type_1 + self.event.type = self.event_type_1 + self.event.product_id = self.product + + def test_is_event_and_event_ok_forbidden(self): + """Cannot write if ``is_event`` and ``event_ok`` are ``True``.""" + with self.assertRaises(ex.EventAndTicketError): + self.product.write({ + "is_event": True, + "event_ok": True, + }) + + def test_change_used_event_product(self): + """Block changing a used event product.""" + self.product.is_event = True + self.event.product_id = self.product + with self.assertRaises(ex.ProductIsNotEventError): + self.product.is_event = False + + def test_link_normal_product_to_event(self): + """Block linking normal product to an event.""" + with self.assertRaises(ex.ProductIsNotEventError): + self.product.event_ids |= self.event + + def test_change_event_type(self): + """Block changing event type in case of conflict.""" + self.product.is_event = True + self._assign_type_and_event() + with self.assertRaises(ex.TypeMismatchError): + self.product.event_type_id = self.event_type_2 + + def test_remove_event_type(self): + """Block changing event type in case of conflict.""" + self.product.is_event = True + self._assign_type_and_event() + self.product.event_type_id = False diff --git a/event_product/views/event.xml b/event_product/views/event.xml new file mode 100644 index 000000000..42b8a3019 --- /dev/null +++ b/event_product/views/event.xml @@ -0,0 +1,20 @@ + + + + + + + + Event products + event.event + + + + + + + + + + diff --git a/event_product/views/product.xml b/event_product/views/product.xml new file mode 100644 index 000000000..3e5d8f748 --- /dev/null +++ b/event_product/views/product.xml @@ -0,0 +1,29 @@ + + + + + + + + Event products + product.template + + + + { + "invisible": [("event_ok", "=", False), + ("is_event", "=", False)], + } + + + + + + + + + + From 2c0bff63900d6fa868fe5043d458a20790731eaa Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 30 Nov 2015 10:47:22 +0100 Subject: [PATCH 02/16] Remove unused exception. --- event_product/exceptions.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/event_product/exceptions.py b/event_product/exceptions.py index da6727714..bdc115a15 100644 --- a/event_product/exceptions.py +++ b/event_product/exceptions.py @@ -25,9 +25,5 @@ class ProductIsNotEventError(EventProductValidationError): __doc__ = _("Product {} is not for events.") -class ProductEventTypeError(EventProductValidationError): - __doc__ = _("Product is already used in some event with a different type.") - - class TypeMismatchError(EventProductValidationError): __doc__ = _("Product has type {product_type}, but event has {event_type}.") From ed367b79066eb4d86ce6e7e63805392535eef66c Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 30 Nov 2015 10:47:33 +0100 Subject: [PATCH 03/16] Spell checking, updated translation. --- event_product/README.rst | 14 +++++++------- event_product/__openerp__.py | 4 ---- event_product/exceptions.py | 5 +++-- event_product/i18n/es.po | 34 ++++++++++++++++----------------- event_product/models/product.py | 2 +- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/event_product/README.rst b/event_product/README.rst index 79e509472..9aee7f2ff 100644 --- a/event_product/README.rst +++ b/event_product/README.rst @@ -6,8 +6,8 @@ Event Products ============== -This module extends the functionality of events and products to support -combining them and allow you to have a *catalog* of events that you organize. +This module extends the functionality of events and products allowing their +combination and the organization of a catalog of events. Those events in your catalog can have variants, and any event can be linked to any product as long as: @@ -67,10 +67,10 @@ To link an event to any of those variants, you need to: Known issues / Roadmap ====================== -* If you install this module, you will install *sale* too. If you do not want - to sale events, but just to handle internal ones, this can be disturbing - because you will be asked to configure accounting and you will install a lot - of dependencies. +* Installing this module will install sale too. If you do not intend to sell + events, but just handle internal ones, this can be annoying since the sale + module requires complex configuration with accounting and external + dependencies. However, this happens because this module needs the ``event_type_id`` field in products, which is added by the *event_sale* module, which installs @@ -116,4 +116,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/event_product/__openerp__.py b/event_product/__openerp__.py index 86a05cefe..b00db4744 100644 --- a/event_product/__openerp__.py +++ b/event_product/__openerp__.py @@ -12,10 +12,6 @@ "license": "AGPL-3", "application": False, "installable": True, - "external_dependencies": { - "python": [], - "bin": [], - }, "depends": [ "event_sale", ], diff --git a/event_product/exceptions.py b/event_product/exceptions.py index bdc115a15..3fad67bb8 100644 --- a/event_product/exceptions.py +++ b/event_product/exceptions.py @@ -18,7 +18,7 @@ def _message(self): class EventAndTicketError(EventProductValidationError): - __doc__ = _("It cannot be a whole event and a ticket at the same time.") + __doc__ = _("It cannot be an event and a ticket at the same time.") class ProductIsNotEventError(EventProductValidationError): @@ -26,4 +26,5 @@ class ProductIsNotEventError(EventProductValidationError): class TypeMismatchError(EventProductValidationError): - __doc__ = _("Product has type {product_type}, but event has {event_type}.") + __doc__ = _("Product has type {product_type}, whereas event has " + "{event_type}.") diff --git a/event_product/i18n/es.po b/event_product/i18n/es.po index 3422b189e..81ee5b82e 100644 --- a/event_product/i18n/es.po +++ b/event_product/i18n/es.po @@ -6,16 +6,16 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 8.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-11-27 12:27+0100\n" -"PO-Revision-Date: 2015-11-27 12:29+0100\n" +"POT-Creation-Date: 2015-11-30 09:45+0000\n" +"PO-Revision-Date: 2015-11-30 10:46+0100\n" +"Last-Translator: Jairo Llopis \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Plural-Forms: \n" +"Language: es\n" "X-Generator: Poedit 1.8.5\n" -"Last-Translator: Jairo Llopis \n" -"Language: es_ES\n" #. module: event_product #: model:ir.model,name:event_product.model_event_event @@ -30,7 +30,7 @@ msgstr "Eventos" #. module: event_product #: field:event_product.product,id:0 msgid "ID" -msgstr "" +msgstr "ID" #. module: event_product #: field:product.template,is_event:0 @@ -40,8 +40,8 @@ msgstr "Es un evento" #. module: event_product #: code:addons/event_product/exceptions.py:21 #, python-format -msgid "It cannot be a whole event and a ticket at the same time." -msgstr "No puede ser un evento entero y un ticket para eventos a la vez." +msgid "It cannot be an event and a ticket at the same time." +msgstr "No puede ser un evento y un ticket para eventos a la vez." #. module: event_product #: field:event.event,product_id:0 @@ -54,17 +54,11 @@ msgstr "Producto" msgid "Product Template" msgstr "Plantilla de producto" -#. module: event_product -#: code:addons/event_product/exceptions.py:33 -#, python-format -msgid "Product has type {product_type}, but event has {event_type}." -msgstr "El producto es de tipo {product_type}, pero el evento de typo {event_type}." - #. module: event_product #: code:addons/event_product/exceptions.py:29 #, python-format -msgid "Product is already used in some event with a different type." -msgstr "El producto ya se usa en algún evento con un tipo diferente." +msgid "Product has type {product_type}, whereas event has {event_type}." +msgstr "El producto es de tipo {product_type}, mientras que el evento es de {event_type}." #. module: event_product #: help:event.event,product_id:0 @@ -79,8 +73,8 @@ msgstr "El producto {} no es para eventos." #. module: event_product #: help:product.template,is_event:0 -msgid "This product defines a whole event (NOT an event ticket)." -msgstr "Este producto define un evento entero (NO un ticket para eventos)." +msgid "This product defines an event (NOT an event ticket)." +msgstr "Este producto define un evento (NO un ticket para eventos)." #. module: event_product #: view:product.template:event_product.product_template_form @@ -90,3 +84,7 @@ msgid "" " (\"is_event\", \"=\", False)],\n" " }" msgstr "" +"{\n" +" \"invisible\": [(\"event_ok\", \"=\", False),\n" +" (\"is_event\", \"=\", False)],\n" +" }" diff --git a/event_product/models/product.py b/event_product/models/product.py index 7f4c33c35..1cef686e3 100644 --- a/event_product/models/product.py +++ b/event_product/models/product.py @@ -36,7 +36,7 @@ class ProductTemplate(models.Model): is_event = fields.Boolean( "Is an event", - help="This product defines a whole event (NOT an event ticket).") + help="This product defines an event (NOT an event ticket).") @api.multi def onchange_event_ok(self, type, event_ok): From f360506b8973cb4446540cece3d89656d37e8b8c Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 23 Dec 2015 13:27:48 +0100 Subject: [PATCH 04/16] Correct default values for new event products. --- event_product/views/event.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/event_product/views/event.xml b/event_product/views/event.xml index 42b8a3019..dd2bd29c9 100644 --- a/event_product/views/event.xml +++ b/event_product/views/event.xml @@ -11,7 +11,9 @@ - + From 0d114c3bb806900a9350a673fff23be3ebab6d97 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 24 Dec 2015 10:32:55 +0100 Subject: [PATCH 05/16] Increase coverage and fix new bugs. - Exceptions have new messages that can be understood when raised from product views. - Exceptions support UTF-8 message formatting. - Almost all product.product tests now test product.template too. --- event_product/exceptions.py | 6 ++-- event_product/models/product.py | 6 ++++ event_product/tests/base.py | 8 ++--- event_product/tests/test_product.py | 54 +++++++++++++++++------------ 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/event_product/exceptions.py b/event_product/exceptions.py index 3fad67bb8..fcc7b6d05 100644 --- a/event_product/exceptions.py +++ b/event_product/exceptions.py @@ -2,6 +2,7 @@ # © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from __future__ import unicode_literals from openerp import _, exceptions @@ -22,9 +23,8 @@ class EventAndTicketError(EventProductValidationError): class ProductIsNotEventError(EventProductValidationError): - __doc__ = _("Product {} is not for events.") + __doc__ = _("An event is using product {}, but it is not for events.") class TypeMismatchError(EventProductValidationError): - __doc__ = _("Product has type {product_type}, whereas event has " - "{event_type}.") + __doc__ = _("Product has type {product_type}, but event has {event_type}.") diff --git a/event_product/models/product.py b/event_product/models/product.py index 1cef686e3..cb709ad0e 100644 --- a/event_product/models/product.py +++ b/event_product/models/product.py @@ -38,6 +38,12 @@ class ProductTemplate(models.Model): "Is an event", help="This product defines an event (NOT an event ticket).") + @api.multi + @api.constrains("is_event", "event_type_id") + def _check_event_type_consistent(self): + """Avoid changing type if it creates an inconsistency.""" + self.product_variant_ids._check_event_type_consistent() + @api.multi def onchange_event_ok(self, type, event_ok): """Inverse of :meth:`~._onchange_is_event`. diff --git a/event_product/tests/base.py b/event_product/tests/base.py index 46d81d68d..b5b75ea53 100644 --- a/event_product/tests/base.py +++ b/event_product/tests/base.py @@ -8,16 +8,16 @@ def setUp(self, *args, **kwargs): result = super(BaseCase, self).setUp(*args, **kwargs) self.event_type_1 = self.env["event.type"].create({ - "name": "Test event type 1", + "name": u"Test êvent type 1", }) self.event_type_2 = self.env["event.type"].create({ - "name": "Test event type 2", + "name": u"Test €vent type 2", }) self.product = self.env["product.product"].create({ - "name": "Test product 1", + "name": u"Test ṕroduct 1", }) self.event = self.env["event.event"].create({ - "name": "Test event 1", + "name": u"Test ëvent 1", "date_begin": "2015-11-26", "date_end": "2015-11-30", }) diff --git a/event_product/tests/test_product.py b/event_product/tests/test_product.py index 78ddd0e5f..ecefc3492 100644 --- a/event_product/tests/test_product.py +++ b/event_product/tests/test_product.py @@ -14,11 +14,21 @@ def setUp(self, *args, **kwargs): result = super(ProductTemplateCase, self).setUp(*args, **kwargs) self.product_new = self.env[self.model].new({ - "name": "Test product 1", + "name": u"Test pròduct 1", }) return result + def _assign_type_and_event(self): + """Assign type to event and product, and link them.""" + self.product.event_type_id = self.event_type_1 + self.event.type = self.event_type_1 + self.event.product_id = self.product + + def prod(self): + """Choose created ``product.template``.""" + return self.product.product_tmpl_id + def test_is_event_disables_event_ok(self): """Setting ``is_event`` disables ``event_ok``.""" self.product_new.event_ok = True @@ -47,45 +57,43 @@ def test_event_ok_disables_is_event(self): self.assertTrue(self.product_new.event_ok) self.assertEqual(self.product_new.type, "service") - -class ProductProductCase(ProductTemplateCase): - model = "product.product" - - def _assign_type_and_event(self): - """Assign type to event and product, and link them.""" - self.product.event_type_id = self.event_type_1 - self.event.type = self.event_type_1 - self.event.product_id = self.product - def test_is_event_and_event_ok_forbidden(self): """Cannot write if ``is_event`` and ``event_ok`` are ``True``.""" with self.assertRaises(ex.EventAndTicketError): - self.product.write({ + self.prod().write({ "is_event": True, "event_ok": True, }) def test_change_used_event_product(self): """Block changing a used event product.""" - self.product.is_event = True + self.prod().is_event = True self.event.product_id = self.product with self.assertRaises(ex.ProductIsNotEventError): - self.product.is_event = False - - def test_link_normal_product_to_event(self): - """Block linking normal product to an event.""" - with self.assertRaises(ex.ProductIsNotEventError): - self.product.event_ids |= self.event + self.prod().is_event = False def test_change_event_type(self): """Block changing event type in case of conflict.""" - self.product.is_event = True + self.prod().is_event = True self._assign_type_and_event() with self.assertRaises(ex.TypeMismatchError): - self.product.event_type_id = self.event_type_2 + self.prod().event_type_id = self.event_type_2 def test_remove_event_type(self): """Block changing event type in case of conflict.""" - self.product.is_event = True + self.prod().is_event = True self._assign_type_and_event() - self.product.event_type_id = False + self.prod().event_type_id = False + + def test_link_normal_product_to_event(self): + """Block linking normal product to an event.""" + with self.assertRaises(ex.ProductIsNotEventError): + self.product.event_ids |= self.event + + +class ProductProductCase(ProductTemplateCase): + model = "product.product" + + def prod(self): + """Choose created ``product.product``.""" + return self.product From 6315149a9049676a30c93715c6ff0e29d908ec4a Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 24 Dec 2015 11:04:56 +0100 Subject: [PATCH 06/16] Add event count button. --- event_product/models/product.py | 36 +++++++++++++++++++++++++++++ event_product/tests/test_product.py | 28 ++++++++++++++++++++++ event_product/views/product.xml | 36 ++++++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/event_product/models/product.py b/event_product/models/product.py index cb709ad0e..8542fd826 100644 --- a/event_product/models/product.py +++ b/event_product/models/product.py @@ -37,6 +37,16 @@ class ProductTemplate(models.Model): is_event = fields.Boolean( "Is an event", help="This product defines an event (NOT an event ticket).") + event_count = fields.Integer( + "Events", + compute="_compute_event_count") + + @api.multi + @api.depends("product_variant_ids.event_ids") + def _compute_event_count(self): + """Count events related with template's variants.""" + for s in self: + s.event_count = len(s.mapped("product_variant_ids.event_ids")) @api.multi @api.constrains("is_event", "event_type_id") @@ -57,6 +67,14 @@ def onchange_event_ok(self, type, event_ok): result["value"]["is_event"] = False return result + @api.multi + def action_view_events(self): + """Open events related to template's variants.""" + self.ensure_one() + action = self.env.ref("event.action_event_view").read()[0] + action["domain"] = [("product_id", "in", self.product_variant_ids.ids)] + return action + class ProductProduct(models.Model): _name = "product.product" @@ -66,6 +84,16 @@ class ProductProduct(models.Model): "event.event", "product_id", "Events") + event_count = fields.Integer( + "Events", + compute="_compute_event_count") + + @api.multi + @api.depends("event_ids") + def _compute_event_count(self): + """Count related events.""" + for s in self: + s.event_count = len(s.event_ids) @api.multi @api.constrains("is_event", "event_type_id", "event_ids") @@ -85,3 +113,11 @@ def onchange_event_ok(self, type, event_ok): result.setdefault("value", dict()) result["value"]["is_event"] = False return result + + @api.multi + def action_view_events(self): + """Open events related to product.""" + self.ensure_one() + action = self.env.ref("event.action_event_view").read()[0] + action["domain"] = [("product_id", "=", self.id)] + return action diff --git a/event_product/tests/test_product.py b/event_product/tests/test_product.py index ecefc3492..a602f58de 100644 --- a/event_product/tests/test_product.py +++ b/event_product/tests/test_product.py @@ -97,3 +97,31 @@ class ProductProductCase(ProductTemplateCase): def prod(self): """Choose created ``product.product``.""" return self.product + + def test_event_count(self): + """Event count is right in template and product.""" + # We have 2 event products + self.product.is_event = True + products = [self.product, self.product.copy()] + templates = [p.product_tmpl_id for p in products] + + # Both are variants of the same template + products[1].product_tmpl_id = products[0].product_tmpl_id + + # We have 5 events + events = [self.event.copy() for n in range(5)] + + # 3 events for first product, 2 for the second + counts = [3, 2] + for event in events[:3]: + event.product_id = products[0] + for event in events[3:]: + event.product_id = products[1] + + # Check event count per product + for n in range(2): + self.assertEqual(products[n].event_count, counts[n]) + + # Check event count per template + self.assertEqual(templates[0].event_count, 5) + self.assertEqual(templates[1].event_count, 0) diff --git a/event_product/views/product.xml b/event_product/views/product.xml index 3e5d8f748..05dbb2e4b 100644 --- a/event_product/views/product.xml +++ b/event_product/views/product.xml @@ -5,7 +5,7 @@ - + Event products product.template + + Events for this product + product.template + + + + + + + + + + + Events for this product + product.product + + + + + + + + + From acc57abd19c982c97338e239aaf2702da32999f6 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 24 Dec 2015 11:33:04 +0100 Subject: [PATCH 07/16] Update known issues/roadmap. --- event_product/README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/event_product/README.rst b/event_product/README.rst index 9aee7f2ff..0c3123641 100644 --- a/event_product/README.rst +++ b/event_product/README.rst @@ -77,6 +77,8 @@ Known issues / Roadmap *sale*; so unless Odoo divides that module in smaller parts with smaller dependencies, the only workaround is to give permissions to use *sale* to nobody. +* Support creating a sales order from the event. +* Support creating an event when confirming an event product sales order. Bug Tracker =========== From 3a7219f00416544e7a83a0d27c39d71ed8a0ca84 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Tue, 29 Dec 2015 13:11:01 +0100 Subject: [PATCH 08/16] Hide event count for non-event products. --- event_product/views/product.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/event_product/views/product.xml b/event_product/views/product.xml index 05dbb2e4b..db42fd894 100644 --- a/event_product/views/product.xml +++ b/event_product/views/product.xml @@ -34,6 +34,9 @@ + + + + + + + + + - - - - Events for this product - product.product - - - +