From 2a680205153ca2b838c8ee189652c63c6fce3854 Mon Sep 17 00:00:00 2001 From: Sebastien LANGE Date: Sat, 20 Dec 2008 20:33:44 +0100 Subject: [PATCH] [IMP] * Add wizard scan product to use barcode reader bzr revid: sebatien.lange@syleam.fr-20081220193344-w4bt1ivc8tttlwsn --- addons/point_of_sale/pos.py | 47 +++++++++++++ addons/point_of_sale/pos_wizard.xml | 3 + addons/point_of_sale/wizard/__init__.py | 1 + .../wizard/wizard_scan_product.py | 70 +++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 addons/point_of_sale/wizard/wizard_scan_product.py diff --git a/addons/point_of_sale/pos.py b/addons/point_of_sale/pos.py index fc6e087fabf..18f37db8806 100644 --- a/addons/point_of_sale/pos.py +++ b/addons/point_of_sale/pos.py @@ -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() diff --git a/addons/point_of_sale/pos_wizard.xml b/addons/point_of_sale/pos_wizard.xml index 67ff7069ae0..afef00eb17f 100644 --- a/addons/point_of_sale/pos_wizard.xml +++ b/addons/point_of_sale/pos_wizard.xml @@ -26,5 +26,8 @@ + + diff --git a/addons/point_of_sale/wizard/__init__.py b/addons/point_of_sale/wizard/__init__.py index 466b2ad22b3..858ea4a474a 100644 --- a/addons/point_of_sale/wizard/__init__.py +++ b/addons/point_of_sale/wizard/__init__.py @@ -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: diff --git a/addons/point_of_sale/wizard/wizard_scan_product.py b/addons/point_of_sale/wizard/wizard_scan_product.py new file mode 100644 index 00000000000..9320b4ffb6f --- /dev/null +++ b/addons/point_of_sale/wizard/wizard_scan_product.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2008 Tiny SPRL (). 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 . +# +############################################################################## + +import pooler +import wizard +from osv import osv + +form_gencod = """ +
+