1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) Copyright (C) 2011 MSF, TeMPO Consulting.
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields, osv
23
from tools.translate import _
24
import decimal_precision as dp
28
class modify_expiry_date(osv.osv_memory):
30
wizard called to confirm an action
32
_name = "modify.expiry.date"
33
_columns = {'kit_id': fields.many2one('composition.kit', string='Composition List', readonly=True),
34
'date': fields.date(string='Date', readonly=True),
35
'new_date': fields.date(string='New Date', help="When using automatic computation, if no date are found in the kit components, the default value is 01/Jan/9999."),
38
_defaults = {'kit_id': lambda s, cr, uid, c: c.get('kit_id', False),
39
'date': lambda s, cr, uid, c: c.get('date', False)}
41
def compute_date(self, cr, uid, ids, context=None):
43
compute the date from items and write it to the wizard
48
kit_obj = self.pool.get('composition.kit')
49
kit_ids = context['active_ids']
50
new_date = kit_obj._compute_expiry_date(cr, uid, kit_ids, context=context)
51
self.write(cr, uid, ids, {'new_date': new_date}, context=context)
54
def do_modify_expiry_date(self, cr, uid, ids, context=None):
56
create a purchase order line for each kit item and delete the selected kit purchase order line
58
# quick integrity check
59
assert context, 'No context defined, problem on method call'
60
if isinstance(ids, (int, long)):
63
kit_obj = self.pool.get('composition.kit')
64
kit_ids = context['active_ids']
65
for obj in self.browse(cr, uid, ids, context=context):
67
raise osv.except_osv(_('Warning !'), _('You need to specify a new date.'))
68
kit_obj.write(cr, uid, kit_ids, {'composition_exp': obj.new_date}, context=context)
70
return {'type': 'ir.actions.act_window',
71
'res_model': 'composition.kit',
73
'view_mode': 'form,tree',