diff --git a/pos_default_payment_method/README.rst b/pos_default_payment_method/README.rst new file mode 100644 index 00000000..ffb06eb3 --- /dev/null +++ b/pos_default_payment_method/README.rst @@ -0,0 +1,64 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +POS Default payment method +========================== + +Configure default payment method for each POS config. + +If you set a default one, when you get to the payment view, it will be automatically activated. +If none is set the standard behavior is in place and you have to select the payment method manually. + +Use case +-------- + +The use case is pretty simple: + +* you have several payment methods +* most of the time, depending on the POS station, you pay with the same method +* without this module you have to click on the payment method to enable it + +So, you want to speed up payment process +when you already know how you want to pay +but still allow to change the method on demand. + +This is what you get with standard behavior when you land on the payment page: + +.. image:: ./images/standard.png + +and this is what happens when you set a default payment on your config: + +.. image:: ./images/module_installed.png + +The payment method is already activated and you have less work to do. + + +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 smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Simone Orsi + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/pos_default_payment_method/__init__.py b/pos_default_payment_method/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_default_payment_method/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_default_payment_method/__manifest__.py b/pos_default_payment_method/__manifest__.py new file mode 100644 index 00000000..2a9b9bf2 --- /dev/null +++ b/pos_default_payment_method/__manifest__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2017-TODAY Camptocamp SA (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'POS Default payment mehotd', + 'version': '10.0.1.0.0', + 'author': 'Camptocamp,Odoo Community Association (OCA)', + 'category': 'Sales Management', + 'depends': [ + 'point_of_sale', + ], + 'demo': [], + 'website': 'https://github.com/OCA/pos', + 'data': [ + 'views/assets.xml', + 'views/pos_config_view.xml', + ], + 'installable': True, + 'license': 'AGPL-3', +} diff --git a/pos_default_payment_method/images/module_installed.png b/pos_default_payment_method/images/module_installed.png new file mode 100644 index 00000000..bfce1a51 Binary files /dev/null and b/pos_default_payment_method/images/module_installed.png differ diff --git a/pos_default_payment_method/images/standard.png b/pos_default_payment_method/images/standard.png new file mode 100644 index 00000000..814e1f48 Binary files /dev/null and b/pos_default_payment_method/images/standard.png differ diff --git a/pos_default_payment_method/models/__init__.py b/pos_default_payment_method/models/__init__.py new file mode 100644 index 00000000..db8634ad --- /dev/null +++ b/pos_default_payment_method/models/__init__.py @@ -0,0 +1 @@ +from . import pos_config diff --git a/pos_default_payment_method/models/pos_config.py b/pos_default_payment_method/models/pos_config.py new file mode 100644 index 00000000..9118edcf --- /dev/null +++ b/pos_default_payment_method/models/pos_config.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2017-TODAY Camptocamp SA (). +# @author: Simone Orsi (https://twitter.com/simahawk) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import fields, models, api, exceptions, _ + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + default_payment_method_id = fields.Many2one( + comodel_name='account.journal', + string='Default payment method', + domain=[('journal_user', '=', True), + ('type', 'in', ['bank', 'cash'])], + ) + + @api.constrains('journal_ids', 'default_payment_method_id') + def _check_default_payment_method_id(self): + if not self.default_payment_method_id: + return + if self.default_payment_method_id not in self.journal_ids: + raise exceptions.ValidationError(_( + "The default payment journal " + "is not enabled on this configuration." + )) diff --git a/pos_default_payment_method/static/src/js/pos_default_payment_method.js b/pos_default_payment_method/static/src/js/pos_default_payment_method.js new file mode 100644 index 00000000..d870f47d --- /dev/null +++ b/pos_default_payment_method/static/src/js/pos_default_payment_method.js @@ -0,0 +1,25 @@ +/****************************************************************************** + * Copyright (C) 2017-TODAY Camptocamp SA (). + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + ******************************************************************************/ + +odoo.define('pos_default_payment_method.activate_payment', function (require) { + "use strict"; + + var pos_models = require('point_of_sale.models'); + var pos_screens = require('point_of_sale.screens'); + + // add `default_payment_method_id` to loaded pos config's fields + pos_models.load_fields("pos.config", "default_payment_method_id"); + + pos_screens.PaymentScreenWidget.include({ + show: function(){ + this._super(); + // activate default payment method if any + if (this.pos.config.default_payment_method_id) { + this.click_paymentmethods(this.pos.config.default_payment_method_id[0]); + } + }, + }); + +}); diff --git a/pos_default_payment_method/tests/__init__.py b/pos_default_payment_method/tests/__init__.py new file mode 100644 index 00000000..1996b9c0 --- /dev/null +++ b/pos_default_payment_method/tests/__init__.py @@ -0,0 +1 @@ +from . import test_constrain diff --git a/pos_default_payment_method/tests/test_constrain.py b/pos_default_payment_method/tests/test_constrain.py new file mode 100644 index 00000000..a77bde3d --- /dev/null +++ b/pos_default_payment_method/tests/test_constrain.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2017-TODAY Camptocamp SA (). +# @author: Simone Orsi (https://twitter.com/simahawk) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import odoo + + +@odoo.tests.common.at_install(False) +@odoo.tests.common.post_install(True) +class TestPOS(odoo.tests.TransactionCase): + + def test_check_default_payment_method_id(self): + journal_ok = self.env['account.journal'].create({ + 'name': 'Ok', + 'code': 'OK', + 'type': 'cash', + }) + journal_ko = self.env['account.journal'].create({ + 'name': 'Ko', + 'code': 'KO', + 'type': 'cash', + }) + config = self.env.ref('point_of_sale.pos_config_main') + config.write({'journal_ids': [(6, 0, journal_ok.ids)]}) + config.default_payment_method_id = journal_ok + with self.assertRaises(odoo.exceptions.ValidationError): + config.default_payment_method_id = journal_ko diff --git a/pos_default_payment_method/views/assets.xml b/pos_default_payment_method/views/assets.xml new file mode 100644 index 00000000..fea39678 --- /dev/null +++ b/pos_default_payment_method/views/assets.xml @@ -0,0 +1,8 @@ + + + + diff --git a/pos_default_payment_method/views/pos_config_view.xml b/pos_default_payment_method/views/pos_config_view.xml new file mode 100644 index 00000000..b6c44669 --- /dev/null +++ b/pos_default_payment_method/views/pos_config_view.xml @@ -0,0 +1,13 @@ + + + + pos.config.form.view default payment method + pos.config + + + + + + + +