~sebastien.beau/openobject-addons/printjob_imrovement

« back to all changes in this revision

Viewing changes to product_serial/stock.py

  • Committer: manu
  • Date: 2011-09-09 08:08:15 UTC
  • Revision ID: esamyn@gmail.com-20110909080815-wiven5j5zddzus22
[SPLIT] mrp_prodlot_autosplit into 2 modules : product_serial & product_serial_mrp
[UPDATE] mrp_prodlot_autosplit to product_serial (bzr mv)
[ADD] product_serial the option to split the move using product logistical unit quantities
[CREATE] product_serial_mrp with mrp_prodlot_autosplit mrp code

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#    Copyright (C) 2008 Raphaël Valyi
6
6
#    Copyright (C) 2011 Anevia S.A. - Ability to group invoice lines
7
7
#              written by Alexis Demeaulte <alexis.demeaulte@anevia.com>
 
8
#    Copyright (C) 2011 Akretion - Ability to split lines on logistical units
 
9
#              written by Emmanuel Samyn
8
10
#
9
11
#    This program is free software: you can redistribute it and/or modify
10
12
#    it under the terms of the GNU Affero General Public License as
30
32
    _inherit = "stock.move"
31
33
 
32
34
    def copy(self, cr, uid, id, default=None, context=None):
 
35
        print "--> 1"
33
36
        if not default:
34
37
            default = {}
35
38
        default['new_prodlot_code'] = False
36
39
        return super(stock_move, self).copy(cr, uid, id, default, context=context)
37
40
 
38
 
 
39
41
    def _get_prodlot_code(self, cr, uid, ids, field_name, arg, context=None):
 
42
        print "--> 2"
40
43
        res = {}
41
44
        for move in self.browse(cr, uid, ids):
42
45
            res[move.id] = move.prodlot_id and move.prodlot_id.name or False
43
46
        return res
44
47
 
45
48
    def _set_prodlot_code(self, cr, uid, ids, name, value, arg, context=None):
 
49
        print "--> 3"
46
50
        if not value: return False
47
51
 
48
52
        if isinstance(ids, (int, long)):
60
64
                })
61
65
                move.write({'prodlot_id' : prodlot_id})
62
66
 
 
67
    def _get_tracking_code(self, cr, uid, ids, field_name, arg, context=None):
 
68
        print "--> 2"
 
69
        res = {}
 
70
        for move in self.browse(cr, uid, ids):
 
71
            res[move.id] = move.tracking_id and move.tracking_id.name or False
 
72
        return res
 
73
 
 
74
    def _set_tracking_code(self, cr, uid, ids, name, value, arg, context=None):
 
75
        print "--> 3"
 
76
        if not value: return False
 
77
 
 
78
        if isinstance(ids, (int, long)):
 
79
            ids = [ids]
 
80
 
 
81
        for move in self.browse(cr, uid, ids, context=context):
 
82
            product_id = move.product_id.id
 
83
            existing_tracking = move.tracking_id
 
84
            if existing_tracking: #avoid creating a tracking twice
 
85
                self.pool.get('stock.tracking').write(cr, uid, existing_tracking.id, {'name': value})
 
86
            else:
 
87
                tracking_id = self.pool.get('stock.tracking').create(cr, uid, {
 
88
                    'name': value,
 
89
                })
 
90
                move.write({'tracking_id' : tracking_id})
 
91
 
63
92
    _columns = {
64
93
        'new_prodlot_code': fields.function(_get_prodlot_code, fnct_inv=_set_prodlot_code,
65
94
                                            method=True, type='char', size=64,
66
 
                                            string='Production lot to create', select=1
 
95
                                            string='Prodlot fast input', select=1
 
96
                                           ),
 
97
        'new_tracking_code': fields.function(_get_tracking_code, fnct_inv=_set_tracking_code,
 
98
                                            method=True, type='char', size=64,
 
99
                                            string='Tracking fast input', select=1
67
100
                                           ),
68
101
    }
69
102
 
77
110
        and: b->, b->e, b->f
78
111
        The following code will detect this situation and reconnect properly the moves into only: b->a, c->e and d->f
