Launchpad automatic translations update.
[odoo/odoo.git] / addons / point_of_sale / wizard / pos_confirm.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 import netsvc
23 from osv import osv
24
25
26 class pos_confirm(osv.osv_memory):
27     _name = 'pos.confirm'
28     _description = 'Post POS Journal Entries'
29
30     def action_confirm(self, cr, uid, ids, context=None):
31         wf_service = netsvc.LocalService("workflow")
32         order_obj = self.pool.get('pos.order')
33         ids = order_obj.search(cr, uid, [('state','=','paid')], context=context)
34         for order in order_obj.browse(cr, uid, ids, context=context):
35             todo = True
36             for line in order.statement_ids:
37                 if line.statement_id.state <> 'confirm':
38                     todo = False
39                     break
40             if todo:
41                 wf_service.trg_validate(uid, 'pos.order', order.id, 'done', cr)
42
43         # Check if there is orders to reconcile their invoices
44         ids = order_obj.search(cr, uid, [('state','=','invoiced'),('invoice_id.state','=','open')], context=context)
45         for order in order_obj.browse(cr, uid, ids, context=context):
46             invoice = order.invoice_id
47             data_lines = [x.id for x in invoice.move_id.line_id if x.account_id.id == invoice.account_id.id]
48             for st in order.statement_ids:
49                 for move in st.move_ids:
50                     data_lines += [x.id for x in move.line_id if x.account_id.id == invoice.account_id.id]
51                     self.pool.get('account.move.line').reconcile(cr, uid, data_lines, context=context)
52         return {}
53 pos_confirm()
54
55 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
56