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 _
28 import pos_box_entries
29 print dir(pos_box_entries)
31 class pos_box_out(osv.osv_memory):
33 _description = 'Pos Box Out'
35 def _get_expense_product(self,cr,uid,context):
38 Make the selection list of expense product.
39 @param self: The object pointer.
40 @param cr: A database cursor
41 @param uid: ID of the user currently logged in
42 @param context: A standard dictionary
43 @return :Return of operation of product
45 obj = self.pool.get('product.product')
46 company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
47 ids = obj.search(cr, uid, ['&', ('expense_pdt', '=', True), '|', ('company_id', '=', company_id), ('company_id', '=', None)])
48 res = obj.read(cr, uid, ids, ['id', 'name'], context)
49 res = [(r['id'], r['name']) for r in res]
50 res.insert(0, ('', ''))
54 'name': fields.char('Name', size=32,required=True),
55 'journal_id': fields.selection(pos_box_entries.get_journal, "Journal",required=True),
56 'product_id': fields.selection(_get_expense_product, "Operation",required=True),
57 'amount' :fields.float('Amount', digits=(16,2)),
58 'ref':fields.char('Ref', size=32),
61 'journal_id': lambda *a: 1,
62 'product_id': lambda *a: 1,
64 def get_out(self, cr, uid, ids, context):
67 Create the entries in the CashBox .
68 @param self: The object pointer.
69 @param cr: A database cursor
70 @param uid: ID of the user currently logged in
71 @param context: A standard dictionary
72 @return :Return of operation of product
75 statement_obj= self.pool.get('account.bank.statement')
76 statement_line_obj=self.pool.get('account.bank.statement.line')
77 product_obj= self.pool.get('product.template')
78 productp_obj= self.pool.get('product.product')
79 res_obj = self.pool.get('res.users')
80 for data in self.read(cr, uid, ids):
82 curr_company = res_obj.browse(cr,uid,uid).company_id.id
83 statement_id = statement_obj.search(cr,uid, [('journal_id','=',data['journal_id']),('company_id','=',curr_company),('user_id','=',uid),('state','=','open')])
84 monday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Monday,0))).strftime('%Y-%m-%d')
85 sunday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday,0))).strftime('%Y-%m-%d')
86 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)])
87 stat_done = statement_obj.browse(cr,uid, done_statmt)
88 address_u = res_obj.browse(cr,uid,uid).address_id
91 amount_check = productp_obj.browse(cr,uid,data['product_id']).am_out or False
94 if address_u and s.partner_id==address_u.partner_id and s.am_out:
96 if (-data['amount'] or 0.0)+ am <-(res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0) and amount_check:
97 val = (res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0)+ am
98 raise osv.except_osv(_('Error !'), _('The maximum value you can still withdraw is exceeded. \n Remaining value is equal to %d ')%(val))
100 acc_id = product_obj.browse(cr,uid,data['product_id']).property_account_income
102 raise osv.except_osv(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr,uid,data['product_id']).name))
104 raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox'))
106 statement_id = statement_id[0]
108 statement_id = statement_obj.create(cr,uid,{'date':time.strftime('%Y-%m-%d 00:00:00'),
109 'journal_id':data['journal_id'],
110 'company_id':curr_company,
113 args['statement_id']= statement_id
114 args['journal_id']= data['journal_id']
116 args['account_id']= acc_id.id
117 amount= data['amount'] or 0.0
118 if data['amount'] > 0:
119 amount= -data['amount']
120 args['amount'] = amount
121 if productp_obj.browse(cr,uid,data['product_id']).am_out:
122 args['am_out'] = True
123 args['ref'] = data['ref'] or ''
124 args['name'] = "%s: %s "%(product_obj.browse(cr,uid,data['product_id']).name, data['name'].decode('utf8'))
125 address_u = res_obj.browse(cr,uid,uid).address_id
127 partner_id = address_u.partner_id and address_u.partner_id.id or None
128 args['partner_id'] = partner_id
129 statement_line_id = statement_line_obj.create(cr, uid, args)