1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools.translate import _
26 class pos_get_sale(osv.osv_memory):
27 _name = 'pos.get.sale'
28 _description = 'Get From Sale'
31 'picking_id': fields.many2one('stock.picking', 'Sale Order', domain=[('state', 'in', ('assigned', 'confirmed')), ('type', '=', 'out')], context="{'contact_display':'partner'}", required=True),
34 def sale_complete(self, cr, uid, ids, context):
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
43 this = self.browse(cr, uid, ids[0], context=context)
44 record_id = context and context.get('active_id', False)
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')
51 order = proxy_pos.browse(cr, uid, record_id, context)
53 if order.state in ('paid', 'invoiced'):
54 raise osv.except_osv(_('UserError '), _("You can't modify this order. It has already been paid"))
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
62 order = proxy_pick.write(cr, uid, [this.picking_id.id], {
63 'invoice_state': 'none',
64 'pos_order': record_id
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,
81 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: