~julie-w/unifield-wm/UTP-925

« back to all changes in this revision

Viewing changes to account_tools/period.py

UF-675 [ADD] Create commitment after PO approbation

- generate a commitment from a PO that have an 'esc' or 'external' partner_type

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
25
 
 
26
def get_period_from_date(self, cr, uid, date=False, context={}):
 
27
    """
 
28
    Get period in which this date could go into, otherwise return last open period
 
29
    """
 
30
    # Some verifications
 
31
    if not context:
 
32
        context = {}
 
33
    if not date:
 
34
        return False
 
35
    # Search period in which this date come from
 
36
    period_ids = self.pool.get('account.period').search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)], limit=1, 
 
37
        order='date_stop desc, name desc', context=context) or []
 
38
    # Get last period if no period found
 
39
    if not period_ids:
 
40
        period_ids = self.pool.get('account.period').search(cr, uid, [('state', '=', 'open')], limit=1, 
 
41
            order='date_stop desc, name desc', context=context) or []
 
42
    if isinstance(period_ids, (int, long)):
 
43
        period_ids = [period_ids]
 
44
    return period_ids
 
45
 
 
46
def get_date_in_period(self, cr, uid, date=None, period_id=None, context={}):
 
47
    """
 
48
    Permit to return a date included in period :
 
49
     - if given date is included in period, return the given date
 
50
     - else return the date_stop of given period
 
51
    """
 
52
    if not context:
 
53
        context={}
 
54
    if not date or not period_id:
 
55
        return False
 
56
    period = self.pool.get('account.period').browse(cr, uid, period_id, context=context)
 
57
    if date < period.date_start or date > period.date_stop:
 
58
        return period.date_stop
 
59
    return date
 
60
 
 
61
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: