diff --git a/pos_require_product_quantity/__init__.py b/pos_require_product_quantity/__init__.py new file mode 100644 index 0000000..0650744 --- /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 0000000..564e8e9 --- /dev/null +++ b/pos_require_product_quantity/__openerp__.py @@ -0,0 +1,26 @@ +# 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", + "website": "www.coopiteasy.be", + "license": "AGPL-3", + "category": "Point of Sale", + "description": """ + When adding a product to order line, this module sets the quantity to + - 1 for "Unit" product, + - 0 for other product. + A popup is shown if product quantity is set to 0 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 0000000..db8634a --- /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 0000000..c725f2a --- /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, api + + +class pos_config(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 0000000..70a3be8 --- /dev/null +++ b/pos_require_product_quantity/static/src/js/pos.js @@ -0,0 +1,71 @@ +/* + 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 models = require('point_of_sale.models'); +var screens = require("point_of_sale.screens"); + +var _t = core._t; +var orderline_prototype = models.Orderline.prototype; + +models.Orderline = models.Orderline.extend({ + initialize: function (attr, options) { + orderline_prototype.initialize.call(this, attr, options); + + var unit = this.get_unit(); + if (unit) { + if (unit.category_id[1] === 'Unit') { + this.set_quantity(1); + } else { + this.set_quantity(0); + } + } + } +}); + +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 i = 0; i < qty_unset_list.length; i++) { + body = body + ' - ' + qty_unset_list[i].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 0000000..a525a8b --- /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 0000000..9f6a9aa --- /dev/null +++ b/pos_require_product_quantity/views/pos_config.xml @@ -0,0 +1,15 @@ + + + + + pos.config.form.view.inherit + pos.config + + + + + + + + +