~argilsoft/+junk/pexego-addons-7.0

« back to all changes in this revision

Viewing changes to restaurant_pos/wizard/pos_open_statement.py

  • Committer: Israel CA
  • Date: 2013-10-22 21:54:35 UTC
  • Revision ID: israel.cruz@hesatecnica.com-20131022215435-jo9l2iq7di64bqjn
Importación inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (C) 2004-2012 Pexego Sistemas Informáticos. All Rights Reserved
 
5
#    $Alejandro Núñez Liz$
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU General Public License as published by
 
9
#    the Free Software Foundation, either version 3 of the License, or
 
10
#    (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 General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import osv
 
23
from tools.translate import _
 
24
 
 
25
class pos_open_statement(osv.TransientModel):
 
26
    _inherit = 'pos.open.statement'
 
27
 
 
28
    def open_statement(self, cr, uid, ids, context=None):
 
29
        """
 
30
             Open the statements
 
31
             @param self: The object pointer.
 
32
             @param cr: A database cursor
 
33
             @param uid: ID of the user currently logged in
 
34
             @param context: A standard dictionary
 
35
             @return : Blank Directory
 
36
        """
 
37
        data = {}
 
38
        try:
 
39
            seccion = int(context['seccion'])
 
40
        except:
 
41
            seccion=1
 
42
        try:
 
43
            pos_user = int(context['pos_user'])
 
44
        except:
 
45
            pos_user = False
 
46
        mod_obj = self.pool.get('ir.model.data')
 
47
        statement_obj = self.pool.get('account.bank.statement')
 
48
        sequence_obj = self.pool.get('ir.sequence')
 
49
        journal_obj = self.pool.get('account.journal')
 
50
        if context is None:
 
51
            context = {}
 
52
 
 
53
        st_ids = []
 
54
        
 
55
        j_ids = journal_obj.search(cr, uid, [('journal_user','=',1),
 
56
        ('zone_id','=',seccion)], context=context)
 
57
        
 
58
        if not j_ids:
 
59
            raise osv.except_osv(_('No Cash Register Defined !'), 
 
60
            _('You must define which payment method must be available through the point of sale by reusing existing bank and cash through "Accounting > Configuration > Financial Accounting > Journals". Select a journal and check the field "PoS Payment Method" from the "Point of Sale" tab. You can also create new payment methods directly from menu "PoS Backend > Configuration > Payment Methods".'))
 
61
 
 
62
        for journal in journal_obj.browse(cr, uid, j_ids, context=context):
 
63
            ids = statement_obj.search(cr, uid, [('state', '!=', 'confirm'), 
 
64
            ('user_id', '=', uid), ('journal_id', '=', journal.id)], context=context)
 
65
            
 
66
            if journal.sequence_id:
 
67
                number = sequence_obj.next_by_id(cr, uid, journal.sequence_id.id)
 
68
            else:
 
69
                number = sequence_obj.next_by_code(cr, uid, 'account.cash.statement')
 
70
            if pos_user:                
 
71
                data.update({
 
72
                    'journal_id': journal.id,
 
73
                    'user_id': uid,
 
74
                    'state': 'draft',
 
75
                    'name': number,
 
76
                    'user_open': pos_user
 
77
                })
 
78
            else:
 
79
                data.update({
 
80
                    'journal_id': journal.id,
 
81
                    'user_id': uid,
 
82
                    'state': 'draft',
 
83
                    'name': number
 
84
                })
 
85
            statement_id = statement_obj.create(cr, uid, data, context=context)
 
86
            st_ids.append(int(statement_id))
 
87
            
 
88
            if journal.auto_cash:
 
89
                statement_obj.button_open(cr, uid, [statement_id], context)
 
90
 
 
91
        tree_res = mod_obj.get_object_reference(cr, uid, 'point_of_sale',
 
92
         'view_cash_statement_pos_tree')
 
93
        tree_id = tree_res and tree_res[1] or False
 
94
        form_res = mod_obj.get_object_reference(cr, uid, 'account',
 
95
         'view_bank_statement_form2')
 
96
        form_id = form_res and form_res[1] or False
 
97
        search_res = mod_obj.get_object_reference(cr, uid, 'account', 
 
98
        'view_account_bank_statement_filter')
 
99
        search_id = search_res and search_res[1] or False
 
100
        
 
101
        return {
 
102
            'type': 'ir.actions.act_window',
 
103
            'name': _('List of Cash Registers'),
 
104
            'view_type': 'form',
 
105
            'view_mode': 'tree,form',
 
106
            'res_model': 'account.bank.statement',
 
107
            'domain': str([('id', 'in', st_ids)]),
 
108
            'views': [(tree_id, 'tree'), (form_id, 'form')],
 
109
            'search_view_id': search_id,
 
110
        }
 
111
    
 
112
pos_open_statement()