~pedro.baeza/serviciosbaeza-openerp-addons/6.1

« back to all changes in this revision

Viewing changes to sale_recurring_orders/wizard/renew_wizard.py

  • Committer: Pedro M. Baeza
  • Date: 2012-09-18 10:46:31 UTC
  • Revision ID: pedro.baeza@serviciosbaeza.com-20120918104631-4lnobl74audpyka7
Initial version adapted from 6.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (c) 2012 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) All Rights Reserved.
 
6
#                       Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> 
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import osv, fields
 
24
from tools.translate import _
 
25
 
 
26
class renew_wizard(osv.osv_memory):
 
27
 
 
28
    _name = "sale.recurring_orders.renew_wizard"
 
29
 
 
30
    def _get_renovation_date(self, cr, uid, context=None):
 
31
        """
 
32
        It returns the next expiration date of the active agreement.
 
33
        @rtype: string with date
 
34
        @return: Next expiration date of the agreement.
 
35
        """
 
36
        agreements = self.pool.get('sale.recurring_orders.agreement').browse(cr, uid, context.get('active_ids',[]), context=context)
 
37
        return agreements[0].next_expiration_date
 
38
 
 
39
    _columns = {
 
40
        'date': fields.date('Renewal date', help="Effective date of the renewal. This date is the one taken into account in the next renewal", required=True),
 
41
        'comments': fields.char('Comments', size=200, help='Renewal comments'),
 
42
    }
 
43
 
 
44
    _defaults = {
 
45
        'date': _get_renovation_date,
 
46
    }
 
47
    
 
48
    def create_renewal(self, cr, uid, ids, context=None):
 
49
        """
 
50
        It creates agreement renewal records with data given in this wizard.
 
51
        """
 
52
        if context is None: context = {}
 
53
        
 
54
        # Create agreement renewal record
 
55
        renew_wizard = self.browse(cr, uid, ids[0], context=context)
 
56
        agreement_ids = context.get('active_ids',[])
 
57
        for agreement_id in agreement_ids:
 
58
            self.pool.get('sale.recurring_orders.agreement.renewal').create(cr, uid, {
 
59
                'agreement_id': agreement_id,
 
60
                'date': renew_wizard.date,
 
61
                'comments': renew_wizard.comments,
 
62
            }, context=context)
 
63
        
 
64
        # Change last renovation date and state in agreement
 
65
        self.pool.get('sale.recurring_orders.agreement').write(cr, uid, agreement_ids, { 'last_renovation_date': renew_wizard.date, 'renewal_state': 'renewed' }, context=context)
 
66
                    
 
67
        return {'type': 'ir.actions.act_window_close'}
 
68
 
 
69
renew_wizard()
 
 
b'\\ No newline at end of file'