Browse Source

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.
pull/420/head
agb80 8 years ago
parent
commit
7ad11acd37
  1. 10
      partner_contact_birthdate/models.py
  2. 12
      partner_contact_birthdate/views/res_partner.xml

10
partner_contact_birthdate/models.py

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from openerp import _, api, fields, models from openerp import _, api, fields, models
import logging import logging
@ -29,6 +31,10 @@ class Partner(models.Model):
# New birthdate field in date format # New birthdate field in date format
birthdate_date = fields.Date("Birthdate") 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 # Make the old Char field to reflect the new Date field
birthdate = fields.Char( birthdate = fields.Char(
@ -41,6 +47,10 @@ class Partner(models.Model):
def _birthdate_compute(self): def _birthdate_compute(self):
"""Store a string of the new date in the old field.""" """Store a string of the new date in the old field."""
self.birthdate = self.birthdate_date self.birthdate = self.birthdate_date
if self.birthdate_date:
self.birthdate_month = datetime.strptime(
self.birthdate_date, '%Y-%m-%d',
).strftime('%m')
@api.one @api.one
def _birthdate_inverse(self): def _birthdate_inverse(self):

12
partner_contact_birthdate/views/res_partner.xml

@ -15,5 +15,17 @@
</field> </field>
</record> </record>
<record id="res_partner_view_search" model="ir.ui.view">
<field name="name">res.partner.view.search</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<filter string="Suppliers" position="after">
<separator/>
<filter string="This month birthdates" name="this_month_birthdates" domain="[('birthdate_month','=', context_today().strftime('%%m'))]"/>
</filter>
</field>
</record>
</data> </data>
</openerp> </openerp>
Loading…
Cancel
Save