Browse Source

[IMP] partner_contact_birthday: Add computed age field

14.0
Ajay Javiya 5 years ago
committed by newtratip
parent
commit
2ce5fb369c
  1. 4
      partner_contact_birthdate/README.rst
  2. 1
      partner_contact_birthdate/__manifest__.py
  3. 14
      partner_contact_birthdate/models/res_partner.py
  4. 1
      partner_contact_birthdate/readme/CONTRIBUTORS.rst
  5. 4
      partner_contact_birthdate/readme/DESCRIPTION.rst
  6. BIN
      partner_contact_birthdate/static/description/age.png
  7. 3
      partner_contact_birthdate/tests/__init__.py
  8. 21
      partner_contact_birthdate/tests/test_res_partner.py
  9. 8
      partner_contact_birthdate/views/res_partner.xml

4
partner_contact_birthdate/README.rst

@ -29,6 +29,10 @@ 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 a birthdate using a date format and allow you to benefit of a clearer API and
UI. UI.
Add a computed age field on Partners
.. image:: ../static/description/age.png
**Table of contents** **Table of contents**
.. contents:: .. contents::

1
partner_contact_birthdate/__manifest__.py

@ -1,5 +1,6 @@
# Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es> # Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>) # Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{ {

14
partner_contact_birthdate/models/res_partner.py

@ -1,8 +1,11 @@
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>) # Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
class ResPartner(models.Model): class ResPartner(models.Model):
@ -11,3 +14,12 @@ class ResPartner(models.Model):
_inherit = "res.partner" _inherit = "res.partner"
birthdate_date = fields.Date("Birthdate") birthdate_date = fields.Date("Birthdate")
age = fields.Integer(string="Age", readonly=True, compute="_compute_age")
@api.depends("birthdate_date")
def _compute_age(self):
for record in self:
age = 0
if record.birthdate_date:
age = relativedelta(fields.Date.today(), record.birthdate_date).years
record.age = age

1
partner_contact_birthdate/readme/CONTRIBUTORS.rst

@ -4,3 +4,4 @@
* Rudolf Schnapka <schnapkar@golive-saar.de> * Rudolf Schnapka <schnapkar@golive-saar.de>
* Denis Leemann <denis.leemann@camptocamp.com> * Denis Leemann <denis.leemann@camptocamp.com>
* Tharathip Chaweewongphan <tharathipc@ecosoft.co.th> * Tharathip Chaweewongphan <tharathipc@ecosoft.co.th>
* Druidoo (<https://www.druidoo.io>)

4
partner_contact_birthdate/readme/DESCRIPTION.rst

@ -1,3 +1,7 @@
This module was written to extend the functionality of Odoo to support setting 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 a birthdate using a date format and allow you to benefit of a clearer API and
UI. UI.
Add a computed age field on Partners
.. image:: ../static/description/age.png

BIN
partner_contact_birthdate/static/description/age.png

After

Width: 1211  |  Height: 582  |  Size: 95 KiB

3
partner_contact_birthdate/tests/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_res_partner

21
partner_contact_birthdate/tests/test_res_partner.py

@ -0,0 +1,21 @@
# Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from odoo import fields
from odoo.tests import common
class TestResPartner(common.TransactionCase):
def setUp(self):
super(TestResPartner, self).setUp()
self.partner_admin = self.env.ref("base.partner_admin")
self.partner_admin.write({"birthdate_date": "1991-09-05"})
def test_compute_age(self):
self.partner_admin._compute_age()
age = relativedelta(
fields.Date.today(), self.partner_admin.birthdate_date
).years
self.assertEqual(self.partner_admin.age, age)

8
partner_contact_birthdate/views/res_partner.xml

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<!-- License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). <!-- License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. -->
Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.
Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
-->
<odoo> <odoo>
<record id="view_partner_form" model="ir.ui.view"> <record id="view_partner_form" model="ir.ui.view">
<field name="name">Birthdate Date field</field> <field name="name">Birthdate Date field</field>
@ -12,6 +14,10 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group[@name='personal_information_group']"> <xpath expr="//group[@name='personal_information_group']">
<field name='birthdate_date' /> <field name='birthdate_date' />
<field
name="age"
attrs="{'invisible': [('birthdate_date', '=', False)]}"
/>
</xpath> </xpath>
</field> </field>
</record> </record>

Loading…
Cancel
Save