1
# -*- coding: utf-8 -*-
2
#########################################################################
5
#########################################################################
7
# Copyright (C) 2009-2011 Akretion, Emmanuel Samyn #
9
#This program is free software: you can redistribute it and/or modify #
10
#it under the terms of the GNU General Public License as published by #
11
#the Free Software Foundation, either version 3 of the License, or #
12
#(at your option) any later version. #
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 General Public License for more details. #
19
#You should have received a copy of the GNU General Public License #
20
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
21
#########################################################################
23
from osv import fields, osv
27
# Class to create a picking out from selected exchange lines
28
class picking_out_from_returned_lines(osv.osv_memory):
29
_name='picking_out_from_exchange_lines.wizard'
30
_description='Wizard to create a picking out from selected exchange lines'
32
'exchange_line_ids' : fields.many2many('temp.exchange.line', 'return_rel_exchange', 'wizard_id', 'temp_exchange_line_id', 'Selected exchange lines'),
35
# Get selected lines to add to picking in
36
def _get_selected_lines(self, cr, uid,context):
37
exchange_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['product_exchange_ids'])['product_exchange_ids']
38
exchange_lines = self.pool.get('product.exchange').browse(cr, uid,exchange_line_ids)
40
for line in exchange_lines:
42
M2M.append(self.pool.get('temp.exchange.line').create(cr, uid, {
44
'returned_product_id' : line.returned_product.id,
45
'returned_product_quantity' : line.returned_product_qty,
46
'returned_prodlot_id' : line.returned_product_serial.id,
47
'replacement_product_id': line.replacement_product.id,
48
'replacement_product_quantity' : line.replacement_product_qty,
49
'replacement_prodlot_id': line.replacement_product_serial.id,
54
'exchange_line_ids': _get_selected_lines,
57
# If "Cancel" button pressed
58
def action_cancel(self,cr,uid,ids,conect=None):
59
return {'type': 'ir.actions.act_window_close',}
61
# If "Create" button pressed
62
def action_create_picking(self, cr, uid, ids, context=None):
63
for exchange_lines in self.browse(cr, uid,ids):
64
claim_id = self.pool.get('crm.claim').browse(cr, uid, context['active_id'])
65
partner_id = claim_id.partner_id.id
67
picking_id = self.pool.get('stock.picking').create(cr, uid, {
68
'origin': "RMA/"+`claim_id.id`,
70
'move_type': 'one', # direct
72
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
73
'address_id': claim_id.partner_address_id.id,
74
'invoice_state': "none",
75
'company_id': claim_id.company_id.id,
76
# 'stock_journal_id': fields.many2one('stock.journal','Stock Journal', select=True),
77
'location_id': self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0],
78
'location_dest_id': claim_id.partner_id.property_stock_customer.id,
79
'note' : 'RMA picking in',
81
# Create picking lines
82
for exchange_line in exchange_lines.exchange_line_ids:
83
move_id = self.pool.get('stock.move').create(cr, uid, {
84
'name' : exchange_line.replacement_product_id.name_template, # Motif : crm id ? stock_picking_id ?
87
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
88
'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
89
'product_id': exchange_line.replacement_product_id.id,
90
'product_qty': exchange_line.replacement_product_quantity,
91
'product_uom': exchange_line.replacement_product_id.uom_id.id,
92
'address_id': claim_id.partner_address_id.id,
93
'prodlot_id': exchange_line.replacement_prodlot_id,
95
'picking_id': picking_id,
97
# 'price_unit': 1.0, # to get from invoice line
98
# 'price_currency_id': claim_id.company_id.currency_id.id, # from invoice ???
99
'company_id': claim_id.company_id.id,
100
'location_id': self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0],
101
'location_dest_id': claim_id.partner_id.property_stock_customer.id,
102
'note': 'RMA Refound',
105
'name': 'Customer Picking OUT',
107
'view_mode': 'tree,form',
108
'domain' : "[('type', '=', 'out'),('partner_id','=',%s)]"%partner_id,
109
'res_model': 'stock.picking',
110
'type': 'ir.actions.act_window',
114
picking_out_from_returned_lines()
116
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: