~unifield-team/unifield-wm/us-826

426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
##############################################################################
4
#
5
#    OpenERP, Open Source Management Solution
6
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
#    Developer: Olivier DOSSMANN
8
#
9
#    This program is free software: you can redistribute it and/or modify
10
#    it under the terms of the GNU Affero General Public License as
11
#    published by the Free Software Foundation, either version 3 of the
12
#    License, or (at your option) any later version.
13
#
14
#    This program is distributed in the hope that it will be useful,
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
#    GNU Affero General Public License for more details.
18
#
19
#    You should have received a copy of the GNU Affero General Public License
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
#
22
##############################################################################
23
24
from time import strftime
634.5.3 by Olivier DOSSMANN
UF-822 [ADD] Payroll entries
25
from osv import osv
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
26
707 by jf
[FIX] Default values
27
def get_period_from_date(self, cr, uid, date=False, context=None):
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
28
    """
1349.15.1 by Olivier DOSSMANN
UTP-429 [FIX] Get right period from december instead special periods 13, 14 and 15.
29
    Get period in which this date could go into, otherwise return last open period.
30
    Do not select special periods (Period 13, 14 and 15).
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
31
    """
32
    # Some verifications
33
    if not context:
34
        context = {}
35
    if not date:
36
        return False
37
    # Search period in which this date come from
1789.3.8 by Olivier DOSSMANN
UTP-943 [FIX] Change period's field behaviour on analytic lines: display period regarding posting date
38
    period_ids = self.pool.get('account.period').search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date), ('number', '!=', 16)], limit=1, 
426.18.23 by Olivier DOSSMANN
UF-675 [FIX] Period research from a date
39
        order='date_start asc, name asc', context=context) or []
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
40
    # Get last period if no period found
41
    if not period_ids:
1789.3.8 by Olivier DOSSMANN
UTP-943 [FIX] Change period's field behaviour on analytic lines: display period regarding posting date
42
        period_ids = self.pool.get('account.period').search(cr, uid, [('state', '=', 'open'), ('number', '!=', 16)], limit=1, 
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
43
            order='date_stop desc, name desc', context=context) or []
44
    if isinstance(period_ids, (int, long)):
45
        period_ids = [period_ids]
46
    return period_ids
47
707 by jf
[FIX] Default values
48
def get_date_in_period(self, cr, uid, date=None, period_id=None, context=None):
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
49
    """
50
    Permit to return a date included in period :
51
     - if given date is included in period, return the given date
52
     - else return the date_stop of given period
53
    """
54
    if not context:
707 by jf
[FIX] Default values
55
        context = {}
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
56
    if not date or not period_id:
57
        return False
58
    period = self.pool.get('account.period').browse(cr, uid, period_id, context=context)
59
    if date < period.date_start or date > period.date_stop:
60
        return period.date_stop
61
    return date
62
634.5.3 by Olivier DOSSMANN
UF-822 [ADD] Payroll entries
63
class account_period(osv.osv):
64
    _name = 'account.period'
65
    _inherit = 'account.period'
66
726 by jf
uF-822 UF-824 [DEV] Homere interface
67
    def get_period_from_date(self, cr, uid, date=False, context=None):
634.5.3 by Olivier DOSSMANN
UF-822 [ADD] Payroll entries
68
        return get_period_from_date(self, cr, uid, date, context)
69
726 by jf
uF-822 UF-824 [DEV] Homere interface
70
    def get_date_in_period(self, cr, uid, date=None, period_id=None, context=None):
634.5.3 by Olivier DOSSMANN
UF-822 [ADD] Payroll entries
71
        return get_date_in_period(self, cr, uid, date, period_id, context)
72
73
account_period()
426.18.8 by Olivier DOSSMANN
UF-675 [ADD] Create commitment after PO approbation
74
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: