diff --git a/pos_round_cash_payment/__init__.py b/pos_round_cash_payment/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/pos_round_cash_payment/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_round_cash_payment/__manifest__.py b/pos_round_cash_payment/__manifest__.py new file mode 100644 index 000000000..26fb878fa --- /dev/null +++ b/pos_round_cash_payment/__manifest__.py @@ -0,0 +1,31 @@ +# Copyright 2020 Coop IT Easy SCRLfs +# - Robin Keunen +# - Houssine bakkali +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Pos Round Cash Payment", + "version": "12.0.1.0.0", + "author": "Coop IT Easy SCRLfs", + "license": "AGPL-3", + "category": "Point of Sale", + "website": "www.coopiteasy.be", + "description": """ + Rounds due amount to nearest 5 cents when adding a cash Payment line. + An line is added on the invoice to record the rounding remainder. + + A Round Remainder journal must be created and assigned to the POS. + + """, + "depends": [ + 'point_of_sale', + ], + 'data': [ + 'views/pos_config.xml', + 'views/account_journal_view.xml', + 'static/src/xml/templates.xml', + ], + 'qweb': [ + 'static/src/xml/pos_round_cash_payment.xml' + ], + 'installable': True, +} diff --git a/pos_round_cash_payment/models/__init__.py b/pos_round_cash_payment/models/__init__.py new file mode 100644 index 000000000..de6a58629 --- /dev/null +++ b/pos_round_cash_payment/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_config +from . import account_journal diff --git a/pos_round_cash_payment/models/account_journal.py b/pos_round_cash_payment/models/account_journal.py new file mode 100644 index 000000000..a5fc771f9 --- /dev/null +++ b/pos_round_cash_payment/models/account_journal.py @@ -0,0 +1,14 @@ +# Copyright 2016 Robin Keunen, Coop IT Easy SCRL fs +# Copyright 2020 Houssine Bakkali, Coop IT Easy SCRL fs +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + + cash_rounding = fields.Boolean( + string='Cash Rounding Journal', + default=False, + ) diff --git a/pos_round_cash_payment/models/pos_config.py b/pos_round_cash_payment/models/pos_config.py new file mode 100644 index 000000000..45612e879 --- /dev/null +++ b/pos_round_cash_payment/models/pos_config.py @@ -0,0 +1,14 @@ +# Copyright 2016 Robin Keunen, Coop IT Easy SCRL fs +# Copyright 2020 Houssine Bakkali, Coop IT Easy SCRL fs +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class pos_config(models.Model): + _inherit = 'pos.config' + + cash_rounding_activated = fields.Boolean( + string='Activate Cash Rounding', + default=False, + ) diff --git a/pos_round_cash_payment/static/src/js/pos_round_cash_payment.js b/pos_round_cash_payment/static/src/js/pos_round_cash_payment.js new file mode 100644 index 000000000..b3f069c63 --- /dev/null +++ b/pos_round_cash_payment/static/src/js/pos_round_cash_payment.js @@ -0,0 +1,77 @@ +/* + POS Round cash Payment for odoo + Copyright (C) 2018 Coop IT Easy SCRLfs + @author: Robin Keunen + @author: Houssine BAKKALI + The licence is in the file __manifest__.py +*/ + +odoo.define( + 'pos_round_cash_payment.pos_round_cash_payment_line', + function (require) { + + "use strict"; + var models = require('point_of_sale.models'); + var screens = require('point_of_sale.screens'); + var round_pr = require('web.utils').round_precision; + + var order_prototype = models.Order.prototype; + + models.load_fields('account.journal', 'cash_rounding'); + + models.Order = models.Order.extend({ + + round_5c: function(x) { + return round_pr(x * 20) / 20; + }, + + round_5c_remainder: function(x) { + return x - this.round_5c(x); + }, + + add_remainder_line: function(cashregister) { + this.assert_editable(); + const due = this.get_due(newPaymentline); + const remainder = this.round_5c_remainder(due) + if (remainder !== 0) { + var newPaymentline = new models.Paymentline({}, + { + order: this, + cashregister:cashregister, pos: this.pos + } + ); + + newPaymentline.set_amount(remainder); + this.paymentlines.add(newPaymentline); + this.select_paymentline(newPaymentline); + } + }, + }); + + screens.PaymentScreenWidget.include({ + click_paymentmethods: function(id) { + var cashregister = null; + + for ( var i = 0; i < this.pos.cashregisters.length; i++ ) { + if ( this.pos.cashregisters[i].journal_id[0] === id ){ + cashregister = this.pos.cashregisters[i]; + break; + } + } + + if (cashregister.journal.cash_rounding == false) { + if (this.pos.config.cash_rounding_activated && cashregister.journal.type == 'cash') { + var rounding_cashregister = null; + for ( var i = 0; i < this.pos.cashregisters.length; i++ ) { + if ( this.pos.cashregisters[i].journal.cash_rounding === true ){ + rounding_cashregister = this.pos.cashregisters[i]; + break; + } + } + this.pos.get_order().add_remainder_line(rounding_cashregister); + } + this._super.apply(this, arguments); + } + }, + }); +}); diff --git a/pos_round_cash_payment/static/src/xml/templates.xml b/pos_round_cash_payment/static/src/xml/templates.xml new file mode 100644 index 000000000..8c04d07f6 --- /dev/null +++ b/pos_round_cash_payment/static/src/xml/templates.xml @@ -0,0 +1,8 @@ + + + + diff --git a/pos_round_cash_payment/views/account_journal_view.xml b/pos_round_cash_payment/views/account_journal_view.xml new file mode 100644 index 000000000..ce1079df1 --- /dev/null +++ b/pos_round_cash_payment/views/account_journal_view.xml @@ -0,0 +1,14 @@ + + + + POS Journal + account.journal + + + + + + + + + \ No newline at end of file diff --git a/pos_round_cash_payment/views/pos_config.xml b/pos_round_cash_payment/views/pos_config.xml new file mode 100644 index 000000000..17d212c92 --- /dev/null +++ b/pos_round_cash_payment/views/pos_config.xml @@ -0,0 +1,23 @@ + + + + pos.config.form.view.inherit + pos.config + + + +
+
+ +
+
+
+
+
+
+
+