[IMP] pos_discount: a new pos extension that allows you to quickly give a global...
authorFrederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com>
Thu, 24 Jul 2014 16:08:12 +0000 (18:08 +0200)
committerFrederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com>
Tue, 5 Aug 2014 12:08:51 +0000 (14:08 +0200)
addons/pos_discount/__init__.py [new file with mode: 0644]
addons/pos_discount/__openerp__.py [new file with mode: 0644]
addons/pos_discount/discount.py [new file with mode: 0644]
addons/pos_discount/static/src/js/discount.js [new file with mode: 0644]
addons/pos_discount/static/src/xml/discount.xml [new file with mode: 0644]
addons/pos_discount/views/templates.xml [new file with mode: 0644]
addons/pos_discount/views/views.xml [new file with mode: 0644]

diff --git a/addons/pos_discount/__init__.py b/addons/pos_discount/__init__.py
new file mode 100644 (file)
index 0000000..5487d14
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- 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 discount
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/pos_discount/__openerp__.py b/addons/pos_discount/__openerp__.py
new file mode 100644 (file)
index 0000000..d367db1
--- /dev/null
@@ -0,0 +1,47 @@
+# -*- 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/>.
+#
+##############################################################################
+
+
+{
+    'name': 'Point of Sale Discounts',
+    'version': '1.0',
+    'category': 'Point of Sale',
+    'sequence': 6,
+    'summary': 'Simple Discounts in the Point of Sale ',
+    'description': """
+
+=======================
+
+This module allows the cashier to quickly give a percentage
+sale discount to a customer.
+
+""",
+    'author': 'OpenERP SA',
+    'depends': ['point_of_sale'],
+    'data': [
+        'views/views.xml',
+        'views/templates.xml'
+    ],
+    'installable': True,
+    'auto_install': False,
+}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/pos_discount/discount.py b/addons/pos_discount/discount.py
new file mode 100644 (file)
index 0000000..f8d24eb
--- /dev/null
@@ -0,0 +1,39 @@
+# -*- 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 logging
+
+import openerp
+
+from openerp import tools
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
+
+class pos_config(osv.osv):
+    _inherit = 'pos.config' 
+    _columns = {
+        'discount_pc': fields.float('Discount Percentage', help='The discount percentage'),
+        'discount_product_id': fields.many2one('product.product','Discount Product', help='The product used to model the discount'),
+    }
+    _defaults = {
+        'discount_pc': 10,
+    }
+
diff --git a/addons/pos_discount/static/src/js/discount.js b/addons/pos_discount/static/src/js/discount.js
new file mode 100644 (file)
index 0000000..5eaab36
--- /dev/null
@@ -0,0 +1,34 @@
+openerp.pos_discount = function(instance){
+    var module   = instance.point_of_sale;
+    var round_pr = instance.web.round_precision
+    var QWeb = instance.web.qweb;
+
+    QWeb.add_template('/pos_discount/static/src/xml/discount.xml');
+
+    module.PosWidget.include({
+        build_widgets: function(){
+            var self = this;
+            this._super();
+            
+            if(!this.pos.config.discount_product_id){
+                return;
+            }
+
+            var discount = $(QWeb.render('DiscountButton'));
+
+            discount.click(function(){
+                var order    = self.pos.get('selectedOrder');
+                var product  = self.pos.db.get_product_by_id(self.pos.config.discount_product_id[0]);
+                var discount = - self.pos.config.discount_pc/ 100.0 * order.getTotalTaxIncluded();
+                if( discount < 0 ){
+                    order.addProduct(product, { price: discount });
+                }
+            });
+
+            discount.appendTo(this.$('.control-buttons'));
+            this.$('.control-buttons').removeClass('oe_hidden');
+        },
+    });
+
+};
+
diff --git a/addons/pos_discount/static/src/xml/discount.xml b/addons/pos_discount/static/src/xml/discount.xml
new file mode 100644 (file)
index 0000000..c8be941
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<templates id="template" xml:space="preserve">
+
+    <t t-name="DiscountButton">
+        <div class='control-button js_discount'>
+            Discount
+        </div>
+    </t>
+
+</templates>
diff --git a/addons/pos_discount/views/templates.xml b/addons/pos_discount/views/templates.xml
new file mode 100644 (file)
index 0000000..0dbf22e
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <template id="assets_frontend" inherit_id="web.assets_common">
+          <xpath expr="." position="inside">
+              <script type="text/javascript" src="/pos_discount/static/src/js/discount.js"></script>
+          </xpath>
+        </template>
+
+    </data>
+</openerp>
diff --git a/addons/pos_discount/views/views.xml b/addons/pos_discount/views/views.xml
new file mode 100644 (file)
index 0000000..3448e0b
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<openerp>
+    <data>
+
+        <record model="ir.ui.view" id="view_pos_config_form">
+            <field name="name">pos.config.form.view</field>
+            <field name="model">pos.config</field>
+            <field name="inherit_id" ref="point_of_sale.view_pos_config_form" />
+            <field name="arch" type="xml">
+                <xpath expr="//group[@string='Receipt']" position="after">
+                    <group string="Discounts" col="4" >
+                        <field name='discount_pc' />
+                        <field name="discount_product_id" />
+                    </group>
+                </xpath>
+            </field>
+        </record>
+
+    </data>
+</openerp>