[IMP] point_of_sale: Convert the box_out wizard into osv_memory wizard

bzr revid: sbh@tinyerp.com-20100315063032-82jq0fglyloak8ml
This commit is contained in:
sbh (Open ERP)
2010-03-15 12:00:32 +05:30
parent 363090e959
commit bd000f7a18
7 changed files with 193 additions and 253 deletions
+1
View File
@@ -50,6 +50,7 @@ Main features :
'wizard/pos_open_statement.xml',
'wizard/pos_close_statement.xml',
'wizard/pos_box_entries.xml',
'wizard/pos_box_out.xml',
'pos_view.xml',
'pos_sequence.xml',
'posrule_data.xml',
+4 -4
View File
@@ -844,17 +844,17 @@ invoiced
string="Refloat"
action="action_box_entries"
id="menu_wizard_enter_jrnl" sequence="3" />
<wizard
<!-- <wizard
string="Enter negative operations"
model="account.bank.statement"
name="pos.out"
menu="False"
id="pos_entries2"/>
id="pos_entries2"/>-->
<menuitem
name="Output Operations" parent="menu_point_config"
string="Refloat"
action="pos_entries2"
type="wizard"
action="action_box_out"
id="menu_wizard_enter_jrnl2" sequence="3" />
<!-- <menuitem name="Sales Waiting Validation" parent="menu_point_config" id="menu_point_ofsale_date_payment"-->
+1 -1
View File
@@ -22,7 +22,6 @@
import wizard_pos_payment
import wizard_default_journal
import wizard_refund_order
import wizard_scan_product
import wizard_receipt
import wizard_return
@@ -42,5 +41,6 @@ import pos_get_sale
import pos_open_statement
import pos_close_statement
import pos_box_entries
import pos_box_out
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+17 -16
View File
@@ -26,28 +26,29 @@ from tools.misc import UpdateableStr
from mx import DateTime
from tools.translate import _
class pos_box_entries(osv.osv_memory):
_name = 'pos.box.entries'
_description = 'Pos Box Entries'
def _get_journal(self,cr,uid,context):
"""
def get_journal(self,cr,uid,context):
"""
@summary: Make the selection list of Cash Journal .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return :Return the list of journal
"""
"""
obj = self.pool.get('account.journal')
user = self.pool.get('res.users').browse(cr, uid, uid)
ids = obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', user.company_id.id)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
obj = self.pool.get('account.journal')
user = self.pool.get('res.users').browse(cr, uid, uid)
ids = obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', user.company_id.id)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
class pos_box_entries(osv.osv_memory):
_name = 'pos.box.entries'
_description = 'Pos Box Entries'
def _get_income_product(self,cr,uid,context):
@@ -70,7 +71,7 @@ class pos_box_entries(osv.osv_memory):
_columns = {
'name': fields.char('Name', size=32,required=True),
'journal_id': fields.selection(_get_journal, "Journal",required=True),
'journal_id': fields.selection(get_journal, "Journal",required=True),
'product_id': fields.selection(_get_income_product, "Operation",required=True),
'amount' :fields.float('Amount', digits=(16,2)),
'ref':fields.char('Ref', size=32),
+132
View File
@@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import netsvc
from osv import osv,fields
from tools.translate import _
from tools.misc import UpdateableStr
from mx import DateTime
from tools.translate import _
import pos_box_entries
print dir(pos_box_entries)
class pos_box_out(osv.osv_memory):
_name = 'pos.box.out'
_description = 'Pos Box Out'
def _get_expense_product(self,cr,uid,context):
"""
@summary: Make the selection list of expense product.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return :Return of operation of product
"""
obj = self.pool.get('product.product')
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
ids = obj.search(cr, uid, ['&', ('expense_pdt', '=', True), '|', ('company_id', '=', company_id), ('company_id', '=', None)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
_columns = {
'name': fields.char('Name', size=32,required=True),
'journal_id': fields.selection(pos_box_entries.get_journal, "Journal",required=True),
'product_id': fields.selection(_get_expense_product, "Operation",required=True),
'amount' :fields.float('Amount', digits=(16,2)),
'ref':fields.char('Ref', size=32),
}
_defaults = {
'journal_id': lambda *a: 1,
'product_id': lambda *a: 1,
}
def get_out(self, cr, uid, ids, context):
"""
@summary: Create the entries in the CashBox .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return :Return of operation of product
"""
args = {}
statement_obj= self.pool.get('account.bank.statement')
statement_line_obj=self.pool.get('account.bank.statement.line')
product_obj= self.pool.get('product.template')
productp_obj= self.pool.get('product.product')
res_obj = self.pool.get('res.users')
for data in self.read(cr, uid, ids):
curr_company = res_obj.browse(cr,uid,uid).company_id.id
statement_id = statement_obj.search(cr,uid, [('journal_id','=',data['journal_id']),('company_id','=',curr_company),('user_id','=',uid),('state','=','open')])
monday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Monday,0))).strftime('%Y-%m-%d')
sunday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday,0))).strftime('%Y-%m-%d')
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)])
stat_done = statement_obj.browse(cr,uid, done_statmt)
address_u = res_obj.browse(cr,uid,uid).address_id
am = 0.0
amount_check = productp_obj.browse(cr,uid,data['product_id']).am_out or False
for st in stat_done:
for s in st.line_ids:
if address_u and s.partner_id==address_u.partner_id and s.am_out:
am+=s.amount
if (-data['amount'] or 0.0)+ am <-(res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0) and amount_check:
val = (res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0)+ am
raise osv.except_osv(_('Error !'), _('The maximum value you can still withdraw is exceeded. \n Remaining value is equal to %d ')%(val))
acc_id = product_obj.browse(cr,uid,data['product_id']).property_account_income
if not acc_id:
raise osv.except_osv(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr,uid,data['product_id']).name))
if not statement_id:
raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox'))
if statement_id:
statement_id = statement_id[0]
if not statement_id:
statement_id = statement_obj.create(cr,uid,{'date':time.strftime('%Y-%m-%d 00:00:00'),
'journal_id':data['journal_id'],
'company_id':curr_company,
'user_id':uid,
})
args['statement_id']= statement_id
args['journal_id']= data['journal_id']
if acc_id:
args['account_id']= acc_id.id
amount= data['amount'] or 0.0
if data['amount'] > 0:
amount= -data['amount']
args['amount'] = amount
if productp_obj.browse(cr,uid,data['product_id']).am_out:
args['am_out'] = True
args['ref'] = data['ref'] or ''
args['name'] = "%s: %s "%(product_obj.browse(cr,uid,data['product_id']).name, data['name'].decode('utf8'))
address_u = res_obj.browse(cr,uid,uid).address_id
if address_u:
partner_id = address_u.partner_id and address_u.partner_id.id or None
args['partner_id'] = partner_id
statement_line_id = statement_line_obj.create(cr, uid, args)
return {}
pos_box_out()
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Box Entries -->
<record id="view_pos_box_out" model="ir.ui.view">
<field name="name">Box Out</field>
<field name="model">pos.box.out</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Sortie de caisse">
<separator string="Please fill these fields for entries to the box:" colspan="4"/>
<field name="name"/>
<field name="journal_id"/>
<field name="product_id"/>
<field name="amount"/>
<field name="ref"/>
<group colspan="4" col="2">
<button icon='gtk-cancel' special="cancel"
string="Close" />
<button name="get_out" string="Make Entries in the CashBox"
colspan="1" type="object" icon="gtk-ok" />
</group>
</form>
</field>
</record>
<record id="action_box_out" model="ir.actions.act_window">
<field name="name">Box Out</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">pos.box.out</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
@@ -1,232 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import netsvc
from tools.misc import UpdateableStr
import wizard
import pooler
from mx import DateTime
from tools.translate import _
entry_form = '''<?xml version="1.0"?>
<form string="%s">
<separator string="Please fill these fields for entries to the box:" colspan="4"/>
<newline/>
<field name="name"/>
<field name="ref"/>
<field name="journal_id"/>
<field name="amount"/>
<field name="product_id"/>
</form>
'''
def _get_journal(self,cr,uid,context):
pool = pooler.get_pool(cr.dbname)
obj = pool.get('account.journal')
user = pool.get('res.users').browse(cr, uid, uid)
ids = obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', user.company_id.id)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
def _get_pdt(self,cr,uid,context):
pool = pooler.get_pool(cr.dbname)
obj = pool.get('product.product')
ids = obj.search(cr, uid, [('income_pdt', '=', True)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
def _get_pdt_exp(self,cr,uid,context):
pool = pooler.get_pool(cr.dbname)
obj = pool.get('product.product')
company_id = pool.get('res.users').browse(cr, uid, uid).company_id.id
ids = obj.search(cr, uid, ['&', ('expense_pdt', '=', True), '|', ('company_id', '=', company_id), ('company_id', '=', None)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
#entry_fields = {
# 'journal_id': {'string': 'Journal', 'type': 'selection', 'selection': _get_journal, 'required':True},
# 'product_id': {'string': 'Operation', 'type': 'selection', 'selection':_get_pdt , 'required':True},
# 'amount': {'string': 'Amount', 'type': 'float'},
# 'name': {'string': 'Name', 'type': 'char', 'size': '32', 'required':True},
# 'ref': {'string': 'Ref.', 'type': 'char', 'size': '32'},
#
#}
out_fields = {
'journal_id': {'string': 'Journal', 'type': 'selection', 'selection': _get_journal, 'required':True},
'product_id': {'string': 'Operation', 'type': 'selection', 'selection':_get_pdt_exp , 'required':True},
'amount': {'string': 'Amount', 'type': 'float'},
'name': {'string': 'Name', 'type': 'char', 'size': '32', 'required':True},
'ref': {'string': 'Ref.', 'type': 'char', 'size': '32'},
}
def _get_out(self, cr, uid, data, context):
args = {}
pool = pooler.get_pool(cr.dbname)
statement_obj= pool.get('account.bank.statement')
product_obj= pool.get('product.template')
productp_obj= pool.get('product.product')
res_obj = pool.get('res.users')
curr_company = res_obj.browse(cr,uid,uid).company_id.id
statement_id = statement_obj.search(cr,uid, [('journal_id','=',data['form']['journal_id']),('company_id','=',curr_company),('user_id','=',uid),('state','=','open')])
monday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Monday,0))).strftime('%Y-%m-%d')
sunday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday,0))).strftime('%Y-%m-%d')
done_statmt = statement_obj.search(cr,uid, [('date','>=',monday+' 00:00:00'),('date','<=',sunday+' 23:59:59'),('journal_id','=',data['form']['journal_id']),('company_id','=',curr_company),('user_id','=',uid)])
stat_done = statement_obj.browse(cr,uid, done_statmt)
address_u = pool.get('res.users').browse(cr,uid,uid).address_id
am = 0.0
amount_check = productp_obj.browse(cr,uid,data['form']['product_id']).am_out or False
for st in stat_done:
for s in st.line_ids:
if address_u and s.partner_id==address_u.partner_id and s.am_out:
am+=s.amount
if (-data['form']['amount'] or 0.0)+ am <-(res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0) and amount_check:
val = (res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0)+ am
raise wizard.except_wizard(_('Error !'), _('The maximum value you can still withdraw is exceeded. \n Remaining value is equal to %d ')%(val))
acc_id = product_obj.browse(cr,uid,data['form']['product_id']).property_account_income
if not acc_id:
raise wizard.except_wizard(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr,uid,data['form']['product_id']).name))
if not statement_id:
raise wizard.except_wizard(_('Error !'), _('You have to open at least one cashbox'))
if statement_id:
statement_id = statement_id[0]
if not statement_id:
statement_id = statement_obj.create(cr,uid,{'date':time.strftime('%Y-%m-%d 00:00:00'),
'journal_id':data['form']['journal_id'],
'company_id':curr_company,
'user_id':uid,
})
args['statement_id']= statement_id
args['journal_id']= data['form']['journal_id']
if acc_id:
args['account_id']= acc_id.id
amount= data['form']['amount'] or 0.0
if data['form']['amount'] > 0:
amount= -data['form']['amount']
args['amount'] = amount
if productp_obj.browse(cr,uid,data['form']['product_id']).am_out:
args['am_out'] = True
args['ref'] = data['form']['ref'] or ''
args['name'] = "%s: %s "%(product_obj.browse(cr,uid,data['form']['product_id']).name, data['form']['name'].decode('utf8'))
address_u = pool.get('res.users').browse(cr,uid,uid).address_id
if address_u:
partner_id = address_u.partner_id and address_u.partner_id.id or None
args['partner_id'] = partner_id
statement_line_id = pool.get('account.bank.statement.line').create(cr, uid, args)
return {}
#def _get_in(self, cr, uid, data, context):
# args = {}
# pool = pooler.get_pool(cr.dbname)
# statement_obj = pool.get('account.bank.statement')
# product_obj = pool.get('product.template')
# res_obj = pool.get('res.users')
# curr_company = res_obj.browse(cr,uid,uid).company_id.id
# statement_id = statement_obj.search(cr,uid, [('journal_id','=',data['form']['journal_id']),('company_id','=',curr_company),('user_id','=',uid),('state','=','open')])
# if not statement_id:
# raise wizard.except_wizard(_('Error !'), _('You have to open at least one cashbox'))
#
# product = pool.get('product.product').browse(cr, uid, data['form']['product_id'])
# acc_id = product_obj.browse(cr,uid,data['form']['product_id']).property_account_income
# if not acc_id:
# raise wizard.except_wizard(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr,uid,data['form']['product_id']).name))
# if statement_id:
# statement_id = statement_id[0]
# if not statement_id:
# statement_id = statement_obj.create(cr,uid,{'date':time.strftime('%Y-%m-%d 00:00:00'),
# 'journal_id':data['form']['journal_id'],
# 'company_id':curr_company,
# 'user_id':uid,
# })
#
# args['statement_id'] = statement_id
# args['journal_id'] = data['form']['journal_id']
# if acc_id:
# args['account_id'] = acc_id.id
# args['amount'] = data['form']['amount'] or 0.0
# args['ref'] = "%s" %(data['form']['ref'] or '')
# args['name'] = "%s: %s "% (product_obj.browse(cr,uid,data['form']['product_id']).name, data['form']['name'].decode('utf8'))
# address_u = pool.get('res.users').browse(cr,uid,uid).address_id
# if address_u:
# partner_id = address_u.partner_id and address_u.partner_id.id or None
# args['partner_id'] = partner_id
# statement_line_id = pool.get('account.bank.statement.line').create(cr, uid, args)
#
# return {}
#
#class box_entries(wizard.interface):
# states = {
# 'init': {
# 'actions': [],
# 'result': {
# 'type': 'form',
# 'arch': entry_form % u'Entrée de caisse',
# 'fields': entry_fields,
# 'state': [('end', 'Cancel', 'gtk-cancel'), ('next', 'Make entries in the Cashbox', 'gtk-ok')]
# }
# },
# 'next': {
# 'actions': [],
# 'result': {
# 'type': 'action',
# 'action': _get_in,
# 'state': 'end'
# }
# },
# }
#
#box_entries('pos.entry')
class box_out(wizard.interface):
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': entry_form % u'Sortie de caisse',
'fields': out_fields,
'state': [('end', 'Cancel', 'gtk-cancel'), ('next', 'Make Entries in the CashBox', 'gtk-ok')]
}
},
'next': {
'actions': [],
'result': {
'type': 'action',
'action': _get_out,
'state': 'end'
}
},
}
box_out('pos.out')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: