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 ##############################################################################
23 from osv import osv,fields
24 from tools.translate import _
25 from tools.misc import UpdateableStr
26 from mx import DateTime
27 from tools.translate import _
30 def get_journal(self,cr,uid,context):
32 Make the selection list of Cash Journal .
33 @param self: The object pointer.
34 @param cr: A database cursor
35 @param uid: ID of the user currently logged in
36 @param context: A standard dictionary
37 @return :Return the list of journal
40 obj = self.pool.get('account.journal')
41 user = self.pool.get('res.users').browse(cr, uid, uid)
42 ids = obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', user.company_id.id)])
43 res = obj.read(cr, uid, ids, ['id', 'name'], context)
44 res = [(r['id'], r['name']) for r in res]
45 res.insert(0, ('', ''))
48 class pos_box_entries(osv.osv_memory):
49 _name = 'pos.box.entries'
50 _description = 'Pos Box Entries'
54 def _get_income_product(self,cr,uid,context):
57 Make the selection list of purchasing products.
58 @param self: The object pointer.
59 @param cr: A database cursor
60 @param uid: ID of the user currently logged in
61 @param context: A standard dictionary
62 @return :Return of operation of product
64 obj = self.pool.get('product.product')
65 ids = obj.search(cr, uid, [('income_pdt', '=', True)])
66 res = obj.read(cr, uid, ids, ['id', 'name'], context)
67 res = [(r['id'], r['name']) for r in res]
68 res.insert(0, ('', ''))
74 'name': fields.char('Name', size=32,required=True),
75 'journal_id': fields.selection(get_journal, "Journal",required=True),
76 'product_id': fields.selection(_get_income_product, "Operation",required=True),
77 'amount' :fields.float('Amount', digits=(16,2)),
78 'ref':fields.char('Ref', size=32),
81 'journal_id': lambda *a: 1,
82 'product_id': lambda *a: 1,
84 def get_in(self, cr, uid, ids, context):
88 Create the entry of statement in journal .
89 @param self: The object pointer.
90 @param cr: A database cursor
91 @param uid: ID of the user currently logged in
92 @param context: A standard dictionary
93 @return :Return of operation of product
95 statement_obj = self.pool.get('account.bank.statement')
96 product_obj = self.pool.get('product.template')
97 res_obj = self.pool.get('res.users')
98 product_obj=self.pool.get('product.product')
99 bank_statement=self.pool.get('account.bank.statement.line')
100 for data in self.read(cr, uid, ids):
102 curr_company = res_obj.browse(cr,uid,uid).company_id.id
103 statement_id = statement_obj.search(cr,uid, [('journal_id','=',data['journal_id']),('company_id','=',curr_company),('user_id','=',uid),('state','=','open')])
105 raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox'))
107 product = product_obj.browse(cr, uid, data['product_id'])
108 acc_id = product_obj.browse(cr,uid,data['product_id']).property_account_income
110 raise osv.except_osv(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr,uid,data['product_id']).name))
112 statement_id = statement_id[0]
114 statement_id = statement_obj.create(cr,uid,{'date':time.strftime('%Y-%m-%d 00:00:00'),
115 'journal_id':data['journal_id'],
116 'company_id':curr_company,
120 args['statement_id'] = statement_id
121 args['journal_id'] = data['journal_id']
123 args['account_id'] = acc_id.id
124 args['amount'] = data['amount'] or 0.0
125 args['ref'] = "%s" %(data['ref'] or '')
126 args['name'] = "%s: %s "% (product_obj.browse(cr,uid,data['product_id']).name, data['name'].decode('utf8'))
127 address_u = res_obj.browse(cr,uid,uid).address_id
129 partner_id = address_u.partner_id and address_u.partner_id.id or None
130 args['partner_id'] = partner_id
131 statement_line_id =bank_statement.create(cr, uid, args)