[FIX] pep8
[odoo/odoo.git] / addons / point_of_sale / wizard / pos_get_sale.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23 from tools.translate import _
24
25
26 class pos_get_sale(osv.osv_memory):
27     _name = 'pos.get.sale'
28     _description = 'Get From Sale'
29
30     _columns = {
31         'picking_id': fields.many2one('stock.picking', 'Sale Order', domain=[('state', 'in', ('assigned', 'confirmed')), ('type', '=', 'out')], context="{'contact_display':'partner'}", required=True),
32     }
33
34     def sale_complete(self, cr, uid, ids, context):
35         """
36              Select the picking order and add the in Point of sale order
37              @param self: The object pointer.
38              @param cr: A database cursor
39              @param uid: ID of the user currently logged in
40              @param context: A standard dictionary
41              @return : nothing
42         """
43         this = self.browse(cr, uid, ids[0], context=context)
44         record_id = context and context.get('active_id', False)
45
46         proxy_pos = self.pool.get('pos.order')
47         proxy_pick = self.pool.get('stock.picking')
48         proxy_order_line = self.pool.get('pos.order.line')
49
50         if record_id:
51             order = proxy_pos.browse(cr, uid, record_id, context)
52
53             if order.state in ('paid', 'invoiced'):
54                 raise osv.except_osv(_('UserError '), _("You can't modify this order. It has already been paid"))
55
56             for pick in proxy_pick.browse(cr, uid, [this.picking_id.id], context):
57                 proxy_pos.write(cr, uid, record_id, {
58                     'last_out_picking': this.picking_id.id,
59                     'partner_id': pick.address_id and pick.address_id.partner_id.id
60                 })
61
62             order = proxy_pick.write(cr, uid, [this.picking_id.id], {
63                 'invoice_state': 'none',
64                 'pos_order': record_id
65             })
66
67             for line in pick.move_lines:
68                 proxy_order_line.create(cr, uid, {
69                     'name': line.sale_line_id.name,
70                     'order_id': record_id,
71                     'qty': line.product_qty,
72                     'product_id': line.product_id.id,
73                     'price_unit': line.sale_line_id.price_unit,
74                     'discount': line.sale_line_id.discount,
75                 })
76
77         return {}
78
79 pos_get_sale()
80
81 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
82