From d10036527819fdee5b19041323735294d01d7f35 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Thu, 23 Nov 2023 10:30:06 +0100 Subject: [PATCH 1/2] [ADD] pos_detailed_cash_register --- pos_detailed_cash_register/README.rst | 87 ++++ pos_detailed_cash_register/__init__.py | 1 + pos_detailed_cash_register/__manifest__.py | 19 + pos_detailed_cash_register/i18n/fr.po | 96 ++++ pos_detailed_cash_register/models/__init__.py | 1 + .../models/pos_session.py | 122 +++++ .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 5 + pos_detailed_cash_register/readme/USAGE.rst | 1 + .../static/description/index.html | 432 ++++++++++++++++++ .../views/pos_session_view.xml | 110 +++++ .../odoo/addons/pos_detailed_cash_register | 1 + setup/pos_detailed_cash_register/setup.py | 6 + 13 files changed, 884 insertions(+) create mode 100644 pos_detailed_cash_register/README.rst create mode 100644 pos_detailed_cash_register/__init__.py create mode 100644 pos_detailed_cash_register/__manifest__.py create mode 100644 pos_detailed_cash_register/i18n/fr.po create mode 100644 pos_detailed_cash_register/models/__init__.py create mode 100644 pos_detailed_cash_register/models/pos_session.py create mode 100644 pos_detailed_cash_register/readme/CONTRIBUTORS.rst create mode 100644 pos_detailed_cash_register/readme/DESCRIPTION.rst create mode 100644 pos_detailed_cash_register/readme/USAGE.rst create mode 100644 pos_detailed_cash_register/static/description/index.html create mode 100644 pos_detailed_cash_register/views/pos_session_view.xml create mode 120000 setup/pos_detailed_cash_register/odoo/addons/pos_detailed_cash_register create mode 100644 setup/pos_detailed_cash_register/setup.py diff --git a/pos_detailed_cash_register/README.rst b/pos_detailed_cash_register/README.rst new file mode 100644 index 0000000000..b626718542 --- /dev/null +++ b/pos_detailed_cash_register/README.rst @@ -0,0 +1,87 @@ +========================== +PoS Detailed Cash Register +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bbff343997230e5b781ff2ff2a3492fea678a0464f5874f9225fb876327dc3f5 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/14.0/pos_detailed_cash_register + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_detailed_cash_register + :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=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module splits the "+ Transactions" lines in the cash control view of a PoS +session into the current transaction and the Cash In/Out lines. + +It also adds a new tab in the PoS session listing the cash in/out operations +with their reasons. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +The cash control must be enabled for the PoS session. + +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 +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* `Akretion `_: + + * Florian Mounier + +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. + +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_detailed_cash_register/__init__.py b/pos_detailed_cash_register/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_detailed_cash_register/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_detailed_cash_register/__manifest__.py b/pos_detailed_cash_register/__manifest__.py new file mode 100644 index 0000000000..83e976968f --- /dev/null +++ b/pos_detailed_cash_register/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "PoS Detailed Cash Register", + "summary": "Add more details about cash register operations in PoS session", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "Akretion,Odoo Community Association (OCA)", + "category": "Point of Sale", + "website": "https://github.com/OCA/pos", + "depends": [ + "point_of_sale", + ], + "data": [ + "views/pos_session_view.xml", + ], +} diff --git a/pos_detailed_cash_register/i18n/fr.po b/pos_detailed_cash_register/i18n/fr.po new file mode 100644 index 0000000000..f808d1cdde --- /dev/null +++ b/pos_detailed_cash_register/i18n/fr.po @@ -0,0 +1,96 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_detailed_cash_register +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-23 08:33+0000\n" +"PO-Revision-Date: 2023-11-23 08:33+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_detailed_cash_register +#: model_terms:ir.ui.view,arch_db:pos_detailed_cash_register.view_pos_session_form +msgid "+ Cash In" +msgstr "+ Cash entrant" + +#. module: pos_detailed_cash_register +#: model_terms:ir.ui.view,arch_db:pos_detailed_cash_register.view_pos_session_form +msgid "+ Transactions" +msgstr "+ Transactions" + +#. module: pos_detailed_cash_register +#: model_terms:ir.ui.view,arch_db:pos_detailed_cash_register.view_pos_session_form +msgid "- Cash Out" +msgstr "- Cash sortant" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__cash_real_total_in +msgid "Cash In" +msgstr "Cash entrant" + +#. module: pos_detailed_cash_register +#: model_terms:ir.ui.view,arch_db:pos_detailed_cash_register.view_pos_session_form +msgid "Cash In/Out" +msgstr "Cash entrant/sortant" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__cash_real_total_out +msgid "Cash Out" +msgstr "Cash sortant" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__cash_register_statement_line_ids +msgid "Cash Register Statement Lines" +msgstr "Lignes de relevé de caisse" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__id +msgid "ID" +msgstr "" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: pos_detailed_cash_register +#: model:ir.model,name:pos_detailed_cash_register.model_pos_session +msgid "Point of Sale Session" +msgstr "Session du point de vente" + +#. module: pos_detailed_cash_register +#: model_terms:ir.ui.view,arch_db:pos_detailed_cash_register.view_pos_session_form +msgid "Statements" +msgstr "Relevés" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__cash_register_total_in +msgid "Total Cash In" +msgstr "Total cash entrant" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__cash_register_total_out +msgid "Total Cash Out" +msgstr "Total cash sortant" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__total_cash_payments +msgid "Total Payments" +msgstr "Total des paiements" + +#. module: pos_detailed_cash_register +#: model:ir.model.fields,field_description:pos_detailed_cash_register.field_pos_session__total_real_cash_payments +msgid "Total Real Payments" +msgstr "Total des paiements réels" diff --git a/pos_detailed_cash_register/models/__init__.py b/pos_detailed_cash_register/models/__init__.py new file mode 100644 index 0000000000..f7116e3d45 --- /dev/null +++ b/pos_detailed_cash_register/models/__init__.py @@ -0,0 +1 @@ +from . import pos_session diff --git a/pos_detailed_cash_register/models/pos_session.py b/pos_detailed_cash_register/models/pos_session.py new file mode 100644 index 0000000000..84b3ef58f9 --- /dev/null +++ b/pos_detailed_cash_register/models/pos_session.py @@ -0,0 +1,122 @@ +# Copyright 2023 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class PosSession(models.Model): + _inherit = "pos.session" + + cash_register_statement_line_ids = fields.One2many( + "account.bank.statement.line", + compute="_compute_cash_register_statement_line_ids", + string="Cash Register Statement Lines", + ) + + cash_register_total_in = fields.Monetary( + compute="_compute_cash_register_totals", + string="Total Cash In", + ) + cash_register_total_out = fields.Monetary( + compute="_compute_cash_register_totals", + string="Total Cash Out", + ) + cash_real_total_in = fields.Monetary( + string="Cash In", + readonly=True, + ) + cash_real_total_out = fields.Monetary( + string="Cash Out", + readonly=True, + ) + + total_cash_payments = fields.Monetary( + compute="_compute_total_cash_payment", + string="Total Payments", + ) + + total_real_cash_payments = fields.Monetary( + compute="_compute_total_real_cash_payment", + string="Total Real Payments", + ) + + def _get_cash_register_counterpart_account(self): + # The cash in/out lines are in the move lines of the cash register + # attached to the suspense account + + # FIXME: Is it always the case? + self.ensure_one() + return self.cash_register_id.journal_id.suspense_account_id + + @api.depends("cash_register_id.line_ids") + def _compute_cash_register_statement_line_ids(self): + for session in self: + # Here we can't list all cash_register_id.line_ids because if the + # session is closed we also have the closure lines. + # We need to filter these out using the account.account + cash_register_account_id = session._get_cash_register_counterpart_account() + + session.cash_register_statement_line_ids = ( + session.cash_register_id.line_ids.filtered( + lambda line: line.move_id.line_ids.filtered( + lambda line: line.account_id == cash_register_account_id + ) + ) + ) + + @api.depends("cash_register_id.line_ids") + def _compute_cash_register_totals(self): + for session in self: + # When the cash register is opened, the cash in/out lines are the + # cash register lines. + session.cash_register_total_in = sum( + [ + line.amount + for line in session.cash_register_id.line_ids + if line.amount > 0 + ] + ) + session.cash_register_total_out = sum( + [ + line.amount + for line in session.cash_register_id.line_ids + if line.amount < 0 + ] + ) + + @api.depends( + "cash_register_total_entry_encoding", + "cash_register_total_in", + "cash_register_total_out", + ) + def _compute_total_cash_payment(self): + for session in self: + # The current transactions without cash in/out lines + session.total_cash_payments = ( + session.cash_register_total_entry_encoding + - session.cash_register_total_in + - session.cash_register_total_out + ) + + @api.depends( + "cash_real_transaction", + "cash_real_total_in", + "cash_real_total_out", + ) + def _compute_total_real_cash_payment(self): + for session in self: + # The real transactions without cash in/out lines + session.total_real_cash_payments = ( + session.cash_real_transaction + - session.cash_real_total_in + - session.cash_real_total_out + ) + + def _validate_session(self): + # We store the cash in/out totals at the session closure to keep the + # real amounts. (Like cash_real_transaction) + self.cash_real_total_in = self.cash_register_total_in + self.cash_real_total_out = self.cash_register_total_out + res = super(PosSession, self)._validate_session() + return res diff --git a/pos_detailed_cash_register/readme/CONTRIBUTORS.rst b/pos_detailed_cash_register/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..a4d0ad9229 --- /dev/null +++ b/pos_detailed_cash_register/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Akretion `_: + + * Florian Mounier diff --git a/pos_detailed_cash_register/readme/DESCRIPTION.rst b/pos_detailed_cash_register/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..46d72a52e8 --- /dev/null +++ b/pos_detailed_cash_register/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module splits the "+ Transactions" lines in the cash control view of a PoS +session into the current transaction and the Cash In/Out lines. + +It also adds a new tab in the PoS session listing the cash in/out operations +with their reasons. diff --git a/pos_detailed_cash_register/readme/USAGE.rst b/pos_detailed_cash_register/readme/USAGE.rst new file mode 100644 index 0000000000..9a6d9fc358 --- /dev/null +++ b/pos_detailed_cash_register/readme/USAGE.rst @@ -0,0 +1 @@ +The cash control must be enabled for the PoS session. diff --git a/pos_detailed_cash_register/static/description/index.html b/pos_detailed_cash_register/static/description/index.html new file mode 100644 index 0000000000..ae5089e226 --- /dev/null +++ b/pos_detailed_cash_register/static/description/index.html @@ -0,0 +1,432 @@ + + + + + + +PoS Detailed Cash Register + + + +
+

