1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# $Id: makesale.py 1183 2005-08-23 07:43:32Z pinky $
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
##############################################################################
30
from mx.DateTime import now
37
sale_form = """<?xml version="1.0"?>
38
<form string="Make an order">
39
<separator string="Create a sale order from this opportunity"/>
40
<field name="name" required="True" />
41
<label string="(empty for default value)" colspan="2"/>
42
<field name="shop_id" required="True" />
43
<field name="partner_id" required="True" />
44
<field name="state" required="True" />
45
<field name="picking_policy" required="True" />
49
'name' : {'string' : 'Order name', 'type': 'char'},
50
'shop_id' : {'string' : 'Shop', 'type' : 'many2one', 'relation' : 'sale.shop'},
51
'state' : {'string' : "Order's state", 'type' : 'selection', 'selection' : [('draft', 'Draft Order'), ('confirm', 'Confirm Order')]},
52
'partner_id' : {'string' : 'Partner', 'type' : 'many2one', 'relation' : 'res.partner', 'readonly':True},
53
'picking_policy': {'string': 'Picking policy', 'type': 'selection', 'selection' : [('direct','Direct Delivery'),('one','All at once')]},
56
ack_form = """<?xml version="1.0"?>
57
<form string="Make an order">
58
<separator string="The sale order is now created" />
63
class make_sale(wizard.interface):
64
def _selectPartner(self, cr, uid, data, context):
65
service = netsvc.LocalService("object_proxy")
66
case = service.execute(cr.dbname, uid, data['model'], 'read', data['ids'], ['partner_id'])
67
return {'partner_id': case[0]['partner_id']}
69
def _makeOrder(self, cr, uid, data, context):
70
case = pooler.get_pool(cr.dbname).get('crm.case')
71
sale = pooler.get_pool(cr.dbname).get('sale.order')
72
partner_addr = pooler.get_pool(cr.dbname).get('res.partner').address_get(cr, uid, [data['form']['partner_id']], ['invoice', 'delivery'])
73
pricelist = ir.ir_get(cr, uid,
74
[('meta','res.partner'), ('name','product.pricelist')],
75
[('id',str(data['form']['partner_id'])), ('uid',str(uid))])[0][2]
77
'origin': 'BO: %s' % str(data['ids'][0]),
78
'picking_policy': data['form']['picking_policy'],
79
'shop_id': data['form']['shop_id'],
80
'state': data['form']['state'],
81
'partner_id': data['form']['partner_id'],
82
'pricelist_id': pricelist,
83
'partner_invoice_id': partner_addr['invoice'],
84
'partner_shipping_id': partner_addr['delivery'],
85
'order_policy': 'manual',
88
if data['form']['name']:
89
ddata['name'] = data['form']['name']
90
nid = sale.create(cr, uid, ddata)
91
case.write(cr, uid, data['ids'], {'ref': 'sale.order,%s' % nid})
96
'actions' : [_selectPartner],
97
'result' : {'type' : 'form', 'arch' : sale_form, 'fields' : sale_fields, 'state' : [('end', 'Cancel'),('order', 'Make an order')]}
100
'actions' : [_makeOrder],
101
'result' : {'type' : 'form', 'arch' : ack_form, 'fields' : ack_fields, 'state' : [('end', 'Ok')]}
104
make_sale('crm.case.make_order')