From 2ce5fb369cf2c6dcb223ba48b6c1a45616d8b7d0 Mon Sep 17 00:00:00 2001 From: Ajay Javiya Date: Thu, 30 Apr 2020 19:39:08 +0530 Subject: [PATCH] [IMP] partner_contact_birthday: Add computed age field --- partner_contact_birthdate/README.rst | 6 ++++- partner_contact_birthdate/__manifest__.py | 1 + .../models/res_partner.py | 14 +++++++++++- .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 4 ++++ .../static/description/age.png | Bin 0 -> 97611 bytes partner_contact_birthdate/tests/__init__.py | 3 +++ .../tests/test_res_partner.py | 21 ++++++++++++++++++ .../views/res_partner.xml | 8 ++++++- 9 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 partner_contact_birthdate/static/description/age.png create mode 100644 partner_contact_birthdate/tests/__init__.py create mode 100644 partner_contact_birthdate/tests/test_res_partner.py diff --git a/partner_contact_birthdate/README.rst b/partner_contact_birthdate/README.rst index fc5b380d9..7488ceb98 100644 --- a/partner_contact_birthdate/README.rst +++ b/partner_contact_birthdate/README.rst @@ -23,12 +23,16 @@ Contact's birthdate :target: https://runbot.odoo-community.org/runbot/134/13.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| 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. +Add a computed age field on Partners + +.. image:: ../static/description/age.png + **Table of contents** .. contents:: diff --git a/partner_contact_birthdate/__manifest__.py b/partner_contact_birthdate/__manifest__.py index 07aacaf6b..d54f155f9 100644 --- a/partner_contact_birthdate/__manifest__.py +++ b/partner_contact_birthdate/__manifest__.py @@ -1,5 +1,6 @@ # Copyright 2014-2015 Grupo ESOC # Copyright 2017-Apertoso N.V. () +# Copyright 2019-2020: Druidoo () # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { diff --git a/partner_contact_birthdate/models/res_partner.py b/partner_contact_birthdate/models/res_partner.py index d98e0d665..73f866657 100644 --- a/partner_contact_birthdate/models/res_partner.py +++ b/partner_contact_birthdate/models/res_partner.py @@ -1,8 +1,11 @@ # Copyright (C) 2014-2015 Grupo ESOC # Copyright 2017-Apertoso N.V. () +# Copyright 2019-2020: Druidoo () # 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): @@ -11,3 +14,12 @@ class ResPartner(models.Model): _inherit = "res.partner" 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 diff --git a/partner_contact_birthdate/readme/CONTRIBUTORS.rst b/partner_contact_birthdate/readme/CONTRIBUTORS.rst index dc7f74d74..64b86b6b9 100644 --- a/partner_contact_birthdate/readme/CONTRIBUTORS.rst +++ b/partner_contact_birthdate/readme/CONTRIBUTORS.rst @@ -4,3 +4,4 @@ * Rudolf Schnapka * Denis Leemann * Tharathip Chaweewongphan +* Druidoo () diff --git a/partner_contact_birthdate/readme/DESCRIPTION.rst b/partner_contact_birthdate/readme/DESCRIPTION.rst index d2dba4cd6..179eeb1f7 100644 --- a/partner_contact_birthdate/readme/DESCRIPTION.rst +++ b/partner_contact_birthdate/readme/DESCRIPTION.rst @@ -1,3 +1,7 @@ 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. + +Add a computed age field on Partners + +.. image:: ../static/description/age.png diff --git a/partner_contact_birthdate/static/description/age.png b/partner_contact_birthdate/static/description/age.png new file mode 100644 index 0000000000000000000000000000000000000000..3a215b4552af423a9ab5594831d4bf4a03f5d2f0 GIT binary patch literal 97611 zcmd43WmH_-(k_eyx8N=zA!u-SPl6L%8Yj3z<8HwM3GVJL!5a7A?(WjK`|T|`@80|D z_x`$LeBUqDSZnr_s%O@$da5QN3Ucq!kcp6?prF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