Browse Source

ADD pos_fixed_discount

pull/518/head
eLBati 4 years ago
parent
commit
a99fff5df8
  1. 0
      pos_fixed_discount/__init__.py
  2. 24
      pos_fixed_discount/__manifest__.py
  3. 52
      pos_fixed_discount/i18n/it.po
  4. 1
      pos_fixed_discount/readme/CONTRIBUTORS.rst
  5. 1
      pos_fixed_discount/readme/DESCRIPTION.rst
  6. 1
      pos_fixed_discount/readme/USAGE.rst
  7. 71
      pos_fixed_discount/static/src/js/discount.js
  8. 18
      pos_fixed_discount/static/src/xml/discount_templates.xml
  9. 9
      pos_fixed_discount/views/pos_templates.xml
  10. 1
      setup/pos_fixed_discount/odoo/addons/pos_fixed_discount
  11. 6
      setup/pos_fixed_discount/setup.py

0
pos_fixed_discount/__init__.py

24
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',
]
}

52
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'."

1
pos_fixed_discount/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Lorenzo Battistini - https://takobi.online

1
pos_fixed_discount/readme/DESCRIPTION.rst

@ -0,0 +1 @@
In point of sale allow to apply discount with fixed amount.

1
pos_fixed_discount/readme/USAGE.rst

@ -0,0 +1 @@
Just click on "Discount (Amount)" and set the amount.

71
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,
}
});

18
pos_fixed_discount/static/src/xml/discount_templates.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="DiscountButton">
<t t-jquery="div[class='control-button js_discount']" t-operation="replace">
<div class='control-button js_discount'>
<i class='fa fa-tag' /> Discount (%)
</div>
</t>
</t>
<t t-name="FixedDiscountButton">
<div class='control-button js_fixed_discount'>
<i class='fa fa-tag' /> Discount (Amount)
</div>
</t>
</templates>

9
pos_fixed_discount/views/pos_templates.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_fixed_discount/static/src/js/discount.js"></script>
</xpath>
</template>
</odoo>

1
setup/pos_fixed_discount/odoo/addons/pos_fixed_discount

@ -0,0 +1 @@
../../../../pos_fixed_discount

6
setup/pos_fixed_discount/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save