Browse Source

[MIG] migrate to v12

pull/7/head
houssine 5 years ago
parent
commit
98f43f8e42
  1. 22
      partner_age/__manifest__.py
  2. 37
      partner_age/__openerp__.py
  3. 2
      partner_age/models/__init__.py
  4. 10
      partner_age/models/partner.py

22
partner_age/__manifest__.py

@ -0,0 +1,22 @@
# Copyright 2013-2018 Open Architects Consulting SPRL.
# Copyright 2018-Coop IT Easy SCRLfs (<http://www.coopiteasy.be>)
# - Houssine BAKKALI - <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).#
{
"name": "Partner Age",
"version": "12.0.1.0.0",
"depends": [
"easy_my_coop",
"partner_contact_birthdate"],
"author": "Houssine BAKKALI <houssine.bakkali@gmail.com>",
"category": "Cooperative management",
'website': "www.coopiteasy.be",
"license": "AGPL-3",
"description": """
This module computes the age of the partner.
""",
'data': [
'view/partner_view.xml',
],
'installable': True,
}

37
partner_age/__openerp__.py

@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013-2017 Open Architects Consulting SPRL.
# Copyright (C) 2018- Coop IT Easy SCRLfs.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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/>.
#
##############################################################################
{
"name": "Partner Age",
"version": "1.0",
"depends": [
"easy_my_coop",
"partner_contact_birthdate"],
"author": "Houssine BAKKALI <houssine.bakkali@gmail.com>",
"category": "Cooperative management",
'website': "www.coopiteasy.be",
"description": """
This module computes the age of the partner.
""",
'data': [
'view/partner_view.xml',
],
'installable': True,
}

2
partner_age/models/__init__.py

@ -1 +1 @@
from . import partner
from . import partner

10
partner_age/models/partner.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as OE_DFORMAT
@ -11,8 +10,10 @@ class ResPartner(models.Model):
def _search_age(self, operator, value):
if operator not in ('=', '!=', '<', '<=', '>', '>=', 'in', 'not in'):
return []
# retrieve all the messages that match with a specific SQL query
query = """SELECT id FROM "%s" WHERE extract(year from age(CURRENT_DATE, birthdate_date)) %s %%s""" % \
query = """SELECT id
FROM "%s"
WHERE extract(year from age(CURRENT_DATE,
birthdate_date)) %s %%s""" % \
(self._table, operator)
self.env.cr.execute(query, (value,))
ids = [t[0] for t in self.env.cr.fetchall()]
@ -22,7 +23,8 @@ class ResPartner(models.Model):
@api.depends('birthdate_date')
def _compute_age(self):
if self.birthdate_date:
dBday = datetime.strptime(self.birthdate_date, OE_DFORMAT).date()
dBday = datetime.strptime(str(self.birthdate_date),
OE_DFORMAT).date()
dToday = datetime.now().date()
self.age = dToday.year - dBday.year - ((
dToday.month, dToday.day) < (dBday.month, dBday.day))

Loading…
Cancel
Save