79
112
        """
 
113
        print "--> 4"
80
114
        result = super(stock_move, self).action_done(cr, uid, ids, context)
81
115
        for move in self.browse(cr, uid, ids):
82
116
            if move.product_id.unique_production_number and move.move_dest_id and move.move_dest_id.id:
107
141
 
108
142
 
109
143
    def split_move_in_single(self, cr, uid, ids, context=None):
 
144
        print "--> 5.1"
110
145
        all_ids = ids[:]
111
146
        for move_id in ids:
112
147
            move = self.browse(cr, uid, move_id)
117
152
                qty -= 1;
118
153
        return all_ids
119
154
 
 
155
        # To split move lines depending on logistical units defined for the product
 
156
        # TO IMPROVE with 1 (or more) algo which will take into account all LU for the product
 
157
    def split_move_in_lu(self, cr, uid, ids, context=None):
 
158
        print "--> 5.2"
 
159
        all_ids = ids[:]
 
160
        for move_id in ids:
 
161
            move = self.browse(cr, uid, move_id)
 
162
            qty = move.product_qty
 
163
            lu_qty = move.product_id.packaging[0].qty
 
164
            # Set existing move to LU quantity
 
165
            self.write(cr, uid, move.id, {'product_qty': lu_qty, 'product_uos_qty': move.product_id.uos_coeff})
 
166
            qty -= lu_qty
 
167
            # While still enough qty to create a new move, create it
 
168
            while qty >= lu_qty:
 
169
                all_ids.append( self.copy(cr, uid, move.id, {'state': move.state, 'prodlot_id': None}) )
 
170
                qty -= lu_qty;
 
171
            # Create a last move for the remainder qty
 
172
            all_ids.append( self.copy(cr, uid, move.id, {'state': move.state, 'prodlot_id': None, 'product_qty':qty}) )            
 
173
        return all_ids
 
174
        
120
175
stock_move()
121
176
 
122
177
 
124
179
    _inherit = "stock.picking"
125
180
 
126
181
    def action_assign_wkf(self, cr, uid, ids):
 
182
        print "--> 6"
127
183
        result = super(stock_picking, self).action_assign_wkf(cr, uid, ids)
128
184
 
129
185
        for picking in self.browse(cr, uid, ids):
130
186
            if picking.company_id.autosplit_is_active:
131
187
                for move in picking.move_lines:
132
 
                    if move.product_id.unique_production_number and \
 
188
                    # SPLIT in single line
 
189
                    if move.product_id.lot_split_type=="single" and \
133
190
                       move.product_qty > 1 and \
134
191
                       ((move.product_id.track_production and move.location_id.usage == 'production') or \
135
192
                        (move.product_id.track_production and move.location_dest_id.usage == 'production') or \
136
193
                        (move.product_id.track_incoming and move.location_id.usage == 'supplier') or \
137
194
                        (move.product_id.track_outgoing and move.location_dest_id.usage == 'customer')):
138
195
                            self.pool.get('stock.move').split_move_in_single(cr, uid, [move.id])
 
196
                            print "--> 6.1" 
 
197
                    # SPLIT with logistical units
 
198
                    elif move.product_id.lot_split_type=="lu" and \
 
199
                       move.product_qty > 1 and move.product_id.packaging and \
 
200
                       ((move.product_id.track_production and move.location_id.usage == 'production') or \
 
201
                        (move.product_id.track_production and move.location_dest_id.usage == 'production') or \
 
202
                        (move.product_id.track_incoming and move.location_id.usage == 'supplier') or \
 
203
                        (move.product_id.track_outgoing and move.location_dest_id.usage == 'customer')):
 
204
                            self.pool.get('stock.move').split_move_in_lu(cr, uid, [move.id])
 
205
                            print "--> 6.2"                       
139
206
 
140
207
        return result
141
208
 
152
219
    # subtotal.
153
220
    def action_invoice_create(self, cursor, user, ids, journal_id=False,
154
221
        group=False, type='out_invoice', context=None):
155
 
 
 
222
        print "--> 7"
156
223
        invoice_dict = super(stock_picking, self).action_invoice_create(cursor, user,
157
224
            ids, journal_id, group, type, context=context)
158
225
 
227
294
        Instead of using dates we assume the product is in the location having the
228
295
        highest number of products with the given serial (should be 1 if no mistake). This
229
296
        is better than using move dates because moves can easily be encoded at with wrong dates."""
 
297
        print "--> 8"
230
298
        res = {}
231
299
 
232
300
        for prodlot_id in ids: