~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to sale/wizard/makesale.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id: makesale.py 1183 2005-08-23 07:43:32Z pinky $
 
6
#
 
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
 
12
# Service Company
 
13
#
 
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.
 
18
#
 
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.
 
23
#
 
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.
 
27
#
 
28
##############################################################################
 
29
 
 
30
from mx.DateTime import now
 
31
 
 
32
import wizard
 
33
import netsvc
 
34
import ir
 
35
import pooler
 
36
 
 
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" />
 
46
</form>"""
 
47
 
 
48
sale_fields = {
 
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')]},
 
54
}
 
55
 
 
56
ack_form = """<?xml version="1.0"?>
 
57
<form string="Make an order">
 
58
        <separator string="The sale order is now created" />
 
59
</form>"""
 
60
 
 
61
ack_fields = {}
 
62
 
 
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']}
 
68
 
 
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]
 
76
                ddata = {
 
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',
 
86
                        'date_order': now(),
 
87
                }
 
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})
 
92
                return {}
 
93
 
 
94
        states = {
 
95
                'init' : {
 
96
                        'actions' : [_selectPartner],
 
97
                        'result' : {'type' : 'form', 'arch' : sale_form, 'fields' : sale_fields, 'state' : [('end', 'Cancel'),('order', 'Make an order')]}
 
98
                },
 
99
                'order' : {
 
100
                        'actions' : [_makeOrder],
 
101
                        'result' : {'type' : 'form', 'arch' : ack_form, 'fields' : ack_fields, 'state' : [('end', 'Ok')]}
 
102
                }
 
103
        }
 
104
make_sale('crm.case.make_order')