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.DateTime import now
30
class make_sale(wizard.interface):
32
def _selectPartner(self, cr, uid, data, context):
33
case_obj = pooler.get_pool(cr.dbname).get('crm.case')
34
case = case_obj.read(cr, uid, data['ids'], ['partner_id'])
35
return {'partner_id': case[0]['partner_id']}
37
def _makeOrder(self, cr, uid, data, context):
38
pool = pooler.get_pool(cr.dbname)
39
purchase_obj = pool.get('purchase.order')
40
sale_obj = pool.get('sale.order')
42
shop_obj = pool.get('sale.shop')
43
shop_id = shop_obj.search(cr, uid, [])[0]
45
partner_obj = pool.get('res.partner')
46
sale_line_obj = pool.get('sale.order.line')
51
user = pool.get('res.users').browse(cr, uid, uid)
52
partner_id = user.company_id.partner_id.id
53
partner_addr = partner_obj.address_get(cr, uid, [partner_id],
54
['invoice', 'delivery', 'contact'])
55
default_pricelist = partner_obj.browse(cr, uid, partner_id,
56
context).property_product_pricelist.id
57
fpos = partner_obj.browse(cr, uid, partner_id,
58
context).property_account_position
59
fpos_id = fpos and fpos.id or False
61
for purchase in purchase_obj.browse(cr, uid, data['ids']):
63
'origin': 'PO:%s' % str(purchase.name),
64
'picking_policy': 'direct',
66
'partner_id': partner_id,
67
'pricelist_id': default_pricelist,
68
'partner_invoice_id': partner_addr['invoice'],
69
'partner_order_id': partner_addr['contact'],
70
'partner_shipping_id': partner_addr['delivery'],
71
'order_policy': 'manual',
73
'fiscal_position': fpos_id
75
new_id = sale_obj.create(cr, uid, vals)
76
fpos = user.company_id.partner_id.property_account_position and user.company_id.partner_id.property_account_position.id or False
77
for line in purchase.order_line:
78
value = sale_line_obj.product_id_change(cr, uid, [], default_pricelist,
79
line.product_id.id, qty=line.product_qty, partner_id=partner_id, fiscal_position=fpos)['value']
80
value['price_unit'] = line.price_unit
81
value['product_id'] = line.product_id.id
82
value['product_uos'] = value.get('product_uos', [False,False])[0]
83
value['product_uom_qty'] = line.product_qty
84
value['order_id'] = new_id
85
sale_line_obj.create(cr, uid, value)
91
'actions': [_makeOrder],
92
'result': {'type': 'state', 'state': 'end'}
96
make_sale('purchase.order.interco')
97
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: