diff --git a/pos_check_accounting_settings/README.rst b/pos_check_accounting_settings/README.rst new file mode 100644 index 0000000000..005bf844ca --- /dev/null +++ b/pos_check_accounting_settings/README.rst @@ -0,0 +1,103 @@ +========================================= +Point of Sale - Check Accounting Settings +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:95ba837ae556e8ecb7af92cc67c3a0b664e5bc119051ebb1d5a73e01bcdf16ab + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/16.0/pos_check_accounting_settings + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_check_accounting_settings + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionnality of Odoo PoS adding extra +checks, when opening session, to ensure that accounting configation +is correct. + +Use case 1 +~~~~~~~~~~ + +When we create a payment method and if: +- the field 'Outstanding Payment' is not set on payment method +- AND the field 'Outstanding Receipts Account' is not on company + +if we use the payment method in the Point of sale, it is not +possible to close the session after. + +.. image:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_check_accounting_settings/static/img/error_oustanding_payment.png + +As it not possible to change a payment method when a session +is not closed, this bad configuration has to be fixed by SQL. + +This module adds a check when opening session, to avoid such situation. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Sylvain LE GAL (https://twitter.com/legalsylvain) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_check_accounting_settings/__init__.py b/pos_check_accounting_settings/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_check_accounting_settings/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_check_accounting_settings/__manifest__.py b/pos_check_accounting_settings/__manifest__.py new file mode 100644 index 0000000000..39f106d19b --- /dev/null +++ b/pos_check_accounting_settings/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Point of Sale - Check Accounting Settings", + "version": "16.0.1.0.0", + "category": "Point of Sale", + "summary": "Prevent incorrect accounting configuration" + " when launching Point Of Sale", + "depends": ["point_of_sale"], + "website": "https://github.com/OCA/pos", + "author": "GRAP,Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "license": "LGPL-3", +} diff --git a/pos_check_accounting_settings/i18n/fr.po b/pos_check_accounting_settings/i18n/fr.po new file mode 100644 index 0000000000..7f5c4c41cc --- /dev/null +++ b/pos_check_accounting_settings/i18n/fr.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_check_accounting_settings +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-06-29 22:22+0000\n" +"PO-Revision-Date: 2024-06-29 22:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_check_accounting_settings +#. odoo-python +#: code:addons/pos_check_accounting_settings/models/pos_config.py:0 +#, python-format +msgid "" +"No outstanding payments/receipts account for the payment method " +"'%(payment_method_name)s'. Please set the field 'Outstanding Payment' on the" +" payment method or the field 'Outstanding Receipts Account' on the company " +"settings." +msgstr "" +"Pas de compte de paiements entrants/sortants en suspens pour la méthode de paiement " +"'%(payment_method_name)s'. Veuillez renseigner le champs 'Paiements sortants en suspens' sur la méthode de paiement, ou le champs 'Compte de paiements entrants en suspens'" +" dans les paramétrage de la société." + +#. module: pos_check_accounting_settings +#: model:ir.model,name:pos_check_accounting_settings.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Configuration du point de vente" diff --git a/pos_check_accounting_settings/models/__init__.py b/pos_check_accounting_settings/models/__init__.py new file mode 100644 index 0000000000..db8634ade1 --- /dev/null +++ b/pos_check_accounting_settings/models/__init__.py @@ -0,0 +1 @@ +from . import pos_config diff --git a/pos_check_accounting_settings/models/pos_config.py b/pos_check_accounting_settings/models/pos_config.py new file mode 100644 index 0000000000..7a9b883946 --- /dev/null +++ b/pos_check_accounting_settings/models/pos_config.py @@ -0,0 +1,31 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, models +from odoo.exceptions import UserError + + +class PosConfig(models.Model): + _inherit = "pos.config" + + def _check_before_creating_new_session(self): + res = super()._check_before_creating_new_session() + for payment_method in self.payment_method_ids.filtered( + lambda x: x.journal_id and x.journal_id.type != "cash" + ): + company = payment_method.journal_id.company_id + if ( + not payment_method.outstanding_account_id + and not company.account_journal_payment_debit_account_id + ): + raise UserError( + _( + "No outstanding payments/receipts account for the payment method" + " '%(payment_method_name)s'." + " Please set the field 'Outstanding Payment' on the payment method" + " or the field 'Outstanding Receipts Account' on the company settings.", + payment_method_name=payment_method.name, + ) + ) + return res diff --git a/pos_check_accounting_settings/readme/CONTRIBUTORS.rst b/pos_check_accounting_settings/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..ae6f43a86d --- /dev/null +++ b/pos_check_accounting_settings/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL (https://twitter.com/legalsylvain) diff --git a/pos_check_accounting_settings/readme/DESCRIPTION.rst b/pos_check_accounting_settings/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..1a25af653d --- /dev/null +++ b/pos_check_accounting_settings/readme/DESCRIPTION.rst @@ -0,0 +1,20 @@ +This module extends the functionnality of Odoo PoS adding extra +checks, when opening session, to ensure that accounting configation +is correct. + +Use case 1 +~~~~~~~~~~ + +When we create a payment method and if: +- the field 'Outstanding Payment' is not set on payment method +- AND the field 'Outstanding Receipts Account' is not on company + +if we use the payment method in the Point of sale, it is not +possible to close the session after. + +.. image:: ../static/img/error_oustanding_payment.png + +As it not possible to change a payment method when a session +is not closed, this bad configuration has to be fixed by SQL. + +This module adds a check when opening session, to avoid such situation. diff --git a/pos_check_accounting_settings/static/description/error_oustanding_payment.png b/pos_check_accounting_settings/static/description/error_oustanding_payment.png new file mode 100644 index 0000000000..c8b7dc983f Binary files /dev/null and b/pos_check_accounting_settings/static/description/error_oustanding_payment.png differ diff --git a/pos_check_accounting_settings/static/description/index.html b/pos_check_accounting_settings/static/description/index.html new file mode 100644 index 0000000000..814395c692 --- /dev/null +++ b/pos_check_accounting_settings/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Point of Sale - Check Accounting Settings + + + +
+

Point of Sale - Check Accounting Settings

+ + +

Beta License: LGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

This module extends the functionnality of Odoo PoS adding extra +checks, when opening session, to ensure that accounting configation +is correct.

+
+

Use case 1

+

When we create a payment method and if: +- the field ‘Outstanding Payment’ is not set on payment method +- AND the field ‘Outstanding Receipts Account’ is not on company

+

if we use the payment method in the Point of sale, it is not +possible to close the session after.

+https://raw.githubusercontent.com/OCA/pos/16.0/pos_check_accounting_settings/static/img/error_oustanding_payment.png +

As it not possible to change a payment method when a session +is not closed, this bad configuration has to be fixed by SQL.

+

This module adds a check when opening session, to avoid such situation.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+ +
+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+ + diff --git a/pos_check_accounting_settings/tests/__init__.py b/pos_check_accounting_settings/tests/__init__.py new file mode 100644 index 0000000000..d9b96c4fa5 --- /dev/null +++ b/pos_check_accounting_settings/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/pos_check_accounting_settings/tests/test_module.py b/pos_check_accounting_settings/tests/test_module.py new file mode 100644 index 0000000000..20c1f5e4d3 --- /dev/null +++ b/pos_check_accounting_settings/tests/test_module.py @@ -0,0 +1,30 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase + + +class TestModule(TransactionCase): + def setUp(self): + super().setUp() + self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy( + default={ + "payment_method_ids": self.env.ref( + "point_of_sale.pos_config_main" + ).payment_method_ids.ids + } + ) + self.bank_payment_method = self.pos_config.payment_method_ids.filtered( + lambda x: x.journal_id.type == "bank" and not x.split_transactions + ) + + def test_correct_configuration(self): + self.pos_config.open_ui() + + def test_incorrect_configuration(self): + self.bank_payment_method.outstanding_account_id = False + self.env.company.account_journal_payment_debit_account_id = False + with self.assertRaises(UserError): + self.pos_config.open_ui() diff --git a/pos_payment_change/tests/test_module.py b/pos_payment_change/tests/test_module.py index 53a7162cbc..4239ff6db2 100644 --- a/pos_payment_change/tests/test_module.py +++ b/pos_payment_change/tests/test_module.py @@ -22,35 +22,21 @@ def setUp(self): "pos.payment.change.wizard.new.line" ] self.product = self.env.ref("product.product_product_3") - self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy() - - def _initialize_journals_open_session(self): - account_id = self.env.company.account_default_pos_receivable_account_id - self.bank_payment_method = self.PosPaymentMethod.create( - { - "name": "Bank", - "receivable_account_id": account_id.id, + self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy( + default={ + "payment_method_ids": self.env.ref( + "point_of_sale.pos_config_main" + ).payment_method_ids.ids } ) - self.cash_payment_method = self.PosPaymentMethod.create( - { - "name": "Cash", - "is_cash_count": True, - "receivable_account_id": account_id.id, - "journal_id": self.env["account.journal"] - .search( - [("type", "=", "cash"), ("company_id", "=", self.env.company.id)], - limit=1, - ) - .id, - } + self.cash_payment_method = self.pos_config.payment_method_ids.filtered( + lambda x: x.journal_id.type == "cash" + ) + self.bank_payment_method = self.pos_config.payment_method_ids.filtered( + lambda x: x.journal_id.type == "bank" and not x.split_transactions ) - # create new session and open it - self.pos_config.payment_method_ids = [ - self.bank_payment_method.id, - self.cash_payment_method.id, - ] + def _open_session(self): self.pos_config.open_ui() self.session = self.pos_config.current_session_id @@ -120,7 +106,7 @@ def _change_payment( def test_01_payment_change_policy_update(self): self.pos_config.payment_change_policy = "update" - self._initialize_journals_open_session() + self._open_session() # Make a sale with 35 in cash journal and 65 in check order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65) @@ -165,7 +151,7 @@ def test_01_payment_change_policy_update(self): def test_02_payment_change_policy_refund(self): self.pos_config.payment_change_policy = "refund" - self._initialize_journals_open_session() + self._open_session() # Make a sale with 35 in cash journal and 65 in check order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65) @@ -185,7 +171,7 @@ def test_02_payment_change_policy_refund(self): def test_03_payment_change_closed_orders(self): self.pos_config.payment_change_policy = "update" - self._initialize_journals_open_session() + self._open_session() # Make a sale with 35 in cash journal and 65 in check order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65) @@ -198,7 +184,7 @@ def test_03_payment_change_closed_orders(self): def test_04_payment_change_security(self): self.pos_config.payment_change_policy = "refund" - self._initialize_journals_open_session() + self._open_session() order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65) # the demo user should be able to do this diff --git a/setup/pos_check_accounting_settings/odoo/addons/pos_check_accounting_settings b/setup/pos_check_accounting_settings/odoo/addons/pos_check_accounting_settings new file mode 120000 index 0000000000..db11b735e3 --- /dev/null +++ b/setup/pos_check_accounting_settings/odoo/addons/pos_check_accounting_settings @@ -0,0 +1 @@ +../../../../pos_check_accounting_settings \ No newline at end of file diff --git a/setup/pos_check_accounting_settings/setup.py b/setup/pos_check_accounting_settings/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_check_accounting_settings/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)