Browse Source

[add] pos_default_payment_method

pull/219/head
Simone Orsi 7 years ago
committed by Sylvain LE GAL
parent
commit
1aac29e3c0
  1. 64
      pos_default_payment_method/README.rst
  2. 1
      pos_default_payment_method/__init__.py
  3. 20
      pos_default_payment_method/__manifest__.py
  4. BIN
      pos_default_payment_method/images/module_installed.png
  5. BIN
      pos_default_payment_method/images/standard.png
  6. 1
      pos_default_payment_method/models/__init__.py
  7. 28
      pos_default_payment_method/models/pos_config.py
  8. 25
      pos_default_payment_method/static/src/js/pos_default_payment_method.js
  9. 1
      pos_default_payment_method/tests/__init__.py
  10. 28
      pos_default_payment_method/tests/test_constrain.py
  11. 8
      pos_default_payment_method/views/assets.xml
  12. 13
      pos_default_payment_method/views/pos_config_view.xml

64
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 <https://github.com/OCA/pos/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 <https://github.com/OCA/pos/issues/new?body=module:%20pos_default_payment_method%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Simone Orsi <simone.orsi@camptocamp.com>
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.

1
pos_default_payment_method/__init__.py

@ -0,0 +1 @@
from . import models

20
pos_default_payment_method/__manifest__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2017-TODAY Camptocamp SA (<http://www.camptocamp.com>).
# 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',
}

BIN
pos_default_payment_method/images/module_installed.png

After

Width: 1046  |  Height: 596  |  Size: 36 KiB

BIN
pos_default_payment_method/images/standard.png

After

Width: 1073  |  Height: 479  |  Size: 34 KiB

1
pos_default_payment_method/models/__init__.py

@ -0,0 +1 @@
from . import pos_config

28
pos_default_payment_method/models/pos_config.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2017-TODAY Camptocamp SA (<http://www.camptocamp.com>).
# @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."
))

25
pos_default_payment_method/static/src/js/pos_default_payment_method.js

@ -0,0 +1,25 @@
/******************************************************************************
* Copyright (C) 2017-TODAY Camptocamp SA (<http://www.camptocamp.com>).
* 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]);
}
},
});
});

1
pos_default_payment_method/tests/__init__.py

@ -0,0 +1 @@
from . import test_constrain

28
pos_default_payment_method/tests/test_constrain.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2017-TODAY Camptocamp SA (<http://www.camptocamp.com>).
# @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

8
pos_default_payment_method/views/assets.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_default_payment_method/static/src/js/pos_default_payment_method.js"></script>
</xpath>
</template>
</odoo>

13
pos_default_payment_method/views/pos_config_view.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="name">pos.config.form.view default payment method</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form"/>
<field name="arch" type="xml">
<field name="journal_ids" position="after">
<field name="default_payment_method_id" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save