From c4772cac0781022a31c5a3fcec0ba536d34b8c0d Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 27 Feb 2019 15:17:47 +0100 Subject: [PATCH] [ADD] pos_require_product_quantity --- pos_require_product_quantity/__init__.py | 1 + pos_require_product_quantity/__openerp__.py | 24 ++++++++ .../models/__init__.py | 1 + .../models/pos_config.py | 15 +++++ .../static/src/js/pos.js | 59 +++++++++++++++++++ .../static/src/xml/templates.xml | 12 ++++ .../views/pos_config.xml | 15 +++++ 7 files changed, 127 insertions(+) create mode 100644 pos_require_product_quantity/__init__.py create mode 100644 pos_require_product_quantity/__openerp__.py create mode 100644 pos_require_product_quantity/models/__init__.py create mode 100644 pos_require_product_quantity/models/pos_config.py create mode 100644 pos_require_product_quantity/static/src/js/pos.js create mode 100644 pos_require_product_quantity/static/src/xml/templates.xml create mode 100644 pos_require_product_quantity/views/pos_config.xml diff --git a/pos_require_product_quantity/__init__.py b/pos_require_product_quantity/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_require_product_quantity/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_require_product_quantity/__openerp__.py b/pos_require_product_quantity/__openerp__.py new file mode 100644 index 00000000..6e340021 --- /dev/null +++ b/pos_require_product_quantity/__openerp__.py @@ -0,0 +1,24 @@ +# coding: utf-8 +# Copyright 2019 Coop IT Easy SCRLfs +# Robin Keunen +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Require Product Quantity in POS", + "version": "9.0.0.1.0", + "author": "Coop IT Easy SCRLfs, Odoo Community Association (OCA)", + "website": "www.coopiteasy.be", + "license": "AGPL-3", + "category": "Point of Sale", + "summary": """ + A popup is shown if product quantity is set to 0 for one or more order + lines when clicking on "Payment" button. + """, + "depends": [ + 'point_of_sale', + ], + 'data': [ + 'views/pos_config.xml', + 'static/src/xml/templates.xml', + ], + 'installable': True, +} diff --git a/pos_require_product_quantity/models/__init__.py b/pos_require_product_quantity/models/__init__.py new file mode 100644 index 00000000..db8634ad --- /dev/null +++ b/pos_require_product_quantity/models/__init__.py @@ -0,0 +1 @@ +from . import pos_config diff --git a/pos_require_product_quantity/models/pos_config.py b/pos_require_product_quantity/models/pos_config.py new file mode 100644 index 00000000..99333c26 --- /dev/null +++ b/pos_require_product_quantity/models/pos_config.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2016 Robin Keunen, Coop IT Easy SCRL fs +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from openerp import models, fields + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + require_product_quantity = fields.Boolean( + string='Require product quantity in POS', + default=False, + ) diff --git a/pos_require_product_quantity/static/src/js/pos.js b/pos_require_product_quantity/static/src/js/pos.js new file mode 100644 index 00000000..5fa266d4 --- /dev/null +++ b/pos_require_product_quantity/static/src/js/pos.js @@ -0,0 +1,59 @@ +/* + Copyright 2019 Coop IT Easy SCRLfs + Robin Keunen + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ + +odoo.define( + + 'pos_require_product_quantity.pos_require_product_quantity', + function (require) { + "use strict"; + + var core = require('web.core'); + var screens = require("point_of_sale.screens"); + + var _t = core._t; + + screens.ActionpadWidget = screens.ActionpadWidget.include({ + renderElement: function () { + var self = this; + this._super(); + + this.$('.pay').click(function () { + + if (self.pos.config.require_product_quantity) { + + var orderlines = self.pos.get_order().orderlines; + var qty_unset_list = []; + + for (var i = 0; i < orderlines.length; i++) { + var line = orderlines.models[i]; + if (line.quantity === 0) { + qty_unset_list.push(line); + } + } + if (qty_unset_list.length > 0) { + self.gui.back(); + var body = _t('No quantity set for products:'); + for (var j = 0; j < qty_unset_list.length; j++) { + body = ( + body + + ' - ' + + qty_unset_list[j].product.display_name + ); + } + self.gui.show_popup( + 'alert', + { + 'title': _t('Missing quantities'), + 'body': body, + }, + ); + } + } + }); + } + }) + } +); diff --git a/pos_require_product_quantity/static/src/xml/templates.xml b/pos_require_product_quantity/static/src/xml/templates.xml new file mode 100644 index 00000000..a525a8be --- /dev/null +++ b/pos_require_product_quantity/static/src/xml/templates.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/pos_require_product_quantity/views/pos_config.xml b/pos_require_product_quantity/views/pos_config.xml new file mode 100644 index 00000000..9f6a9aad --- /dev/null +++ b/pos_require_product_quantity/views/pos_config.xml @@ -0,0 +1,15 @@ + + + + + pos.config.form.view.inherit + pos.config + + + + + + + + +