1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
6
# Jon Chow <jon.chow@elico-corp.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
from openerp.osv import fields,osv
24
from openerp.tools.translate import _
27
class wizard_picking_tracking_line(osv.osv_memory):
28
_name = 'wizard.picking.tracking.line'
31
'name': fields.char('name', size=32),
32
'wizard_id': fields.many2one('wizard.picking.tracking', 'WPT'),
33
'qty': fields.float('Pack Quantity'),
34
'stock_move_id': fields.many2one('stock.move', 'Stock move'),
35
'product_id': fields.related('stock_move_id', 'product_id', type='many2one',relation='product.product', string='Product', readonly=True),
36
'tracking_id': fields.related('stock_move_id', 'tracking_id', type='many2one',relation='stock.tracking', string='Pack', readonly=True),
37
'product_qty': fields.related('stock_move_id', 'product_qty', type='float', string='Delivery Quantity', readonly=True),
40
def onchange_stock_move_id(self, cr, uid, ids, stock_move_id, context=None):
41
data = {'product_id': False, 'tracking_id':False, 'product_qty':0, 'qty':0 }
43
stock_move = self.pool.get('stock.move').browse(cr, uid, stock_move_id)
44
product_id = stock_move.product_id.id
45
tracking_id = stock_move.tracking_id and stock_move.tracking_id.id or False
46
product_qty = stock_move.product_qty
47
qty = not tracking_id and product_qty or 0.0
48
data.update( {'product_id':product_id, 'tracking_id':tracking_id, 'product_qty':product_qty, 'qty':qty})
49
return {'value': data}
51
wizard_picking_tracking_line()
55
class wizard_picking_tracking(osv.osv_memory):
56
_name = 'wizard.picking.tracking'
58
def _get_serial(self, cr, uid, context=None):
59
src_model = context.get('active_model')
60
src_record = self.pool.get(src_model).browse(cr, uid, context.get('active_id',False))
62
if src_model == 'stock.picking.out':
63
return src_record.partner_id.ref
64
elif src_model == 'stock.move':
65
return src_record.picking_id.partner_id.ref
70
def _get_lines(self, cr, uid, context=None):
71
src_model = context.get('active_model')
72
src_record = self.pool.get(src_model).browse(cr, uid, context.get('active_id',False))
75
if src_model == 'stock.picking.out':
77
for move in picking.move_lines:
79
'stock_move_id': move.id,
80
'product_id': move.product_id.id,
81
'product_qty': move.product_qty,
82
'tracking_id': move.tracking_id and move.tracking_id.id or False,
83
'qty': not move.tracking_id and move.product_qty or 0.0 ,
86
elif src_model == 'stock.move':
89
'stock_move_id': move.id,
90
'product_id': move.product_id.id,
91
'product_qty': move.product_qty,
92
'tracking_id': move.tracking_id and move.tracking_id.id or False,
93
'qty': not move.tracking_id and move.product_qty or 0.0 ,
99
def _get_picking(self, cr, uid, context=None):
100
src_model = context.get('active_model')
101
if src_model == 'stock.picking.out':
102
return context.get('active_id', False)
103
elif src_model == 'stock.move':
104
stock_move=self.pool.get(src_model).browse(cr, uid, context.get('active_id', False))
105
return stock_move.picking_id.id
108
def _get_pack_address(self, cr, uid, context=None):
109
src_model = context.get('active_model')
110
src_record = self.pool.get(src_model).browse(cr, uid, context.get('active_id',False))
111
if src_model == 'stock.picking.out':
112
picking_out = src_record
113
sale_order = picking_out.sale_id
114
return sale_order.partner_shipping_id and sale_order.partner_shipping_id.name or False
116
elif src_model == 'stock.move':
118
sale_order = move.picking_id.sale_id
119
return sale_order.partner_shipping_id and sale_order.partner_shipping_id.name or False
123
'name': fields.char('name', size=32, readonly=True),
124
'picking_id': fields.many2one('stock.picking','Picking'),
125
'ul_id': fields.many2one('product.ul', 'Pack Template', required=True),
126
'lines': fields.one2many('wizard.picking.tracking.line', 'wizard_id', 'Lines'),
128
'pack_address': fields.char('Address', size=128),
129
'pack_note': fields.char('Note', size=128),
130
'gross_weight': fields.float('GW (Kg)'),
131
#'net_weight': fields.float('NW (Kg)'),
135
'lines': lambda self,cr,uid,context: self._get_lines(cr, uid, context=context),
136
'picking_id': lambda self,cr,uid,context: self._get_picking(cr, uid, context=context),
137
'pack_address': lambda self,cr,uid,context: self._get_pack_address(cr, uid, context=context),
141
def _action_check(self, wizard):
142
if wizard.picking_id.state == 'done':
143
raise osv.except_osv(_('Warning!'), _("Wizard split pack can not be used when state is done !"))
144
for line in wizard.lines:
145
if line.qty > line.product_qty:
146
raise osv.except_osv(_('Warning!'), _("New pack quantity can not bigger than stock move quantity"))
150
def action_split(self, cr, uid, ids, context=None):
153
tracking_obj = self.pool.get('stock.tracking')
154
stock_move_obj = self.pool.get('stock.move')
155
procurement_obj = self.pool.get('procurement.order')
156
wizard = self.browse(cr,uid,ids[0],context=context)
157
self._action_check(wizard)
160
'ul_id': wizard.ul_id.id,
161
'pack_address': wizard.pack_address,
162
'pack_note': wizard.pack_note,
163
'gross_weight': wizard.gross_weight,
167
new_pack_id = tracking_obj.create(cr, uid, tracking_values)
169
for line in wizard.lines:
170
stock_move = line.stock_move_id
171
old_pack_id = stock_move.tracking_id and stock_move.tracking_id.id or False
176
res_product_qty = stock_move.product_qty - line.qty
179
# update old stock move count procurement count
180
stock_move_obj.write(cr, uid, stock_move.id, {'product_qty':res_product_qty})
182
procurement_id = stock_move.procurements and stock_move.procurements[0].id
185
procurement_obj.write(cr, uid, procurement_id, {'product_uos_qty':res_product_qty, 'product_qty':res_product_qty})
187
new_move_data = stock_move_obj.copy_data(cr, uid, stock_move.id, default = {
188
'product_qty': line.qty ,
189
'product_uos_qty': line.qty,
190
'tracking_id': new_pack_id,
191
'procurements': False,
193
new_move_id = stock_move_obj.create(cr, uid, new_move_data)
196
procurement_data = procurement_obj.copy_data(cr, uid, procurement_id, default = {
197
'product_uos_qty': line.qty,
198
'product_qty': line.qty,
201
new_procurement_id = procurement_obj.create(cr, uid, procurement_data)
204
#if not res_product_qty, only to change the package
205
stock_move_obj.write(cr, uid, stock_move.id, {'tracking_id':new_pack_id})
209
'name': _('Pack Split'),
212
'res_model': 'stock.picking.out',
213
'res_id': wizard.picking_id.id,
214
'type': 'ir.actions.act_window',
217
wizard_picking_tracking()
219
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'