Browse Source

Merge pull request #176 from acsone/10.0-mig-pos_payment_entries_globalization_mgs

[10.0][MIG] pos payment entries globalization
pull/358/head
David Vidal 6 years ago
committed by GitHub
parent
commit
46500e927c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      pos_payment_entries_globalization/README.rst
  2. 1
      pos_payment_entries_globalization/__init__.py
  3. 20
      pos_payment_entries_globalization/__manifest__.py
  4. 2
      pos_payment_entries_globalization/models/__init__.py
  5. 15
      pos_payment_entries_globalization/models/account_journal.py
  6. 103
      pos_payment_entries_globalization/models/pos_session.py
  7. BIN
      pos_payment_entries_globalization/static/description/icon.png
  8. 1
      pos_payment_entries_globalization/tests/__init__.py
  9. 367
      pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py
  10. 21
      pos_payment_entries_globalization/views/account_journal_view.xml
  11. 1
      setup/pos_payment_entries_globalization/odoo/__init__.py
  12. 1
      setup/pos_payment_entries_globalization/odoo/addons/__init__.py
  13. 1
      setup/pos_payment_entries_globalization/odoo/addons/pos_payment_entries_globalization
  14. 6
      setup/pos_payment_entries_globalization/setup.py

63
pos_payment_entries_globalization/README.rst

@ -0,0 +1,63 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=================================
POS payment entries globalization
=================================
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.
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
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/184/10.0
For further information, please visit:
* https://www.odoo.com/forum/help-1
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_payment_entries_globalization%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Meyomesse Gilles <meyomesse.gilles@gmail.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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_payment_entries_globalization/__init__.py

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

20
pos_payment_entries_globalization/__manifest__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
# 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://acsone.eu",
'category': 'Point Of Sale',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
],
'data': [
'views/account_journal_view.xml',
],
'installable': True,
}

2
pos_payment_entries_globalization/models/__init__.py

@ -0,0 +1,2 @@
from . import account_journal
from . import pos_session

15
pos_payment_entries_globalization/models/account_journal.py

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
# 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')

103
pos_payment_entries_globalization/models/pos_session.py

@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
# 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.iteritems():
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)
for lines in to_reconcile:
lines.reconcile()
@api.multi
def action_pos_session_closing_control(self):
super(PosSession, self).action_pos_session_closing_control()
for record in self:
# Call the method to generate globalization entries
record._generate_globalization_entries()

BIN
pos_payment_entries_globalization/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

1
pos_payment_entries_globalization/tests/__init__.py

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

367
pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py

@ -0,0 +1,367 @@
# -*- coding: utf-8 -*-
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# 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)

21
pos_payment_entries_globalization/views/account_journal_view.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<record model="ir.ui.view" id="view_account_journal_pos_user_form">
<field name="name">POS Journal (pos_payment_entries_globalization)</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="point_of_sale.view_account_journal_pos_user_form"/>
<field name="arch" type="xml">
<xpath expr="//group[field[@name='journal_user']]" position="after">
<group string="Payment Globalization" name="globalization">
<field name="pos_payment_globalization" />
<field name="pos_payment_globalization_account" attrs="{'required': [('pos_payment_globalization', '=', True)], 'invisible': [('pos_payment_globalization', '=', False)]}"/>
<field name="pos_payment_globalization_journal" attrs="{'required': [('pos_payment_globalization', '=', True)], 'invisible': [('pos_payment_globalization', '=', False)]}"/>
</group>
</xpath>
</field>
</record>
</data>
</odoo>

1
setup/pos_payment_entries_globalization/odoo/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/pos_payment_entries_globalization/odoo/addons/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/pos_payment_entries_globalization/odoo/addons/pos_payment_entries_globalization

@ -0,0 +1 @@
../../../../pos_payment_entries_globalization

6
setup/pos_payment_entries_globalization/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save