diff options
| author | Frederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com> | 2014-07-24 18:08:12 +0200 |
|---|---|---|
| committer | Frederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com> | 2014-07-24 18:08:12 +0200 |
| commit | dfd9f164a2e182b424b595c3429cc14d761dab0f (patch) | |
| tree | d3f934e0d8df8408deafc64846d37e4bdcd2aeb8 /addons/pos_discount | |
| parent | 6d87dfb0046d6f4ae48d04a1c0996bc9716fe39f (diff) | |
[IMP] pos_discount: a new pos extension that allows you to quickly give a global discount on the current order
Diffstat (limited to 'addons/pos_discount')
| -rw-r--r-- | addons/pos_discount/__init__.py | 25 | ||||
| -rw-r--r-- | addons/pos_discount/__openerp__.py | 47 | ||||
| -rw-r--r-- | addons/pos_discount/discount.py | 39 | ||||
| -rw-r--r-- | addons/pos_discount/static/src/js/discount.js | 34 | ||||
| -rw-r--r-- | addons/pos_discount/static/src/xml/discount.xml | 10 | ||||
| -rw-r--r-- | addons/pos_discount/views/templates.xml | 12 | ||||
| -rw-r--r-- | addons/pos_discount/views/views.xml | 20 |
7 files changed, 187 insertions, 0 deletions
diff --git a/addons/pos_discount/__init__.py b/addons/pos_discount/__init__.py new file mode 100644 index 00000000000..5487d145a9b --- /dev/null +++ b/addons/pos_discount/__init__.py @@ -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 index 00000000000..d367db148cd --- /dev/null +++ b/addons/pos_discount/__openerp__.py @@ -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 index 00000000000..f8d24eb638b --- /dev/null +++ b/addons/pos_discount/discount.py @@ -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 index 00000000000..5eaab362d20 --- /dev/null +++ b/addons/pos_discount/static/src/js/discount.js @@ -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 index 00000000000..c8be941683f --- /dev/null +++ b/addons/pos_discount/static/src/xml/discount.xml @@ -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 index 00000000000..0dbf22eb0fe --- /dev/null +++ b/addons/pos_discount/views/templates.xml @@ -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 index 00000000000..3448e0b2b6f --- /dev/null +++ b/addons/pos_discount/views/views.xml @@ -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> |
