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
[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
6 years ago
committed by
Oihane Crucelaegui
9 changed files with 15 additions and 105 deletions
-
13partner_contact_birthdate/README.rst
-
1partner_contact_birthdate/__init__.py
-
5partner_contact_birthdate/__manifest__.py
-
10partner_contact_birthdate/hooks.py
-
19partner_contact_birthdate/i18n/fr.po
-
24partner_contact_birthdate/models/res_partner.py
-
4partner_contact_birthdate/tests/__init__.py
-
34partner_contact_birthdate/tests/test_birthdate.py
-
10partner_contact_birthdate/views/res_partner.xml
@ -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() |
@ -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 |
@ -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 |
@ -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" |
Write
Preview
Loading…
Cancel
Save
Reference in new issue