Browse Source

[CHG] remove useless birthdate field; changes after review; fix pylint warning; move birthdate field on the main area of the form

pull/714/head
Olivier-LAURENT 5 years ago
committed by Oihane Crucelaegui
parent
commit
31d0266e54
  1. 13
      partner_contact_birthdate/README.rst
  2. 1
      partner_contact_birthdate/__init__.py
  3. 5
      partner_contact_birthdate/__manifest__.py
  4. 10
      partner_contact_birthdate/hooks.py
  5. 19
      partner_contact_birthdate/i18n/fr.po
  6. 24
      partner_contact_birthdate/models/res_partner.py
  7. 4
      partner_contact_birthdate/tests/__init__.py
  8. 34
      partner_contact_birthdate/tests/test_birthdate.py
  9. 10
      partner_contact_birthdate/views/res_partner.xml

13
partner_contact_birthdate/README.rst

@ -13,10 +13,6 @@ 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.
@ -33,7 +29,6 @@ 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:
@ -41,13 +36,6 @@ 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
=======
@ -77,4 +65,3 @@ 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

1
partner_contact_birthdate/__init__.py

@ -2,4 +2,3 @@
# © 2017-Apertoso N.V. (<http://www.apertoso.be>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from .hooks import post_init_hook

5
partner_contact_birthdate/__manifest__.py

@ -8,14 +8,13 @@
"author": "Tecnativa,"
"Odoo Community Association (OCA)",
"category": "Customer Relationship Management",
"website": "https://www.tecnativa.com/",
"website": "https://github.com/OCA/partner-contact",
"depends": [
"partner_contact_personal_information_page",
"base",
],
"data": [
"views/res_partner.xml",
],
"post_init_hook": "post_init_hook",
"license": "AGPL-3",
'installable': True,
}

10
partner_contact_birthdate/hooks.py

@ -1,10 +0,0 @@
# -*- coding: utf-8 -*-
from odoo import SUPERUSER_ID
from odoo.api import Environment
def post_init_hook(cr, pool):
env = Environment(cr, SUPERUSER_ID, {})
env['res.partner'].search(
[('birthdate', "!=", False)])._birthdate_inverse()

19
partner_contact_birthdate/i18n/fr.po

@ -6,27 +6,24 @@
# OCA Transbot <transbot@odoo-community.org>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Project-Id-Version: Odoo Server 11.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-10 01:50+0000\n"
"PO-Revision-Date: 2017-06-10 01:50+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2016\n"
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
"POT-Creation-Date: 2019-02-11 17:43+0000\n"
"PO-Revision-Date: 2019-02-11 17:43+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"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Plural-Forms: \n"
#. module: partner_contact_birthdate
#: model:ir.model.fields,field_description:partner_contact_birthdate.field_res_partner_birthdate
#: model:ir.model.fields,field_description:partner_contact_birthdate.field_res_partner_birthdate_date
#: model:ir.model.fields,field_description:partner_contact_birthdate.field_res_users_birthdate
#: model:ir.model.fields,field_description:partner_contact_birthdate.field_res_users_birthdate_date
msgid "Birthdate"
msgstr "Date de naissance"
#. module: partner_contact_birthdate
#: model:ir.model,name:partner_contact_birthdate.model_res_partner
msgid "Partner"
msgstr "Partenaire"
msgid "Contact"
msgstr "Contact"

24
partner_contact_birthdate/models/res_partner.py

@ -1,33 +1,11 @@
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
# © 2017-Apertoso N.V. (<http://www.apertoso.be>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
import logging
_logger = logging.getLogger(__name__)
from odoo import fields, models
class ResPartner(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."""
self.birthdate_date = self.birthdate

4
partner_contact_birthdate/tests/__init__.py

@ -1,4 +0,0 @@
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
# © 2017-Apertoso N.V. (<http://www.apertoso.be>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_birthdate

34
partner_contact_birthdate/tests/test_birthdate.py

@ -1,34 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
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)})
def test_old_to_new(self):
with self.assertRaises(ValueError):
self.partner.birthdate = "Not a date"

10
partner_contact_birthdate/views/res_partner.xml

@ -6,13 +6,11 @@
<record id="view_personal_information_birthdate_date" model="ir.ui.view">
<field name="name">Birthdate Date field</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_contact_personal_information_page.personal_information"/>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[@name='personal_information_group']">
<field name="birthdate_date"/>
</xpath>
</data>
<xpath expr="//field[@name='function']" position="after">
<field name="birthdate_date" attrs="{'invisible': [('is_company', '=', True)]}"/>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save