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
class make_sale(wizard.interface):
39
def _selectPartner(self, cr, uid, data, context):
40
case_obj = pooler.get_pool(cr.dbname).get('crm.case')
41
case = case_obj.read(cr, uid, data['ids'], ['partner_id'])
42
return {'partner_id': case[0]['partner_id']}
44
def _makeOrder(self, cr, uid, data, context):
45
pool = pooler.get_pool(cr.dbname)
46
purchase_obj = pool.get('purchase.order')
47
sale_obj = pool.get('sale.order')
49
shop_obj = pool.get('sale.shop')
50
shop_id = shop_obj.search(cr, uid, [])[0]
52
partner_obj = pool.get('res.partner')
53
sale_line_obj = pool.get('sale.order.line')
58
user = pool.get('res.users').browse(cr, uid, uid)
59
partner_id = user.company_id.partner_id.id
60
partner_addr = partner_obj.address_get(cr, uid, [partner_id],
61
['invoice', 'delivery', 'contact'])
62
default_pricelist = partner_obj.browse(cr, uid, partner_id,
63
context).property_product_pricelist.id
66
for purchase in purchase_obj.browse(cr, uid, data['ids']):
68
'origin': 'PO:%s' % str(purchase.name),
69
'picking_policy': 'direct',
71
'partner_id': partner_id,
72
'pricelist_id': default_pricelist,
73
'partner_invoice_id': partner_addr['invoice'],
74
'partner_order_id': partner_addr['contact'],
75
'partner_shipping_id': partner_addr['delivery'],
76
'order_policy': 'manual',
79
new_id = sale_obj.create(cr, uid, vals)
81
for line in purchase.order_line:
82
value = sale_line_obj.product_id_change(cr, uid, [], default_pricelist,
83
line.product_id.id, qty=line.product_qty, partner_id=partner_id)['value']
84
value['price_unit'] = line.price_unit
85
value['product_id'] = line.product_id.id
86
value['product_uos'] = value.get('product_uos', [False,False])[0]
87
value['product_uom_qty'] = line.product_qty
88
value['order_id'] = new_id
89
sale_line_obj.create(cr, uid, value)
95
'actions': [_makeOrder],
96
'result': {'type': 'state', 'state': 'end'}
100
make_sale('purchase.order.interco')