1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (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 General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
from mx import DateTime
25
from osv import fields, osv
28
class sale_order_line(osv.osv):
29
_inherit = 'sale.order.line'
31
'production_lot_id': fields.many2one('stock.production.lot', 'Production Lot',),
32
'customer_ref': fields.char('Customer reference', size=64),
36
'type': lambda *a: 'make_to_order',
39
def button_confirm(self, cr, uid, ids, context={}):
40
lines = self.pool.get('sale.order.line').browse(cr, uid, ids)
43
if line.production_lot_id:
46
production_lot_dico = {
47
'name': line.order_id and (str(line.order_id.name)+('/%02d'%(l_id,))) or False,
48
'product_id': line.product_id.id
50
production_lot_id = self.pool.get('stock.production.lot').create(cr, uid, production_lot_dico)
51
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'production_lot_id': production_lot_id})
53
super(sale_order_line, self).button_confirm(cr, uid, ids, context)
56
def copy(self, cr, uid, id, default=None, context={}):
60
'production_lot_id': False,
63
return super(sale_order_line, self).copy(cr, uid, id, default, context)
67
class sale_order(osv.osv):
69
_inherit = "sale.order"
70
_order = "create_date desc"
73
'invoice_quantity': lambda *a: 'procurement',
74
'picking_policy': lambda *a: 'direct',
75
'order_policy': lambda *a: 'picking',
78
def action_ship_create(self, cr, uid, ids, *args):
80
for order in self.browse(cr, uid, ids, context={}):
81
output_id = order.shop_id.warehouse_id.lot_output_id.id
83
for line in order.order_line:
85
date_planned = (DateTime.now() + DateTime.RelativeDateTime(days=line.delay or 0.0)).strftime('%Y-%m-%d')
86
if line.state == 'done':
88
if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'):
89
location_id = order.shop_id.warehouse_id.lot_stock_id.id
91
loc_dest_id = order.partner_id.property_stock_customer.id
92
picking_id = self.pool.get('stock.picking').create(cr, uid, {
96
'move_type': order.picking_policy,
98
'address_id': order.partner_shipping_id.id,
100
'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none',
101
'carrier_id': order.carrier_id.id,
103
move_id = self.pool.get('stock.move').create(cr, uid, {
104
'name': 'SO:' + order.name,
105
'picking_id': picking_id,
106
'product_id': line.product_id.id,
107
'date_planned': date_planned,
108
'product_qty': line.product_uom_qty,
109
'product_uom': line.product_uom.id,
110
'product_uos_qty': line.product_uos_qty,
111
'product_uos': line.product_uos.id,
112
'product_packaging': line.product_packaging.id,
113
'address_id': line.address_allotment_id.id or order.partner_shipping_id.id,
114
'location_id': location_id,
115
'location_dest_id': output_id,
116
'sale_line_id': line.id,
117
'tracking_id': False,
120
'prodlot_id': line.production_lot_id.id,
121
'customer_ref': line.customer_ref,
123
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
125
'origin': order.name,
126
'date_planned': date_planned,
127
'product_id': line.product_id.id,
128
'product_qty': line.product_uom_qty,
129
'product_uom': line.product_uom.id,
130
'location_id': order.shop_id.warehouse_id.lot_stock_id.id,
131
'procure_method': line.type,
133
'production_lot_id': line.production_lot_id.id,
134
'customer_ref': line.customer_ref,
136
wf_service = netsvc.LocalService("workflow")
137
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
138
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id})
139
elif line.product_id and line.product_id.product_tmpl_id.type == 'service':
140
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
142
'origin': order.name,
143
'date_planned': date_planned,
144
'product_id': line.product_id.id,
145
'product_qty': line.product_uom_qty,
146
'product_uom': line.product_uom.id,
147
'location_id': order.shop_id.warehouse_id.lot_stock_id.id,
148
'procure_method': line.type,
150
wf_service = netsvc.LocalService("workflow")
151
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
152
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id})
155
# No procurement because no product in the sale.order.line.
161
wf_service = netsvc.LocalService("workflow")
162
wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
163
#val = {'picking_ids':[(6,0,[picking_id])]}
165
if order.state == 'shipping_except':
166
val['state'] = 'progress'
167
if (order.order_policy == 'manual') and order.invoice_ids:
168
val['state'] = 'manual'
169
self.write(cr, uid, [order.id], val)
174
# def action_ship_create(self, cr, uid, ids, *args):
175
# result = super(sale_order, self).action_ship_create(cr, uid, ids, *args)
178
# move_obj = self.pool.get('stock.move')
179
# proc_obj = self.pool.get('mrp.procurement')
180
# for order in self.browse(cr, uid, ids, context={}):
181
# for line in order.order_line:
182
# for move in line.move_ids :
183
# mids.append(move.id)
184
# pids.extend([p.id for p in move.procurement_ids])
185
# move_obj.write(cr, uid, mids, {
186
# 'prodlot_id': line.production_lot_id.id,
187
# 'customer_ref': line.customer_ref
189
# proc_obj.write(cr, uid, pids, {
190
# 'production_lot_id': line.production_lot_id.id,
191
# 'customer_ref': line.customer_ref
197
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: