* Add wizard scan product to use barcode reader

bzr revid: sebatien.lange@syleam.fr-20081220193344-w4bt1ivc8tttlwsn
This commit is contained in:
Sebastien LANGE 2008-12-20 20:33:44 +01:00
parent d5705c6b5c
commit 2a68020515
4 changed files with 121 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import time
import netsvc
from osv import fields, osv
from mx import DateTime
from tools.translate import _
class pos_config_journal(osv.osv):
@ -811,6 +812,52 @@ class pos_order_line(osv.osv):
return False
return super(pos_order_line, self).write(cr, user, ids, values, context)
def _scan_product(self, cr, uid, ean, qty, order):
# search pricelist_id
pricelist_id = self.pool.get('pos.order').read(cr, uid, [order], ['pricelist_id'] )
if not pricelist_id:
return False
new_line = True
product_id = self.pool.get('product.product').search(cr, uid, [('ean13','=', ean)])
if not product_id:
return false
# search price product
product = self.pool.get('product.product').read(cr, uid, product_id)
product_name = product[0]['name']
price = self.price_by_product(cr, uid, 0, pricelist_id[0]['pricelist_id'][0], product_id[0], 1)
order_line_ids = self.search(cr, uid, [('name','=',product_name),('order_id','=',order)])
if order_line_ids:
new_line = False
order_line_id = order_line_ids[0]
qty += self.read(cr, uid, order_line_ids[0], ['qty'])['qty']
if new_line:
vals = {'product_id': product_id[0],
'price_unit': price,
'qty': qty,
'name': product_name,
'order_id': order,
}
line_id = self.create(cr, uid, vals)
if not line_id:
raise wizard.except_wizard(_('Error'), _('Create line failed !'))
else:
vals = {
'qty': qty,
'price_unit': price
}
line_id = self.write(cr, uid, order_line_id, vals)
if not line_id:
raise wizard.except_wizard(_('Error'), _('Modify line failed !'))
line_id = order_line_id
price_line = float(qty)*float(price)
return {'name': product_name, 'product_id': product_id[0], 'price': price, 'price_line': price_line ,'qty': qty }
pos_order_line()

View File

@ -26,5 +26,8 @@
<wizard string="Get From Order" model="pos.order"
name="pos.sale.get" id="pos_sale_get"/>
<wizard string="Scan Product" model="pos.order"
name="pos.scan_product" id="pos_scan_product"/>
</data>
</openerp>

View File

@ -27,5 +27,6 @@ import wizard_add_product
import wizard_confirm
import wizard_discount
import wizard_get_sale
import wizard_scan_product
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# Copyright (c) 2008 Sylëam Info Services. (http://www.syleam.fr) All Rights Reserved.
#
# 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 pooler
import wizard
from osv import osv
form_gencod = """<?xml version="1.0"?>
<form string="Scan product">
<label string="Scan gencod" colspan="4"/>
<field name="gencod" colspan="4" nolabel="1"/>
</form>
"""
fields_gencod = {
'gencod': {'string': 'Gencod',
'type': 'char',
'size': 13,
'required': True}
}
def _scan(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
result = pool.get('pos.order.line')._scan_product(cr, uid, data['form']['gencod'], 1, data['id'])
return {'gencod': False}
def _pre_init(self, cr, uid, data, context):
return {'gencod': False}
class pos_scan_product(wizard.interface):
states = {
'init' : {'actions' : [_pre_init],
'result' : {
'type': 'form',
'arch': form_gencod,
'fields': fields_gencod,
'state': [('end','Cancel','gtk-cancel'),
('add', 'Add', 'gtk-ok', True)],
}
},
'add' : {'actions' : [_scan],
'result' : {
'type': 'state',
'state': 'init',
}
}
}
pos_scan_product('pos.scan_product')