~grzegorz-og.pl/openobject-addons/extra-5.0_account_asset

« back to all changes in this revision

Viewing changes to sale_intercompany/wizard/makesale.py

  • Committer: Fabien Pinckaers
  • Date: 2007-10-07 12:27:44 UTC
  • Revision ID: fp@tinyerp.com-158b6550adbba6dd10450dc8e84960ad9ef4b0ef
Account_Analytic_Progress
        Used for Shared Funding PRpject Tracking
Sale Intercompany
        MAnage Intercompany sales processes, work on 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
class make_sale(wizard.interface):
 
38
 
 
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']}
 
43
 
 
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')
 
48
 
 
49
                shop_obj = pool.get('sale.shop')
 
50
                shop_id = shop_obj.search(cr, uid, [])[0]
 
51
 
 
52
                partner_obj = pool.get('res.partner')
 
53
                sale_line_obj = pool.get('sale.order.line')
 
54
 
 
55
 
 
56
                new_ids = []
 
57
 
 
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
 
64
 
 
65
 
 
66
                for purchase in purchase_obj.browse(cr, uid, data['ids']):
 
67
                        vals = {
 
68
                                'origin': 'PO:%s' % str(purchase.name),
 
69
                                'picking_policy': 'direct',
 
70
                                'shop_id': shop_id,
 
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',
 
77
                                'date_order': now(),
 
78
                        }
 
79
                        new_id = sale_obj.create(cr, uid, vals)
 
80
 
 
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)
 
90
 
 
91
                return {}
 
92
 
 
93
        states = {
 
94
                'init': {
 
95
                        'actions': [_makeOrder],
 
96
                        'result': {'type': 'state', 'state': 'end'}
 
97
                }
 
98
        }
 
99
 
 
100
make_sale('purchase.order.interco')