From a99fff5df8a1d672df52fc1256f4624b18fd4446 Mon Sep 17 00:00:00 2001 From: eLBati Date: Tue, 28 Jul 2020 11:24:51 +0200 Subject: [PATCH] ADD pos_fixed_discount --- pos_fixed_discount/__init__.py | 0 pos_fixed_discount/__manifest__.py | 24 +++++++ pos_fixed_discount/i18n/it.po | 52 ++++++++++++++ pos_fixed_discount/readme/CONTRIBUTORS.rst | 1 + pos_fixed_discount/readme/DESCRIPTION.rst | 1 + pos_fixed_discount/readme/USAGE.rst | 1 + pos_fixed_discount/static/src/js/discount.js | 71 +++++++++++++++++++ .../static/src/xml/discount_templates.xml | 18 +++++ pos_fixed_discount/views/pos_templates.xml | 9 +++ .../odoo/addons/pos_fixed_discount | 1 + setup/pos_fixed_discount/setup.py | 6 ++ 11 files changed, 184 insertions(+) create mode 100644 pos_fixed_discount/__init__.py create mode 100644 pos_fixed_discount/__manifest__.py create mode 100644 pos_fixed_discount/i18n/it.po create mode 100644 pos_fixed_discount/readme/CONTRIBUTORS.rst create mode 100644 pos_fixed_discount/readme/DESCRIPTION.rst create mode 100644 pos_fixed_discount/readme/USAGE.rst create mode 100644 pos_fixed_discount/static/src/js/discount.js create mode 100644 pos_fixed_discount/static/src/xml/discount_templates.xml create mode 100644 pos_fixed_discount/views/pos_templates.xml create mode 120000 setup/pos_fixed_discount/odoo/addons/pos_fixed_discount create mode 100644 setup/pos_fixed_discount/setup.py diff --git a/pos_fixed_discount/__init__.py b/pos_fixed_discount/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pos_fixed_discount/__manifest__.py b/pos_fixed_discount/__manifest__.py new file mode 100644 index 00000000..524169e6 --- /dev/null +++ b/pos_fixed_discount/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2020 Lorenzo Battistini @ TAKOBI +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +{ + "name": "Point of Sale Fixed Discounts", + "summary": "Allow to apply discounts with fixed amount", + "version": "12.0.1.0.0", + "development_status": "Beta", + "category": "Point of Sale", + "website": "https://github.com/OCA/pos>", + "author": "TAKOBI, Odoo Community Association (OCA)", + "maintainers": ["eLBati"], + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": [ + "pos_discount", + ], + "data": [ + "views/pos_templates.xml", + ], + "qweb": [ + 'static/src/xml/discount_templates.xml', + ] +} diff --git a/pos_fixed_discount/i18n/it.po b/pos_fixed_discount/i18n/it.po new file mode 100644 index 00000000..d239b6c5 --- /dev/null +++ b/pos_fixed_discount/i18n/it.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-07-28 09:20+0000\n" +"PO-Revision-Date: 2020-07-28 09:20+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_fixed_discount +#. openerp-web +#: code:addons/pos_fixed_discount/static/src/xml/discount_templates.xml:7 +#, python-format +msgid "Discount (%)" +msgstr "Sconto (%)" + +#. module: pos_fixed_discount +#. openerp-web +#: code:addons/pos_fixed_discount/static/src/xml/discount_templates.xml:14 +#, python-format +msgid "Discount (Amount)" +msgstr "Sconto (importo)" + +#. module: pos_fixed_discount +#. openerp-web +#: code:addons/pos_fixed_discount/static/src/js/discount.js:15 +#, python-format +msgid "Discount Amount" +msgstr "Importo sconto" + +#. module: pos_fixed_discount +#. openerp-web +#: code:addons/pos_fixed_discount/static/src/js/discount.js:28 +#, python-format +msgid "No discount product found" +msgstr "Nessun prodotto sconto trovato" + +#. module: pos_fixed_discount +#. openerp-web +#: code:addons/pos_fixed_discount/static/src/js/discount.js:29 +#, python-format +msgid "The discount product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'." +msgstr "Il prodotto sconto sembra mal configurato. Assicurarsi che sia impostato come 'può essere venduto' e 'disponibile nel punto vendita'." + diff --git a/pos_fixed_discount/readme/CONTRIBUTORS.rst b/pos_fixed_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..356f259b --- /dev/null +++ b/pos_fixed_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ + * Lorenzo Battistini - https://takobi.online diff --git a/pos_fixed_discount/readme/DESCRIPTION.rst b/pos_fixed_discount/readme/DESCRIPTION.rst new file mode 100644 index 00000000..5880c289 --- /dev/null +++ b/pos_fixed_discount/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +In point of sale allow to apply discount with fixed amount. diff --git a/pos_fixed_discount/readme/USAGE.rst b/pos_fixed_discount/readme/USAGE.rst new file mode 100644 index 00000000..c1c9ab9e --- /dev/null +++ b/pos_fixed_discount/readme/USAGE.rst @@ -0,0 +1 @@ +Just click on "Discount (Amount)" and set the amount. diff --git a/pos_fixed_discount/static/src/js/discount.js b/pos_fixed_discount/static/src/js/discount.js new file mode 100644 index 00000000..6f7e92d0 --- /dev/null +++ b/pos_fixed_discount/static/src/js/discount.js @@ -0,0 +1,71 @@ +odoo.define('pos_fixed_discount.pos_fixed_discount', function (require) { +"use strict"; + +var core = require('web.core'); +var screens = require('point_of_sale.screens'); +var field_utils = require('web.field_utils'); + +var _t = core._t; + +var FixedDiscountButton = screens.ActionButtonWidget.extend({ + template: 'FixedDiscountButton', + button_click: function(){ + var self = this; + this.gui.show_popup('number',{ + 'title': _t('Discount Amount'), + 'value': 0, + 'confirm': function(val) { + self.apply_discount(val); + }, + }); + }, + apply_discount: function(amount) { + var order = this.pos.get_order(); + var lines = order.get_orderlines(); + var product = this.pos.db.get_product_by_id(this.pos.config.discount_product_id[0]); + if (product === undefined) { + this.gui.show_popup('error', { + title : _t("No discount product found"), + body : _t("The discount product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'."), + }); + return; + } + + // Remove existing discounts + var i = 0; + while ( i < lines.length ) { + if (lines[i].get_product() === product) { + order.remove_orderline(lines[i]); + } else { + i++; + } + } + + // Add discount + // We add the price as manually set to avoid recomputation when changing customer. + var discount = - amount.replace(",", "."); + + if( discount < 0 ){ + order.add_product(product, { + price: discount, + extras: { + price_manually_set: true, + }, + }); + } + }, +}); + +screens.define_action_button({ + 'name': 'fixed_discount', + 'widget': FixedDiscountButton, + 'condition': function(){ + return this.pos.config.module_pos_discount && this.pos.config.discount_product_id; + }, +}); + +return { + FixedDiscountButton: FixedDiscountButton, +} + +}); diff --git a/pos_fixed_discount/static/src/xml/discount_templates.xml b/pos_fixed_discount/static/src/xml/discount_templates.xml new file mode 100644 index 00000000..eaf07a21 --- /dev/null +++ b/pos_fixed_discount/static/src/xml/discount_templates.xml @@ -0,0 +1,18 @@ + + + + + +
+ Discount (%) +
+
+
+ + +
+ Discount (Amount) +
+
+ +
diff --git a/pos_fixed_discount/views/pos_templates.xml b/pos_fixed_discount/views/pos_templates.xml new file mode 100644 index 00000000..2d0ab851 --- /dev/null +++ b/pos_fixed_discount/views/pos_templates.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/setup/pos_fixed_discount/odoo/addons/pos_fixed_discount b/setup/pos_fixed_discount/odoo/addons/pos_fixed_discount new file mode 120000 index 00000000..6d2564bd --- /dev/null +++ b/setup/pos_fixed_discount/odoo/addons/pos_fixed_discount @@ -0,0 +1 @@ +../../../../pos_fixed_discount \ No newline at end of file diff --git a/setup/pos_fixed_discount/setup.py b/setup/pos_fixed_discount/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/pos_fixed_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)