~openerprma/openerp-rma/6.0

« back to all changes in this revision

Viewing changes to crm_claim_rma/wizard/picking_from_exchange_lines.py

  • Committer: manu
  • Date: 2011-10-12 13:01:59 UTC
  • Revision ID: esamyn@gmail.com-20111012130159-ovdwe94br734fc06
[INIT] crm_claim_rma & product_warranty

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#########################################################################
 
3
#                                                                       #
 
4
#                                                                       #
 
5
#########################################################################
 
6
#                                                                       #
 
7
# Copyright (C) 2009-2011  Akretion, Emmanuel Samyn                     #
 
8
#                                                                       #
 
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.                                    #
 
13
#                                                                       #
 
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.                           #
 
18
#                                                                       #
 
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
#########################################################################
 
22
 
 
23
from osv import fields, osv
 
24
import pooler
 
25
import time
 
26
 
 
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'
 
31
    _columns = {
 
32
        'exchange_line_ids' : fields.many2many('temp.exchange.line', 'return_rel_exchange', 'wizard_id', 'temp_exchange_line_id', 'Selected exchange lines'),
 
33
    }
 
34
    
 
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)
 
39
        M2M = []
 
40
        for line in exchange_lines:
 
41
            if line.selected:
 
42
                M2M.append(self.pool.get('temp.exchange.line').create(cr, uid, {
 
43
                                            'name' : "#",
 
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,        
 
50
                                    }))
 
51
        return M2M    
 
52
   
 
53
    _defaults = {
 
54
        'exchange_line_ids': _get_selected_lines,
 
55
    }    
 
56
 
 
57
    # If "Cancel" button pressed
 
58
    def action_cancel(self,cr,uid,ids,conect=None):
 
59
        return {'type': 'ir.actions.act_window_close',}
 
60
 
 
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
 
66
            # create picking
 
67
            picking_id = self.pool.get('stock.picking').create(cr, uid, {
 
68
                                            'origin': "RMA/"+`claim_id.id`,
 
69
                        'type': 'out',
 
70
                        'move_type': 'one', # direct
 
71
                        'state': 'draft',
 
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',                        
 
80
                                    })
 
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 ?
 
85
                                            'priority': '0',
 
86
                                            #'create_date':
 
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,
 
94
                                            # 'tracking_id': 
 
95
                                            'picking_id': picking_id,
 
96
                                            'state': 'draft',
 
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',                        
 
103
                                    })
 
104
        view = {
 
105
            'name': 'Customer Picking OUT',
 
106
            'view_type': 'form',
 
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',
 
111
        }
 
112
        return view
 
113
                              
 
114
picking_out_from_returned_lines()
 
115
 
 
116
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: