Browse Source

Add pos_payment_entries_globalization module

pull/176/head
Adrien Peiffer (ACSONE) 9 years ago
committed by gilles
parent
commit
e69109610d
  1. 62
      pos_payment_entries_globalization/README.rst
  2. 4
      pos_payment_entries_globalization/__init__.py
  3. 21
      pos_payment_entries_globalization/__openerp__.py
  4. 5
      pos_payment_entries_globalization/models/__init__.py
  5. 15
      pos_payment_entries_globalization/models/account_journal.py
  6. 102
      pos_payment_entries_globalization/models/pos_session.py
  7. BIN
      pos_payment_entries_globalization/static/description/icon.png
  8. 5
      pos_payment_entries_globalization/tests/__init__.py
  9. 271
      pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py
  10. 19
      pos_payment_entries_globalization/views/account_journal_view.xml

62
pos_payment_entries_globalization/README.rst

@ -0,0 +1,62 @@
.. 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 method (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/8.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>
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.

4
pos_payment_entries_globalization/__init__.py

@ -0,0 +1,4 @@
# -*- 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 . import models

21
pos_payment_entries_globalization/__openerp__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2015 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': '8.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
],
'data': [
'views/account_journal_view.xml',
],
}

5
pos_payment_entries_globalization/models/__init__.py

@ -0,0 +1,5 @@
# -*- 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 . 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 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp 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')

102
pos_payment_entries_globalization/models/pos_session.py

@ -0,0 +1,102 @@
# -*- 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 openerp 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 _create_globalization_move(self, journal_id, period_id):
"""Create the globalization move"""
entries_vals = {
'journal_id': journal_id,
'period_id': period_id,
'date': fields.Date.today(),
'name': "%s - %s" % (
self.name, _("Payment globalization")),
}
return self.env['account.move'].create(entries_vals)
@api.model
def _create_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'].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
}
return self.env['account.move.line'].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 = []
period = self.env['account.period'].find()
for key, lines in grouped_move_lines.iteritems():
global_account_id, global_journal_id = key
move = self._create_globalization_move(global_journal_id,
period.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._create_globalization_counterpart_line(
counterpart_debit, 0.0, global_account_id, move)
if counterpart_credit:
self._create_globalization_counterpart_line(
0.0, counterpart_credit, global_account_id, move)
for lines in to_reconcile:
lines.reconcile()
@api.multi
def wkf_action_close(self):
res = super(PosSession, self).wkf_action_close()
for record in self:
# Call the method to generate globalization entries
record._generate_globalization_entries()
return res

BIN
pos_payment_entries_globalization/static/description/icon.png

After

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

5
pos_payment_entries_globalization/tests/__init__.py

@ -0,0 +1,5 @@
# -*- 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 . import test_pos_payment_entries_globalization

271
pos_payment_entries_globalization/tests/test_pos_payment_entries_globalization.py

@ -0,0 +1,271 @@
# -*- 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 openerp.tests import common
class TestPosPaymentEntriesGlobalization(common.TransactionCase):
def setUp(self):
super(TestPosPaymentEntriesGlobalization, self).setUp()
self.move_line_obj = self.env['account.move.line']
self.pos_session_obj = self.env['pos.session']
self.pos_order_obj = self.env['pos.order']
self.main_config = self.env.ref('point_of_sale.pos_config_main')
self.payment_method_01 = self.env.ref('account.cash_journal')
self.payment_method_02 = self.env.ref('account.bank_journal')
self.payment_method_02.default_debit_account_id.reconcile = True
self.payment_method_03 = self.env.ref('account.check_journal')
self.payment_method_03.default_debit_account_id.reconcile = True
self.income_account = self.env.ref('account.o_income')
self.income_account_02 = self.income_account.copy()
self.misc_journal = self.env.ref('account.miscellaneous_journal')
self.misc_journal_02 = self.misc_journal.copy()
self.product_01 = self.env.ref('point_of_sale.perrier_50cl')
def open_session(self):
# I create and open a new session
session = self.pos_session_obj.create(
{'config_id': self.main_config.id})
ctx = self.env.context.copy()
# context is updated in open_cb
# -> Need to call with old api to give unfrozen context
self.registry['pos.session'].open_cb(
self.cr, self.uid, [session.id], context=ctx)
return session
def create_order(self, amount, session):
# I create a new order
order_vals = {
'session_id': session.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):
session = self.open_session()
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 order
order_01 = self.create_order(100, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_02.id}
self.pos_order_obj.add_payment(order_01.id, payment_data)
if order_01.test_paid():
order_01.signal_workflow('paid')
# I create a new order
order_02 = self.create_order(100, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_02.id}
self.pos_order_obj.add_payment(order_02.id, payment_data)
if order_02.test_paid():
order_02.signal_workflow('paid')
# I close the session
session.signal_workflow('close')
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.reconcile_ref)
self.assertEqual(len(not_reconcile_reverse_lines), 0)
def test_globalization_1(self):
session = self.open_session()
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, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_02.id}
self.pos_order_obj.add_payment(order_01.id, payment_data)
if order_01.test_paid():
order_01.signal_workflow('paid')
# I create a new order
order_02 = self.create_order(100, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_03.id}
self.pos_order_obj.add_payment(order_02.id, payment_data)
if order_02.test_paid():
order_02.signal_workflow('paid')
# I close the session
session.signal_workflow('close')
# 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.reconcile_ref)
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.reconcile_ref)
self.assertEqual(len(not_reconcile_reverse_lines), 0)
def test_globalization_2(self):
session = self.open_session()
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(200, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_02.id}
self.pos_order_obj.add_payment(order_01.id, payment_data)
payment_data = {'amount': 100,
'journal': self.payment_method_03.id}
self.pos_order_obj.add_payment(order_01.id, payment_data)
if order_01.test_paid():
order_01.signal_workflow('paid')
# I close the session
session.signal_workflow('close')
# 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.reconcile_ref)
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.reconcile_ref)
self.assertEqual(len(not_reconcile_reverse_lines), 0)
def test_globalization_3(self):
session = self.open_session()
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 a new order
order_01 = self.create_order(100, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_02.id}
self.pos_order_obj.add_payment(order_01.id, payment_data)
if order_01.test_paid():
order_01.signal_workflow('paid')
# I create a new order
order_02 = self.create_order(100, session)
# I pay the created order
payment_data = {'amount': 100,
'journal': self.payment_method_03.id}
self.pos_order_obj.add_payment(order_02.id, payment_data)
if order_02.test_paid():
order_02.signal_workflow('paid')
# I close the session
session.signal_workflow('close')
# 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.reconcile_ref)
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.reconcile_ref)
self.assertEqual(len(not_reconcile_reverse_lines), 0)

19
pos_payment_entries_globalization/views/account_journal_view.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<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>
</openerp>
Loading…
Cancel
Save