forked from Yaltik/golem
Add age and area_id filter for contacts
This commit is contained in:
parent
a8807a9798
commit
34a697d5dc
@ -19,6 +19,8 @@
|
||||
""" GOLEM Members """
|
||||
|
||||
import logging
|
||||
from datetime import date, timedelta
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -85,6 +87,15 @@ class ResPartner(models.Model):
|
||||
""" GOLEM Member partner adaptations """
|
||||
_inherit = 'res.partner'
|
||||
|
||||
age = fields.Integer(compute='_compute_age', store=True)
|
||||
|
||||
@api.depends('birthdate_date')
|
||||
def _compute_age(self):
|
||||
for contact in self:
|
||||
if contact.birthdate_date:
|
||||
age = relativedelta(date.today(), fields.Date.from_string(contact.birthdate_date))
|
||||
contact.age = age.years
|
||||
|
||||
@api.model
|
||||
def _get_default_nationality_id(self):
|
||||
return self.env.ref('base.main_company').country_id
|
||||
|
@ -48,6 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
position="after">
|
||||
<field name="area_id" placeholder="Area, quarter..."
|
||||
options="{'no_create': true}" />
|
||||
<field name="age"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@ -90,6 +91,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="member_number" />
|
||||
<field name="area_id"/>
|
||||
<field name="age"/>
|
||||
</field>
|
||||
<filter name="filter_my_partners" position="before">
|
||||
<filter name="is_subscriber" string="Is Subscriber"
|
||||
@ -103,6 +106,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<separator />
|
||||
<filter name="is_service_user" string="Is Service User"
|
||||
domain="[('member_id', '!=', False)]" />
|
||||
<filter name="by_are_id" string="By Area"
|
||||
context="{'group_by': area_id}"/>
|
||||
<separator />
|
||||
</filter>
|
||||
</field>
|
||||
|
Loading…
Reference in New Issue
Block a user