1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from openerp import models, fields, api
class AccountMove(models.Model):
_inherit = 'account.move'
search_year = fields.Char(
string='Year (Search)', compute='_compute_date_search',
multi='_date_search', store=True, index=True)
search_month = fields.Char(
string='Month (Search)', compute='_compute_date_search',
multi='_date_search', store=True, index=True)
search_day = fields.Char(
string='Day (Search)', compute='_compute_date_search',
multi='_date_search', store=True, index=True)
@api.multi
@api.depends('date')
def _compute_date_search(self):
date_scheme = '%Y-%m-%d'
for item in self:
if item.date:
my_date = datetime.strptime(item.date, date_scheme)
item.search_year = my_date.strftime('%Y')
item.search_month = my_date.strftime('%Y-%m')
item.search_day = my_date.strftime('%Y-%m-%d')
else:
item.search_year = False
item.search_month = False
item.search_day = False