diff --git a/partner_contact_birthdate/README.rst b/partner_contact_birthdate/README.rst new file mode 100644 index 000000000..590cd7f74 --- /dev/null +++ b/partner_contact_birthdate/README.rst @@ -0,0 +1,79 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Module name +=========== + +This module was written to extend the functionality of Odoo to support setting +a birthdate using a date format and allow you to benefit of a clearer API and +UI. + +Installation +============ + +To install this module, you need to: + +* Ensure that the current contents of the *birthdate* field in the + *res.partner* model in your database are empty or in a format easily readable + by the python function strptime_ in case you want this module to + automatically convert those to the new format. +* Install the OCA repository `partner-contact`_. +* Update your modules list. +* Search and install this module. + +Configuration +============= + +No configuration is needed. + +Usage +===== + +To use this module, you need to: + +* Edit or create a partner. +* Ensure it is **not** a company. +* Go to the *Personal Information* sheet. +* Set the birthdate there. + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 +* https://github.com/OCA/partner-contact/ + +Known issues / Roadmap +====================== + +* If you have data in your *res.partner* records' *birthdate* field that cannot + be converted to date by Pyhton's strptime_ function, those records will have + an empty *birthdate_date* after install. + +Credits +======= + +Contributors +------------ + +* EL Hadji DEM +* Jairo Llopis +* Matjaž Mozetič +* Rudolf Schnapka + +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. + + +.. _partner-contact: https://github.com/OCA/partner-contact/ +.. _strptime: https://docs.python.org/2/library/datetime.html#datetime.datetime.strptime diff --git a/partner_contact_birthdate/__init__.py b/partner_contact_birthdate/__init__.py new file mode 100644 index 000000000..3b3430c28 --- /dev/null +++ b/partner_contact_birthdate/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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/partner_contact_birthdate/__openerp__.py b/partner_contact_birthdate/__openerp__.py new file mode 100644 index 000000000..d7758ddb2 --- /dev/null +++ b/partner_contact_birthdate/__openerp__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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": "Contact's birthdate", + "version": "8.0.1.0.0", + "author": "Odoo Community Association (OCA)", + "category": "Customer Relationship Management", + "website": "https://odoo-community.org/", + "depends": [ + "partner_contact_personal_information_page", + ], + "data": [ + "views/res_partner.xml", + ], +} diff --git a/partner_contact_birthdate/data/res_partner.yml b/partner_contact_birthdate/data/res_partner.yml new file mode 100644 index 000000000..2b3d5efe9 --- /dev/null +++ b/partner_contact_birthdate/data/res_partner.yml @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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 . + +- !function {model: res.partner, name: _birthdate_install} diff --git a/partner_contact_birthdate/i18n/de.po b/partner_contact_birthdate/i18n/de.po new file mode 100644 index 000000000..fb55fa663 --- /dev/null +++ b/partner_contact_birthdate/i18n/de.po @@ -0,0 +1,37 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_contact +# +# Rudolf Schnapka , 2014. +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-20 07:17+0000\n" +"PO-Revision-Date: 2015-05-20 09:20+0100\n" +"Last-Translator: Rudolf Schnapka \n" +"Language-Team: German \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.7.6\n" + +#. module: partner_contact_birthdate +#: field:res.partner,birthdate_date:0 +msgid "Birthdate" +msgstr "Geburtsdatum" + +#. module: partner_contact_birthdate +#: code:addons/partner_contact_birthdate/models.py:52 +#, python-format +msgid "" +"Could not convert '{0.birthdate}' to date in res.partner {0.id} ({0.name}). " +"Skipping." +msgstr "" + +#. module: partner_contact_birthdate +#: model:ir.model,name:partner_contact_birthdate.model_res_partner +msgid "Partner" +msgstr "Partner" diff --git a/partner_contact_birthdate/i18n/es.po b/partner_contact_birthdate/i18n/es.po new file mode 100644 index 000000000..186164de1 --- /dev/null +++ b/partner_contact_birthdate/i18n/es.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_contact_birthdate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0-20150514\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-20 07:17+0000\n" +"PO-Revision-Date: 2015-05-20 09:21+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" +"X-Generator: Poedit 1.7.6\n" +"Language: es_ES\n" + +#. module: partner_contact_birthdate +#: field:res.partner,birthdate_date:0 +msgid "Birthdate" +msgstr "Fecha de nacimiento" + +#. module: partner_contact_birthdate +#: code:addons/partner_contact_birthdate/models.py:52 +#, python-format +msgid "" +"Could not convert '{0.birthdate}' to date in res.partner {0.id} ({0.name}). " +"Skipping." +msgstr "" +"No se pudo convertir '{0.birthdate}' en fecha en el res.partner {0.id} ({0." +"name}). Omitiéndolo." + +#. module: partner_contact_birthdate +#: model:ir.model,name:partner_contact_birthdate.model_res_partner +msgid "Partner" +msgstr "Empresa" diff --git a/partner_contact_birthdate/i18n/fr.po b/partner_contact_birthdate/i18n/fr.po new file mode 100644 index 000000000..027d1e9b6 --- /dev/null +++ b/partner_contact_birthdate/i18n/fr.po @@ -0,0 +1,36 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_contact +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-20 07:17+0000\n" +"PO-Revision-Date: 2015-05-20 09:20+0100\n" +"Last-Translator: EL Hadji DEM \n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.7.6\n" + +#. module: partner_contact_birthdate +#: field:res.partner,birthdate_date:0 +msgid "Birthdate" +msgstr "Date de naissance" + +#. module: partner_contact_birthdate +#: code:addons/partner_contact_birthdate/models.py:52 +#, python-format +msgid "" +"Could not convert '{0.birthdate}' to date in res.partner {0.id} ({0.name}). " +"Skipping." +msgstr "" + +#. module: partner_contact_birthdate +#: model:ir.model,name:partner_contact_birthdate.model_res_partner +msgid "Partner" +msgstr "Partenaire" diff --git a/partner_contact_birthdate/i18n/partner_contact_birthdate.pot b/partner_contact_birthdate/i18n/partner_contact_birthdate.pot new file mode 100644 index 000000000..cff48d4de --- /dev/null +++ b/partner_contact_birthdate/i18n/partner_contact_birthdate.pot @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_contact_birthdate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0-20150514\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-20 07:17+0000\n" +"PO-Revision-Date: 2015-05-20 07:17+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_contact_birthdate +#: field:res.partner,birthdate_date:0 +msgid "Birthdate" +msgstr "" + +#. module: partner_contact_birthdate +#: code:addons/partner_contact_birthdate/models.py:52 +#, python-format +msgid "Could not convert '{0.birthdate}' to date in res.partner {0.id} ({0.name}). Skipping." +msgstr "" + +#. module: partner_contact_birthdate +#: model:ir.model,name:partner_contact_birthdate.model_res_partner +msgid "Partner" +msgstr "" + diff --git a/partner_contact_birthdate/i18n/sl.po b/partner_contact_birthdate/i18n/sl.po new file mode 100644 index 000000000..bd5a0da26 --- /dev/null +++ b/partner_contact_birthdate/i18n/sl.po @@ -0,0 +1,37 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_contact +# +# Matjaž Mozetič , 2015. +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-05-20 07:17+0000\n" +"PO-Revision-Date: 2015-05-20 09:22+0100\n" +"Last-Translator: Matjaž Mozetič \n" +"Language-Team: Slovenian \n" +"Language: sl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.7.6\n" + +#. module: partner_contact_birthdate +#: field:res.partner,birthdate_date:0 +msgid "Birthdate" +msgstr "Rojstni datum" + +#. module: partner_contact_birthdate +#: code:addons/partner_contact_birthdate/models.py:52 +#, python-format +msgid "" +"Could not convert '{0.birthdate}' to date in res.partner {0.id} ({0.name}). " +"Skipping." +msgstr "" + +#. module: partner_contact_birthdate +#: model:ir.model,name:partner_contact_birthdate.model_res_partner +msgid "Partner" +msgstr "Partner" diff --git a/partner_contact_birthdate/models.py b/partner_contact_birthdate/models.py new file mode 100644 index 000000000..2686fed6d --- /dev/null +++ b/partner_contact_birthdate/models.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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 openerp import _, api, fields, models +import logging + + +_logger = logging.getLogger(__name__) + + +class Partner(models.Model): + """Partner with birth date in date format.""" + _inherit = "res.partner" + + # New birthdate field in date format + birthdate_date = fields.Date("Birthdate") + + # Make the old Char field to reflect the new Date field + birthdate = fields.Char( + compute="_birthdate_compute", + inverse="_birthdate_inverse", + store=True) + + @api.one + @api.depends("birthdate_date") + def _birthdate_compute(self): + """Store a string of the new date in the old field.""" + self.birthdate = self.birthdate_date + + @api.one + def _birthdate_inverse(self): + """Convert the old Char date to the new Date format.""" + try: + self.birthdate_date = self.birthdate + except ValueError: + _logger.warn( + _("Could not convert '{0.birthdate}' to date in " + "res.partner {0.id} ({0.name}). Skipping.").format(self)) + + @api.model + def _birthdate_install(self): + """Export all old birthdates to the new format.""" + self.search([('birthdate', "!=", False)])._inverse_birthdate() diff --git a/partner_contact_birthdate/static/description/icon.png b/partner_contact_birthdate/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_contact_birthdate/static/description/icon.png differ diff --git a/partner_contact_birthdate/tests/__init__.py b/partner_contact_birthdate/tests/__init__.py new file mode 100644 index 000000000..73d8cb813 --- /dev/null +++ b/partner_contact_birthdate/tests/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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_birthdate diff --git a/partner_contact_birthdate/tests/test_birthdate.py b/partner_contact_birthdate/tests/test_birthdate.py new file mode 100644 index 000000000..1782d3a40 --- /dev/null +++ b/partner_contact_birthdate/tests/test_birthdate.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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 openerp import fields +from openerp.tests.common import TransactionCase +from datetime import date + + +class GoodCase(TransactionCase): + def setUp(self): + super(GoodCase, self).setUp() + self.partner = self.env["res.partner"].create({"name": str(self)}) + self.birthdate = date.today() + + def tearDown(self): + self.assertEqual(self.partner.birthdate, self.partner.birthdate_date) + super(GoodCase, self).tearDown() + + def test_new_to_old(self): + self.partner.birthdate_date = self.birthdate + + def test_old_to_new(self): + self.partner.birthdate = fields.Date.to_string(self.birthdate) + + +class BadCase(TransactionCase): + def setUp(self): + super(BadCase, self).setUp() + self.partner = self.env["res.partner"].create({"name": str(self)}) + self.birthdate = date.today() + + def tearDown(self): + self.assertNotEqual(self.partner.birthdate, + self.partner.birthdate_date) + super(BadCase, self).tearDown() + + def test_old_to_new(self): + self.partner.birthdate = "Not a date" diff --git a/partner_contact_birthdate/views/res_partner.xml b/partner_contact_birthdate/views/res_partner.xml new file mode 100644 index 000000000..d3ec7399b --- /dev/null +++ b/partner_contact_birthdate/views/res_partner.xml @@ -0,0 +1,19 @@ + + + + + + Birthdate Date field + res.partner + + + + + + + + + + + +