diff --git a/pos_payment_entries_globalization/README.rst b/pos_payment_entries_globalization/README.rst new file mode 100644 index 00000000..5cf231c1 --- /dev/null +++ b/pos_payment_entries_globalization/README.rst @@ -0,0 +1,98 @@ +================================= +POS payment entries globalization +================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/11.0/pos_payment_entries_globalization + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-11-0/pos-11-0-pos_payment_entries_globalization + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/184/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to globalize payment entries created by the POS. + +In some cases, all banking transactions are received in a single bank statement +line. With this module, it's possible to reconcile this one line with the +payment globalization line. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + + * Configure globalize account and journal on POS payment methods + (Account journal). + +A globalization entry is generated for each globalization journal and each +globalization account defined on payment methods. + +Usage +===== + +Now it's easier to reconcile bank transactions with PoS payments. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Adrien Peiffer +* Meyomesse Gilles +* `Tecnativa `_ + + * David Vidal + * Rafael Blasco + +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_payment_entries_globalization/__init__.py b/pos_payment_entries_globalization/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_payment_entries_globalization/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_payment_entries_globalization/__manifest__.py b/pos_payment_entries_globalization/__manifest__.py new file mode 100644 index 00000000..2152cbba --- /dev/null +++ b/pos_payment_entries_globalization/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "POS payment entries globalization", + 'summary': """Globalize POS Payment""", + 'author': 'ACSONE SA/NV,' + 'Odoo Community Association (OCA)', + 'website': "http://github.com/OCA/pos", + 'category': 'Point Of Sale', + 'version': '11.0.1.0.0', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'views/account_journal_view.xml', + ], + 'installable': True, +} diff --git a/pos_payment_entries_globalization/i18n/es.po b/pos_payment_entries_globalization/i18n/es.po new file mode 100644 index 00000000..6c760b81 --- /dev/null +++ b/pos_payment_entries_globalization/i18n/es.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_entries_globalization +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-02-21 09:03+0000\n" +"PO-Revision-Date: 2019-02-21 09:03+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_payment_entries_globalization +#: model:ir.model,name:pos_payment_entries_globalization.model_account_journal +msgid "Journal" +msgstr "Diario" + +#. module: pos_payment_entries_globalization +#: model:ir.ui.view,arch_db:pos_payment_entries_globalization.view_account_journal_pos_user_form +msgid "Payment Globalization" +msgstr "Globalización de pagos" + +#. module: pos_payment_entries_globalization +#: code:addons/pos_payment_entries_globalization/models/pos_session.py:35 +#: code:addons/pos_payment_entries_globalization/models/pos_session.py:59 +#, python-format +msgid "Payment globalization" +msgstr "Globalización de pagos" + +#. module: pos_payment_entries_globalization +#: code:addons/pos_payment_entries_globalization/models/pos_session.py:44 +#, python-format +msgid "Payment globalization counterpart" +msgstr "Contrapartida de globalización de pagos" + +#. module: pos_payment_entries_globalization +#: model:ir.model.fields,field_description:pos_payment_entries_globalization.field_account_journal_pos_payment_globalization +msgid "Pos Payment Globalization" +msgstr "Globalización de pagos en Punto de Venta" + +#. module: pos_payment_entries_globalization +#: model:ir.model.fields,field_description:pos_payment_entries_globalization.field_account_journal_pos_payment_globalization_account +msgid "Pos Payment Globalization Account" +msgstr "Cuenta para globalización de pagos en Punto de Venta" + +#. module: pos_payment_entries_globalization +#: model:ir.model.fields,field_description:pos_payment_entries_globalization.field_account_journal_pos_payment_globalization_journal +msgid "Pos Payment Globalization Journal" +msgstr "Diario para globalización de pagos en Punto de Venta" + +#. module: pos_payment_entries_globalization +#: model:ir.model,name:pos_payment_entries_globalization.model_pos_session +msgid "pos.session" +msgstr "pos.session" diff --git a/pos_payment_entries_globalization/i18n/pos_payment_entries_globalization.pot b/pos_payment_entries_globalization/i18n/pos_payment_entries_globalization.pot new file mode 100644 index 00000000..86b461f8 --- /dev/null +++ b/pos_payment_entries_globalization/i18n/pos_payment_entries_globalization.pot @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_entries_globalization +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-02-21 09:05+0000\n" +"PO-Revision-Date: 2019-02-21 09:05+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_payment_entries_globalization +#: model:ir.model,name:pos_payment_entries_globalization.model_account_journal +msgid "Journal" +msgstr "" + +#. module: pos_payment_entries_globalization +#: model:ir.ui.view,arch_db:pos_payment_entries_globalization.view_account_journal_pos_user_form +msgid "Payment Globalization" +msgstr "" + +#. module: pos_payment_entries_globalization +#: code:addons/pos_payment_entries_globalization/models/pos_session.py:35 +#: code:addons/pos_payment_entries_globalization/models/pos_session.py:59 +#, python-format +msgid "Payment globalization" +msgstr "" + +#. module: pos_payment_entries_globalization +#: code:addons/pos_payment_entries_globalization/models/pos_session.py:44 +#, python-format +msgid "Payment globalization counterpart" +msgstr "" + +#. module: pos_payment_entries_globalization +#: model:ir.model.fields,field_description:pos_payment_entries_globalization.field_account_journal_pos_payment_globalization +msgid "Pos Payment Globalization" +msgstr "" + +#. module: pos_payment_entries_globalization +#: model:ir.model.fields,field_description:pos_payment_entries_globalization.field_account_journal_pos_payment_globalization_account +msgid "Pos Payment Globalization Account" +msgstr "" + +#. module: pos_payment_entries_globalization +#: model:ir.model.fields,field_description:pos_payment_entries_globalization.field_account_journal_pos_payment_globalization_journal +msgid "Pos Payment Globalization Journal" +msgstr "" + +#. module: pos_payment_entries_globalization +#: model:ir.model,name:pos_payment_entries_globalization.model_pos_session +msgid "pos.session" +msgstr "" + diff --git a/pos_payment_entries_globalization/models/__init__.py b/pos_payment_entries_globalization/models/__init__.py new file mode 100644 index 00000000..9b7ed82d --- /dev/null +++ b/pos_payment_entries_globalization/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_journal +from . import pos_session diff --git a/pos_payment_entries_globalization/models/account_journal.py b/pos_payment_entries_globalization/models/account_journal.py new file mode 100644 index 00000000..9acd5518 --- /dev/null +++ b/pos_payment_entries_globalization/models/account_journal.py @@ -0,0 +1,14 @@ +# Copyright 2015-2017 ACSONE SA/NV () +# 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' + + pos_payment_globalization = fields.Boolean() + pos_payment_globalization_account = fields.Many2one( + comodel_name='account.account') + pos_payment_globalization_journal = fields.Many2one( + comodel_name='account.journal') diff --git a/pos_payment_entries_globalization/models/pos_session.py b/pos_payment_entries_globalization/models/pos_session.py new file mode 100644 index 00000000..749d9aff --- /dev/null +++ b/pos_payment_entries_globalization/models/pos_session.py @@ -0,0 +1,103 @@ +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields, api, _ +from collections import defaultdict + + +class PosSession(models.Model): + _inherit = 'pos.session' + + @api.multi + def _get_move_lines_for_globalization(self): + """ Get all move lines for globalization by journal-account""" + self.ensure_one() + grouped_move_lines = defaultdict(list) + for st in self.statement_ids: + if st.journal_id.pos_payment_globalization: + # One move per journal and account combination + key = (st.journal_id.pos_payment_globalization_account.id, + st.journal_id.pos_payment_globalization_journal.id) + debit_account_id =\ + st.journal_id.default_debit_account_id.id + lines = st.move_line_ids.filtered( + lambda r: r.account_id.id == debit_account_id) + grouped_move_lines[key].extend(lines) + return grouped_move_lines + + @api.model + def _prepare_globalization_move(self, journal_id): + """Create the globalization move""" + entries_vals = { + 'journal_id': journal_id, + 'date': fields.Date.today(), + 'name': "%s - %s" % ( + self.name, _("Payment globalization")), + } + return self.env['account.move'].create(entries_vals) + + @api.model + def _prepare_globalization_counterpart_line(self, debit, credit, + account_id, move): + """Create the globalization counterpart line""" + item_vals = { + 'name': _("Payment globalization counterpart"), + 'credit': credit, + 'debit': debit, + 'account_id': account_id, + 'move_id': move.id + } + return self.env['account.move.line'].with_context( + {'check_move_validity': False}).create(item_vals) + + @api.model + def _create_reverse_line(self, line_to_reverse, move): + """Create move line the reverse payment line in entries + genereted by pos""" + item_vals = { + 'name': "%s - %s" % ( + line_to_reverse.name, _("Payment globalization")), + 'credit': line_to_reverse.debit, + 'debit': line_to_reverse.credit, + 'account_id': line_to_reverse.account_id.id, + 'move_id': move.id + } + # case of reverse account move line don't check move validity + # because it will assert balanced move + # that need : sum(debit) - sum(credit) must be gt 0 + return self.env['account.move.line'].with_context( + {'check_move_validity': False}).create(item_vals) + + @api.multi + def _generate_globalization_entries(self): + """Generate globalization moves""" + self.ensure_one() + grouped_move_lines = self._get_move_lines_for_globalization() + to_reconcile = [] + for key, lines in grouped_move_lines.items(): + global_account_id, global_journal_id = key + move = self._prepare_globalization_move(global_journal_id) + counterpart_debit = 0.0 + counterpart_credit = 0.0 + for line in lines: + counterpart_debit += line.debit + counterpart_credit += line.credit + new_line = self._create_reverse_line(line, move) + # Pair to reconcile : payment line and the reverse line + to_reconcile.append(line + new_line) + if counterpart_debit: + self._prepare_globalization_counterpart_line( + counterpart_debit, 0.0, global_account_id, move) + if counterpart_credit: + self._prepare_globalization_counterpart_line( + 0.0, counterpart_credit, global_account_id, move) + move.post() + for lines in to_reconcile: + lines.reconcile() + + @api.multi + def action_pos_session_close(self): + super(PosSession, self).action_pos_session_close() + for record in self: + # Call the method to generate globalization entries + record._generate_globalization_entries() diff --git a/pos_payment_entries_globalization/readme/CONFIGURE.rst b/pos_payment_entries_globalization/readme/CONFIGURE.rst new file mode 100644 index 00000000..2d7237e2 --- /dev/null +++ b/pos_payment_entries_globalization/readme/CONFIGURE.rst @@ -0,0 +1,7 @@ +To configure this module, you need to: + + * Configure globalize account and journal on POS payment methods + (Account journal). + +A globalization entry is generated for each globalization journal and each +globalization account defined on payment methods. diff --git a/pos_payment_entries_globalization/readme/CONTRIBUTORS.rst b/pos_payment_entries_globalization/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..0f6d0c1c --- /dev/null +++ b/pos_payment_entries_globalization/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Adrien Peiffer +* Meyomesse Gilles +* `Tecnativa `_ + + * David Vidal + * Rafael Blasco diff --git a/pos_payment_entries_globalization/readme/DESCRIPTION.rst b/pos_payment_entries_globalization/readme/DESCRIPTION.rst new file mode 100644 index 00000000..3d7442e9 --- /dev/null +++ b/pos_payment_entries_globalization/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module allows to globalize payment entries created by the POS. + +In some cases, all banking transactions are received in a single bank statement +line. With this module, it's possible to reconcile this one line with the +payment globalization line. diff --git a/pos_payment_entries_globalization/readme/USAGE.rst b/pos_payment_entries_globalization/readme/USAGE.rst new file mode 100644 index 00000000..769e6255 --- /dev/null +++ b/pos_payment_entries_globalization/readme/USAGE.rst @@ -0,0 +1 @@ +Now it's easier to reconcile bank transactions with PoS payments. diff --git a/pos_payment_entries_globalization/static/description/icon.png b/pos_payment_entries_globalization/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/pos_payment_entries_globalization/static/description/icon.png differ diff --git a/pos_payment_entries_globalization/tests/__init__.py b/pos_payment_entries_globalization/tests/__init__.py new file mode 100644 index 00000000..2718af2b --- /dev/null +++ b/pos_payment_entries_globalization/tests/__init__.py @@ -0,0 +1 @@ +from . import test_pos_payment_entries_globalization diff --git a/pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py b/pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py new file mode 100644 index 00000000..437e455a --- /dev/null +++ b/pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py @@ -0,0 +1,366 @@ +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import SavepointCase + + +class TestPosPaymentEntriesGlobalization(SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestPosPaymentEntriesGlobalization, cls).setUpClass() + + cls.move_line_obj = cls.env['account.move.line'] + cls.pos_order_obj = cls.env['pos.order'] + cls.main_config = cls.env.ref('point_of_sale.pos_config_main') + cls.account_type = cls.env['account.account.type'] + cls.account_account = cls.env['account.account'] + cls.payment_method = cls.env['account.journal'] + cls.product_01 = cls.env.ref( + 'point_of_sale.product_product_consumable') + cls.pos_config = cls.env.ref('point_of_sale.pos_config_main') + cls.customer_01 = cls.env.ref('base.res_partner_2') + cls.pos_session_obj = cls.env['pos.session'] + + # MODELS + cls.account_type = cls.account_type.create({ + 'name': 'Bank and Cash', + 'type': 'liquidity', + 'include_initial_balance': True + }) + cls.income_account = cls.account_account.create({ + 'code': 'X11006', + 'name': 'Other Income', + 'user_type_id': cls.account_type.id, + }) + cls.income_account_02 = cls.income_account.copy() + cls.account_account = cls.account_account.create({ + 'code': 'Test X1014', + 'name': 'Bank Current Account - (test)', + 'user_type_id': cls.account_type.id, + 'reconcile': True + }) + + cls.payment_method_02 = cls.payment_method.create({ + 'name': 'Bank - Test', + 'code': 'TBNK', + 'type': 'bank', + 'default_debit_account_id': cls.account_account.id, + 'default_credit_account_id': cls.account_account.id + }) + + # next line + cls.payment_method_03 = cls.payment_method.create({ + 'name': 'Checks Journal - (test)', + 'code': 'TBNK', + 'type': 'bank', + 'default_debit_account_id': cls.account_account.id, + 'default_credit_account_id': cls.account_account.id + }) + + cls.misc_journal = cls.payment_method.create({ + 'name': 'Miscellaneous Journal - (test)', + 'code': 'TMIS', + 'type': 'general' + }) + cls.misc_journal_02 = cls.misc_journal.copy() + + def create_order(self, amount, session): + # I create a new order + order_vals = { + 'session_id': session.id, + 'partner_id': self.customer_01.id, + 'lines': [(0, 0, {'product_id': self.product_01.id, + 'price_unit': amount})] + } + return self.pos_order_obj.create(order_vals) + + def test_globalization_0(self): + # add payment method + self.main_config.write( + {'journal_ids': [(6, 0, [self.payment_method_02.id])]}) + # Create and open a new session + self.session = self.pos_session_obj.create( + {'config_id': self.main_config.id}) + self.session.action_pos_session_open() + + # config pos payment globalization + self.payment_method_02.pos_payment_globalization = True + self.payment_method_02.pos_payment_globalization_account = \ + self.income_account + self.payment_method_02.pos_payment_globalization_journal = \ + self.misc_journal + + # I create a new orders + order_01 = self.create_order(100, self.session) + order_02 = self.create_order(100, self.session) + + # I pay the created order + payment_data1 = {'amount': 100, + 'journal': self.payment_method_02.id, + 'partner_id': order_01.partner_id.id} + payment_data2 = {'amount': 100, + 'journal': self.payment_method_02.id, + 'partner_id': order_02.partner_id.id} + + # add payment to orders and pay + order_01.add_payment(payment_data1) + if order_01.test_paid(): + order_01.action_pos_order_paid() + + order_02.add_payment(payment_data2) + if order_02.test_paid(): + order_02.action_pos_order_paid() + + # close session + self.session.action_pos_session_closing_control() + + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account.id), + ('journal_id', '=', self.misc_journal.id)]) + + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 200, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 2) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) + + def test_globalization_1(self): + # add payment method + self.main_config.write( + {'journal_ids': [(6, 0, [self.payment_method_02.id, + self.payment_method_03.id])] + }) + # Create and open a new session + self.session = self.pos_session_obj.create( + {'config_id': self.main_config.id}) + self.session.action_pos_session_open() + + self.payment_method_02.pos_payment_globalization = True + self.payment_method_02.pos_payment_globalization_account = \ + self.income_account + self.payment_method_02.pos_payment_globalization_journal = \ + self.misc_journal + self.payment_method_03.pos_payment_globalization = True + self.payment_method_03.pos_payment_globalization_account = \ + self.income_account_02 + self.payment_method_03.pos_payment_globalization_journal = \ + self.misc_journal + + # I create a new order + order_01 = self.create_order(100, self.session) + order_02 = self.create_order(100, self.session) + + # I pay the created order + payment_data1 = {'amount': 100, + 'journal': self.payment_method_02.id, + 'partner_id': order_01.partner_id.id} + payment_data2 = {'amount': 100, + 'journal': self.payment_method_03.id, + 'partner_id': order_02.partner_id.id} + + # add payment to orders and pay + order_01.add_payment(payment_data1) + if order_01.test_paid(): + order_01.action_pos_order_paid() + + order_02.add_payment(payment_data2) + if order_02.test_paid(): + order_02.action_pos_order_paid() + + # close session + self.session.action_pos_session_closing_control() + + # I check the first globalization account + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account.id), + ('journal_id', '=', self.misc_journal.id)]) + + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 100, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 1) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) + # I check the second globalization account + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account_02.id), + ('journal_id', '=', self.misc_journal.id)]) + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 100, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 1) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) + + def test_globalization_2(self): + # add payment method + self.main_config.write({'journal_ids': [(6, 0, [ + self.payment_method_02.id, self.payment_method_03.id])]}) + # Create and open a new session + self.session = self.pos_session_obj.create( + {'config_id': self.main_config.id}) + self.session.action_pos_session_open() + + self.payment_method_02.pos_payment_globalization = True + self.payment_method_02.pos_payment_globalization_account = \ + self.income_account + self.payment_method_02.pos_payment_globalization_journal = \ + self.misc_journal + self.payment_method_03.pos_payment_globalization = True + self.payment_method_03.pos_payment_globalization_account = \ + self.income_account_02 + self.payment_method_03.pos_payment_globalization_journal = \ + self.misc_journal + + # create orders + order_01 = self.create_order(100, self.session) + order_02 = self.create_order(100, self.session) + + # I pay the created order + payment_data1 = {'amount': 100, + 'journal': self.payment_method_02.id, + 'partner_id': order_01.partner_id.id} + payment_data2 = {'amount': 100, + 'journal': self.payment_method_03.id, + 'partner_id': order_02.partner_id.id} + + order_01.add_payment(payment_data1) + if order_01.test_paid(): + order_01.action_pos_order_paid() + + order_02.add_payment(payment_data2) + if order_02.test_paid(): + order_02.action_pos_order_paid() + + # close session + self.session.action_pos_session_closing_control() + + # I check the first globalization account + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account.id), + ('journal_id', '=', self.misc_journal.id)]) + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 100, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 1) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) + # I check the second globalization account + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account_02.id), + ('journal_id', '=', self.misc_journal.id)]) + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 100, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 1) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) + + def test_globalization_3(self): + # add payment method + self.main_config.write( + {'journal_ids': [(6, 0, [self.payment_method_02.id, + self.payment_method_03.id])]}) + # Create and open a new session + self.session = self.pos_session_obj.create( + {'config_id': self.main_config.id}) + self.session.action_pos_session_open() + + self.payment_method_02.pos_payment_globalization = True + self.payment_method_02.pos_payment_globalization_account =\ + self.income_account + self.payment_method_02.pos_payment_globalization_journal =\ + self.misc_journal + self.payment_method_03.pos_payment_globalization = True + self.payment_method_03.pos_payment_globalization_account =\ + self.income_account + self.payment_method_03.pos_payment_globalization_journal =\ + self.misc_journal_02 + + # I create orders + order_01 = self.create_order(100, self.session) + order_02 = self.create_order(100, self.session) + + # I pay the created orders + payment_data1 = {'amount': 100, + 'journal': self.payment_method_02.id, + 'partner_id': order_02.partner_id.id} + payment_data2 = {'amount': 100, + 'journal': self.payment_method_03.id, + 'partner_id': order_02.partner_id.id} + + order_01.add_payment(payment_data1) + if order_01.test_paid(): + order_01.action_pos_order_paid() + + order_02.add_payment(payment_data2) + if order_02.test_paid(): + order_02.action_pos_order_paid() + + # close session + self.session.action_pos_session_closing_control() + + # I check the first globalization journal + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account.id), + ('journal_id', '=', self.misc_journal.id)]) + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 100, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 1) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) + # I check the second globalization journal + move_line = self.move_line_obj.search( + [('account_id', '=', self.income_account.id), + ('journal_id', '=', self.misc_journal_02.id)]) + # I check that there is only one move line + self.assertEqual(len(move_line.ids), 1) + self.assertAlmostEqual(move_line.debit, 100, 2) + domain = [('move_id', '=', move_line.move_id.id), + ('id', '!=', move_line.id)] + reverse_lines = self.move_line_obj.search(domain) + # I ensure that the move contains reverse lines + self.assertEqual(len(reverse_lines), 1) + # I ensure reverse lines are reconciled + not_reconcile_reverse_lines = reverse_lines.filtered( + lambda r: not r.reconciled) + self.assertEqual(len(not_reconcile_reverse_lines), 0) diff --git a/pos_payment_entries_globalization/views/account_journal_view.xml b/pos_payment_entries_globalization/views/account_journal_view.xml new file mode 100644 index 00000000..36e763bd --- /dev/null +++ b/pos_payment_entries_globalization/views/account_journal_view.xml @@ -0,0 +1,21 @@ + + + + + + POS Journal (pos_payment_entries_globalization) + account.journal + + + + + + + + + + + + +