1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-TODAY OpenERP SA (<http://openerp.com>).
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 openerp.osv import fields, osv
23 from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
25 from openerp.tools.translate import _
27 class stock_partial_move_line(osv.osv_memory):
28 _inherit = "stock.partial.picking.line"
29 _name = "stock.partial.move.line"
31 'wizard_id' : fields.many2one('stock.partial.move', string="Wizard", ondelete='CASCADE'),
34 class stock_partial_move(osv.osv_memory):
35 _name = "stock.partial.move"
36 _inherit = 'stock.partial.picking'
37 _description = "Partial Move Processing Wizard"
39 'date': fields.datetime('Date', required=True),
40 'move_ids' : fields.one2many('stock.partial.move.line', 'wizard_id', 'Moves'),
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'),
47 def default_get(self, cr, uid, fields, context=None):
48 if context is None: context = {}
51 move_ids = context.get('active_ids', [])
52 if not move_ids or not context.get('active_model') == 'stock.move':
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)
59 res.update(date=time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))
62 def do_partial(self, cr, uid, ids, context=None):
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)
67 'delivery_date' : partial.date
70 for move in partial.move_ids:
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,
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'}
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: