From 7ad11acd37b41c4e1e47c6c918bc338cde0e1a05 Mon Sep 17 00:00:00 2001 From: agb80 Date: Sat, 20 May 2017 20:28:48 -0500 Subject: [PATCH] feat(res.partner): add field birthdate_month Add field birtdate_month that allow create a new filter to display only res.partners which birthdate is on current month. --- partner_contact_birthdate/models.py | 10 ++++++++++ partner_contact_birthdate/views/res_partner.xml | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/partner_contact_birthdate/models.py b/partner_contact_birthdate/models.py index 880674ec1..8ff7330cc 100644 --- a/partner_contact_birthdate/models.py +++ b/partner_contact_birthdate/models.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from datetime import datetime + from openerp import _, api, fields, models import logging @@ -29,6 +31,10 @@ class Partner(models.Model): # New birthdate field in date format birthdate_date = fields.Date("Birthdate") + birthdate_month = fields.Char( + 'Birthdate month', compute='_birthdate_compute', store=True, + help='Helper field to get current month birthdate partners', + ) # Make the old Char field to reflect the new Date field birthdate = fields.Char( @@ -41,6 +47,10 @@ class Partner(models.Model): def _birthdate_compute(self): """Store a string of the new date in the old field.""" self.birthdate = self.birthdate_date + if self.birthdate_date: + self.birthdate_month = datetime.strptime( + self.birthdate_date, '%Y-%m-%d', + ).strftime('%m') @api.one def _birthdate_inverse(self): diff --git a/partner_contact_birthdate/views/res_partner.xml b/partner_contact_birthdate/views/res_partner.xml index d3ec7399b..2fe3307ba 100644 --- a/partner_contact_birthdate/views/res_partner.xml +++ b/partner_contact_birthdate/views/res_partner.xml @@ -15,5 +15,17 @@ + + res.partner.view.search + res.partner + + + + + + + + +