PoS Detailed Cash Register

+ + +

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

+

This module splits the “+ Transactions” lines in the cash control view of a PoS +session into the current transaction and the Cash In/Out lines.

+

It also adds a new tab in the PoS session listing the cash in/out operations +with their reasons.

+

Table of contents

+ +
+

Usage

+

The cash control must be enabled for the PoS session.

+
+
+

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

+
    +
  • Akretion
  • +
+
+
+

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.

+

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_detailed_cash_register/views/pos_session_view.xml b/pos_detailed_cash_register/views/pos_session_view.xml new file mode 100644 index 0000000000..e96f2e4001 --- /dev/null +++ b/pos_detailed_cash_register/views/pos_session_view.xml @@ -0,0 +1,110 @@ + + + + + pos.session + + + + + total_real_cash_payments + + + + + + + + + + + + + + total_cash_payments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/setup/pos_detailed_cash_register/odoo/addons/pos_detailed_cash_register b/setup/pos_detailed_cash_register/odoo/addons/pos_detailed_cash_register new file mode 120000 index 0000000000..9487e893f5 --- /dev/null +++ b/setup/pos_detailed_cash_register/odoo/addons/pos_detailed_cash_register @@ -0,0 +1 @@ +../../../../pos_detailed_cash_register \ No newline at end of file diff --git a/setup/pos_detailed_cash_register/setup.py b/setup/pos_detailed_cash_register/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_detailed_cash_register/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From b55433e46273d6a12aa61ff58915a54ea8cd6cb0 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Thu, 23 Jan 2025 16:35:29 +0100 Subject: [PATCH 2/2] [IMP] pos_detailed_cash_register: Add detailed cash box --- .../models/pos_session.py | 39 +++++++++++++++++-- .../views/pos_session_view.xml | 36 +++++++++++++++-- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/pos_detailed_cash_register/models/pos_session.py b/pos_detailed_cash_register/models/pos_session.py index 84b3ef58f9..30b7f2aa9e 100644 --- a/pos_detailed_cash_register/models/pos_session.py +++ b/pos_detailed_cash_register/models/pos_session.py @@ -41,14 +41,47 @@ class PosSession(models.Model): string="Total Real Payments", ) + # We can't use cashbox_start since it's unused in pos, so we get last session end + previous_session_cash_box_end_id = fields.Many2one( + "account.bank.statement.cashbox", + compute="_compute_previous_session_cash_box_end_id", + string="Previous Session Cash Box End", + ) + previous_session_cash_box_end_line_ids = fields.One2many( + related="previous_session_cash_box_end_id.cashbox_lines_ids", + string="Previous Session Cash Box End Lines", + ) + + cash_box_end_id = fields.Many2one( + related="cash_register_id.cashbox_end_id", + string="Cash Box End", + ) + cash_box_end_line_ids = fields.One2many( + related="cash_box_end_id.cashbox_lines_ids", + string="Cash Box End Lines", + ) + def _get_cash_register_counterpart_account(self): # The cash in/out lines are in the move lines of the cash register # attached to the suspense account - # FIXME: Is it always the case? - self.ensure_one() return self.cash_register_id.journal_id.suspense_account_id + @api.depends("config_id") + def _compute_previous_session_cash_box_end_id(self): + for record in self: + previous_session = self.search( + [ + ("config_id", "=", record.config_id.id), + ("state", "=", "closed"), + ("rescue", "=", False), + ("id", "<", record.id), + ], + order="id desc", + limit=1, + ) + record.previous_session_cash_box_end_id = previous_session.cash_box_end_id + @api.depends("cash_register_id.line_ids") def _compute_cash_register_statement_line_ids(self): for session in self: @@ -118,5 +151,5 @@ def _validate_session(self): # real amounts. (Like cash_real_transaction) self.cash_real_total_in = self.cash_register_total_in self.cash_real_total_out = self.cash_register_total_out - res = super(PosSession, self)._validate_session() + res = super()._validate_session() return res diff --git a/pos_detailed_cash_register/views/pos_session_view.xml b/pos_detailed_cash_register/views/pos_session_view.xml index e96f2e4001..60ae60abcb 100644 --- a/pos_detailed_cash_register/views/pos_session_view.xml +++ b/pos_detailed_cash_register/views/pos_session_view.xml @@ -1,8 +1,8 @@ @@ -84,13 +84,41 @@ + + + + + + + + + + + + + - +