~openerprma/openerp-rma/6.0

« back to all changes in this revision

Viewing changes to crm_claim_rma/wizard/exchange_from_returned_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 in from selected return lines
 
28
class exchange_from_returned_lines(osv.osv_memory):
 
29
    _name='exchange_from_returned_lines.wizard'
 
30
    _description='Wizard to create an exchange from selected return lines'
 
31
    _columns = {
 
32
        'exchange_line_ids' : fields.many2many('temp.exchange.line', 'exchange_rel_refund', 'wizard_id', 'temp_exchange_line_id', 'Selected exchange lines'),
 
33
    }
 
34
    
 
35
    # Get selected lines to add to exchange
 
36
    def _get_selected_lines(self, cr, uid,context):
 
37
        returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['return_line_ids'])['return_line_ids'] 
 
38
        returned_lines = self.pool.get('return.line').browse(cr, uid,returned_line_ids)
 
39
        M2M = []
 
40
        for line in returned_lines:
 
41
            if line.selected:
 
42
                print "_get_selected : ",line.unit_sale_price
 
43
                M2M.append(self.pool.get('temp.exchange.line').create(cr, uid, {
 
44
                                            'name' : "#",
 
45
                                            'returned_product_id' : line.product_id.id,
 
46
                                            'returned_product_quantity' : line.product_returned_quantity,
 
47
                                            'returned_prodlot_id' : line.prodlot_id.id,
 
48
                                            'returned_unit_sale_price' : line.unit_sale_price,
 
49
                                    }))
 
50
        return M2M    
 
51
   
 
52
    _defaults = {
 
53
        'exchange_line_ids': _get_selected_lines,
 
54
    }    
 
55
 
 
56
    # If "Cancel" button pressed
 
57
    def action_cancel(self,cr,uid,ids,conect=None):
 
58
        return {'type': 'ir.actions.act_window_close',}
 
59
 
 
60
    # If "Create" button pressed
 
61
    def action_create_exchange(self, cr, uid, ids, context=None):
 
62
        for exchange in self.browse(cr, uid,ids):
 
63
            claim_id = self.pool.get('crm.claim').browse(cr, uid, context['active_id'])
 
64
            # create exchange
 
65
            for line in exchange.exchange_line_ids:
 
66
                print "for : ",line.returned_unit_sale_price
 
67
                exchange_id = self.pool.get('product.exchange').create(cr, uid, {
 
68
                                            'name' : "#",
 
69
                                            'state': 'draft',
 
70
                                            'exchange_send_date': time.strftime('%Y-%m-%d %H:%M:%S'),
 
71
                                            'returned_product' : line.returned_product_id.id,
 
72
                                            'returned_product_serial' : line.returned_prodlot_id.id,
 
73
                                            'returned_product_qty' : line.returned_product_quantity,
 
74
                                            'returned_unit_sale_price' : line.returned_unit_sale_price,
 
75
                                            'replacement_product' : line.replacement_product_id.id,
 
76
                                            'replacement_product_serial' : line.replacement_prodlot_id.id,
 
77
                                            'replacement_product_qty' : line.replacement_product_quantity,
 
78
                                            'claim_return_id' : claim_id.id                    
 
79
                                    })
 
80
 
 
81
        return {'type': 'ir.actions.act_window_close',}
 
82
                              
 
83
exchange_from_returned_lines()
 
84
 
 
85
#===== Temp exchange line
 
86
class temp_exchange_line(osv.osv_memory):
 
87
    """
 
88
    Class to handle a product exchange line
 
89
    """
 
90
    _name = "temp.exchange.line"
 
91
    _description = "List of product to exchange"
 
92
    _columns = {
 
93
        'name': fields.char('Comment', size=128, help="To describe the line product problem"),        
 
94
        'returned_product_id': fields.many2one('product.product', 'Returned product', required=True),
 
95
        'returned_product_quantity' : fields.float('Returned quantity', digits=(12,2), help="Quantity of product returned"),
 
96
        'returned_unit_sale_price' : fields.float('Unit sale price', digits=(12,2),),
 
97
        'returned_prodlot_id': fields.many2one('stock.production.lot', 'Returned serial/Lot'),
 
98
        'replacement_product_id': fields.many2one('product.product', 'Replacement product', required=True),
 
99
        'replacement_product_quantity' : fields.float('Replacement quantity', digits=(12,2), help="Replacement quantity"),
 
100
        'replacement_prodlot_id': fields.many2one('stock.production.lot', 'Replacement serial/Lot'),        
 
101
    }
 
102
    
 
103
temp_exchange_line()
 
104
 
 
105
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: