[IMP]remove tabs and add spaces instead of them
[odoo/odoo.git] / addons / point_of_sale / wizard / pos_box_out.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 time
23 from datetime import datetime
24 from dateutil.relativedelta import relativedelta
25
26 from osv import osv, fields
27 from tools.translate import _
28 import pos_box_entries
29
30 class pos_box_out(osv.osv_memory):
31     _name = 'pos.box.out'
32     _description = 'Pos Box Out'
33
34     def _get_expense_product(self, cr, uid, context=None):
35         """
36              Make the selection list of expense product.
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 :Return of operation of product
42         """
43         product_obj = self.pool.get('product.product')
44         company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
45         ids = product_obj.search(cr, uid, ['&', ('expense_pdt', '=', True), '|', ('company_id', '=', company_id), ('company_id', '=', None)], context=context)
46         res = product_obj.read(cr, uid, ids, ['id', 'name'], context=context)
47         res = [(r['id'], r['name']) for r in res]
48         return res
49
50     _columns = {
51         'name': fields.char('Description / Reason', size=32, required=True),
52         'journal_id': fields.selection(pos_box_entries.get_journal, "Cash Register", required=True, size=-1),
53         'product_id': fields.selection(_get_expense_product, "Operation", required=True, size=-1),
54         'amount': fields.float('Amount', digits=(16, 2), required=True),
55     }
56     _defaults = {
57          'journal_id': 1,
58          'product_id': 1,
59     }
60     def get_out(self, cr, uid, ids, context=None):
61
62         """
63          Create the entries in the CashBox   .
64          @param self: The object pointer.
65          @param cr: A database cursor
66          @param uid: ID of the user currently logged in
67          @param context: A standard dictionary
68          @return :Return of operation of product
69         """
70         vals = {}
71         statement_obj = self.pool.get('account.bank.statement')
72         statement_line_obj = self.pool.get('account.bank.statement.line')
73         product_obj = self.pool.get('product.product')
74         res_obj = self.pool.get('res.users')
75         for data in  self.read(cr, uid, ids, context=context):
76             curr_company = res_obj.browse(cr, uid, uid, context=context).company_id.id
77             statement_ids = statement_obj.search(cr, uid, [('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid), ('state', '=', 'open')], context=context)
78             monday = (datetime.today() + relativedelta(weekday=0)).strftime('%Y-%m-%d')
79             sunday = (datetime.today() + relativedelta(weekday=6)).strftime('%Y-%m-%d')
80             done_statmt = statement_obj.search(cr, uid, [('date', '>=', monday+' 00:00:00'), ('date', '<=', sunday+' 23:59:59'), ('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid)], context=context)
81             stat_done = statement_obj.browse(cr, uid, done_statmt, context=context)
82             am = 0.0
83             product = product_obj.browse(cr, uid, data['product_id'], context=context)
84             acc_id = product.property_account_expense or product.categ_id.property_account_expense_categ
85             if not acc_id:
86                 raise osv.except_osv(_('Error !'), _('please check that account is set to %s')%(product.name))
87             if not statement_ids:
88                 raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox'))
89             vals['statement_id'] = statement_ids[0]
90             vals['journal_id'] = data['journal_id']
91             vals['account_id'] = acc_id.id
92             amount = data['amount'] or 0.0
93             if data['amount'] > 0:
94                 amount = -data['amount']
95             vals['amount'] = amount
96             vals['name'] = "%s: %s " % (product.name, data['name'])
97             statement_line_obj.create(cr, uid, vals, context=context)
98         return {}
99
100 pos_box_out()
101
102
103 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: