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
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"
32
34
def copy(self, cr, uid, id, default=None, context=None):
35
38
default['new_prodlot_code'] = False
36
39
return super(stock_move, self).copy(cr, uid, id, default, context=context)
39
41
def _get_prodlot_code(self, cr, uid, ids, field_name, arg, context=None):
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
45
48
def _set_prodlot_code(self, cr, uid, ids, name, value, arg, context=None):
46
50
if not value: return False
48
52
if isinstance(ids, (int, long)):
61
65
move.write({'prodlot_id' : prodlot_id})
67
def _get_tracking_code(self, cr, uid, ids, field_name, arg, context=None):
70
for move in self.browse(cr, uid, ids):
71
res[move.id] = move.tracking_id and move.tracking_id.name or False
74
def _set_tracking_code(self, cr, uid, ids, name, value, arg, context=None):
76
if not value: return False
78
if isinstance(ids, (int, long)):
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})
87
tracking_id = self.pool.get('stock.tracking').create(cr, uid, {
90
move.write({'tracking_id' : tracking_id})
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
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
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
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:
109
143
def split_move_in_single(self, cr, uid, ids, context=None):
111
146
for move_id in ids:
112
147
move = self.browse(cr, uid, move_id)
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):
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})
167
# While still enough qty to create a new move, create it
169
all_ids.append( self.copy(cr, uid, move.id, {'state': move.state, 'prodlot_id': None}) )
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}) )
124
179
_inherit = "stock.picking"
126
181
def action_assign_wkf(self, cr, uid, ids):
127
183
result = super(stock_picking, self).action_assign_wkf(cr, uid, ids)
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])
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])
153
220
def action_invoice_create(self, cursor, user, ids, journal_id=False,
154
221
group=False, type='out_invoice', context=None):
156
223
invoice_dict = super(stock_picking, self).action_invoice_create(cursor, user,
157
224
ids, journal_id, group, type, context=context)