[IMP] stock: added missing 'context' parameter (opw 616952)
[odoo/odoo.git] / addons / stock / wizard / stock_partial_move.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-TODAY OpenERP SA (<http://openerp.com>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import fields, osv
23 from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
24 import time
25 from openerp.tools.translate import _
26
27 class stock_partial_move_line(osv.osv_memory):
28     _inherit = "stock.partial.picking.line"
29     _name = "stock.partial.move.line"
30     _columns = {
31         'wizard_id' : fields.many2one('stock.partial.move', string="Wizard", ondelete='CASCADE'),
32     }
33
34 class stock_partial_move(osv.osv_memory):
35     _name = "stock.partial.move"
36     _inherit = 'stock.partial.picking'
37     _description = "Partial Move Processing Wizard"
38     _columns = {
39         'date': fields.datetime('Date', required=True),
40         'move_ids' : fields.one2many('stock.partial.move.line', 'wizard_id', 'Moves'),
41
42         # picking_id is not used for move processing, so we remove the required attribute
43         # from the inherited column, and ignore it
44         'picking_id': fields.many2one('stock.picking', 'Picking'),
45      }
46
47     def default_get(self, cr, uid, fields, context=None):
48         if context is None: context = {}
49         # no call to super!
50         res = {}
51         move_ids = context.get('active_ids', [])
52         if not move_ids or not context.get('active_model') == 'stock.move':
53             return res
54         if 'move_ids' in fields:
55             move_ids = self.pool.get('stock.move').browse(cr, uid, move_ids, context=context)
56             moves = [self._partial_move_for(cr, uid, m, context=context) for m in move_ids if m.state not in ('done','cancel')]
57             res.update(move_ids=moves)
58         if 'date' in fields:
59             res.update(date=time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))
60         return res
61
62     def do_partial(self, cr, uid, ids, context=None):
63         # no call to super!
64         assert len(ids) == 1, 'Partial move processing may only be done one form at a time.'
65         partial = self.browse(cr, uid, ids[0], context=context)
66         partial_data = {
67             'delivery_date' : partial.date
68         }
69         moves_ids = []
70         for move in partial.move_ids:
71             if not move.move_id:
72                 raise osv.except_osv(_('Warning !'), _("You have manually created product lines, please delete them to proceed"))
73             move_id = move.move_id.id
74             partial_data['move%s' % (move_id)] = {
75                 'product_id': move.product_id.id,
76                 'product_qty': move.quantity,
77                 'product_uom': move.product_uom.id,
78                 'prodlot_id': move.prodlot_id.id,
79             }
80             moves_ids.append(move_id)
81             if (move.move_id.picking_id.type == 'in') and (move.product_id.cost_method == 'average'):
82                 partial_data['move%s' % (move_id)].update(product_price=move.cost,
83                                                           product_currency=move.currency.id)
84         self.pool.get('stock.move').do_partial(cr, uid, moves_ids, partial_data, context=context)
85         return {'type': 'ir.actions.act_window_close'}
86
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: