diff --git a/pos_multi_discount/README.rst b/pos_multi_discount/README.rst new file mode 100644 index 0000000000..c58e151824 --- /dev/null +++ b/pos_multi_discount/README.rst @@ -0,0 +1,78 @@ +================== +pos_multi_discount +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e591052b7acf247f2e06959d5fbc4b43dd7f604fa82d6ea1d3eed379f5f9b7c7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/14.0/pos_multi_discount + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_multi_discount + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Ilyas +* Ooops404 + +Contributors +~~~~~~~~~~~~ + +* Ooops404 + + * Ilyas + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_multi_discount/__init__.py b/pos_multi_discount/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_multi_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_multi_discount/__manifest__.py b/pos_multi_discount/__manifest__.py new file mode 100644 index 0000000000..265a0017c9 --- /dev/null +++ b/pos_multi_discount/__manifest__.py @@ -0,0 +1,19 @@ +{ + "name": "pos_multi_discount", + "summary": "pos_multi discount", + "version": "14.0.1.0.0", + "category": "Point Of Sale", + "author": "Ilyas, Ooops404, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "depends": [ + "pos_discount", + ], + "data": [ + "views/pos_templates.xml", + "views/pos_views.xml", + ], + "qweb": [ + "static/src/xml/Screens/ProductScreen/Orderline.xml", + ], +} diff --git a/pos_multi_discount/models/__init__.py b/pos_multi_discount/models/__init__.py new file mode 100644 index 0000000000..234b311eae --- /dev/null +++ b/pos_multi_discount/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_config +from . import pos_order diff --git a/pos_multi_discount/models/pos_config.py b/pos_multi_discount/models/pos_config.py new file mode 100644 index 0000000000..6cb3fb6fde --- /dev/null +++ b/pos_multi_discount/models/pos_config.py @@ -0,0 +1,5 @@ +from odoo import models + + +class PosConfig(models.Model): + _inherit = "pos.config" diff --git a/pos_multi_discount/models/pos_order.py b/pos_multi_discount/models/pos_order.py new file mode 100644 index 0000000000..52bb90ae91 --- /dev/null +++ b/pos_multi_discount/models/pos_order.py @@ -0,0 +1,18 @@ +from odoo import api, fields, models + + +class PosOrderLine(models.Model): + _inherit = "pos.order.line" + + manual_discount = fields.Float("Manual Disc.%") + manual_amount = fields.Monetary( + "Manual Disc. Amount", + compute="_compute_relative_discounts", + help="Based on product price", + ) + + @api.depends("qty", "price_unit", "manual_discount") + def _compute_relative_discounts(self): + for rec in self: + subtotal = rec.qty * rec.price_unit + rec.manual_amount = subtotal * rec.manual_discount / 100 diff --git a/pos_multi_discount/readme/CONFIGURATION.rst b/pos_multi_discount/readme/CONFIGURATION.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pos_multi_discount/readme/CONTRIBUTORS.rst b/pos_multi_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..6f583d7f26 --- /dev/null +++ b/pos_multi_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Ooops404 + + * Ilyas diff --git a/pos_multi_discount/readme/DESCRIPTION.rst b/pos_multi_discount/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pos_multi_discount/readme/USAGE.rst b/pos_multi_discount/readme/USAGE.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pos_multi_discount/static/description/icon.png b/pos_multi_discount/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/pos_multi_discount/static/description/icon.png differ diff --git a/pos_multi_discount/static/src/css/pos.css b/pos_multi_discount/static/src/css/pos.css new file mode 100644 index 0000000000..2f58b6e621 --- /dev/null +++ b/pos_multi_discount/static/src/css/pos.css @@ -0,0 +1,18 @@ +.payment-screen .discount-controls { + margin-top: 10px; +} + +.payment-screen .paymentlines-empty .fixed_discount_line { + text-align: center; + font-size: 20px; + margin-bottom: 10px; +} + +.payment-screen .fixed_discount_label { + font-size: 16px; + padding-right: 7px; +} + +.payment-screen .fixed_discount_amount { + font-size: 16px; +} diff --git a/pos_multi_discount/static/src/js/models.js b/pos_multi_discount/static/src/js/models.js new file mode 100644 index 0000000000..c22f671b63 --- /dev/null +++ b/pos_multi_discount/static/src/js/models.js @@ -0,0 +1,46 @@ +odoo.define("pos_multi_discount.POSModels", function (require) { + "use strict"; + + var models = require("point_of_sale.models"); + var field_utils = require("web.field_utils"); + + var _super_orderline = models.Orderline.prototype; + models.Orderline = models.Orderline.extend({ + initialize: function (attr, options) { + _super_orderline.initialize.call(this, attr, options); + this.manual_discount = 0; + }, + init_from_JSON: function (json) { + _super_orderline.init_from_JSON.apply(this, arguments); + this.manual_discount = json.manual_discount; + }, + set_discount: function (discount) { + var parsed_discount = + typeof discount === "number" + ? discount + : isNaN(parseFloat(discount)) + ? 0 + : field_utils.parse.float(String(discount)); + var disc = Math.min(Math.max(parsed_discount || 0, 0), 100); + this.manual_discount = disc; + this.discount = this.manual_discount + 0; // + fixed disc + % disc + this.discountStr = String(disc); + this.trigger("change", this); + }, + get_show_total_discount_line: function () { + var mode = this.pos.env.isDebug(); + if (mode === "assets" || mode === "1") { + return true; + } + return false; + }, + get_manual_discount: function () { + return this.manual_discount; + }, + export_as_JSON: function () { + var vals = _super_orderline.export_as_JSON.apply(this, arguments); + vals.manual_discount = this.manual_discount; + return vals; + }, + }); +}); diff --git a/pos_multi_discount/static/src/xml/Screens/ProductScreen/Orderline.xml b/pos_multi_discount/static/src/xml/Screens/ProductScreen/Orderline.xml new file mode 100644 index 0000000000..ae4199469a --- /dev/null +++ b/pos_multi_discount/static/src/xml/Screens/ProductScreen/Orderline.xml @@ -0,0 +1,34 @@ + + + + + +
  • + Manual discount + + % + +
  • +
    + +
  • + Total Discount + + % + +
  • +
    +
    + + + +
    +
    diff --git a/pos_multi_discount/views/pos_templates.xml b/pos_multi_discount/views/pos_templates.xml new file mode 100644 index 0000000000..4a91cabf29 --- /dev/null +++ b/pos_multi_discount/views/pos_templates.xml @@ -0,0 +1,11 @@ + + +