Skip to content

Commit

Permalink
[MIG] pos_cash_move_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesTephaneMeyomesse committed Jun 27, 2017
1 parent 7110667 commit f575797
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 84 deletions.
5 changes: 3 additions & 2 deletions pos_cash_move_reason/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Usage

You can use configured products on "Put Money In" and "Take Money Out" wizard available in point of sale session:

.. figure:: /pos_cash_move_reason/static/description/pos_cash_move_reason_02.png
.. figure:: /pos_cash_move_reason/static/description/pos_cash_move_reason.png
:alt: Take money out wizard


.. 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
:target: https://runbot.odoo-community.org/runbot/184/10.0


Bug Tracker
Expand All @@ -47,6 +47,7 @@ Contributors
------------

* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Meyomesse Gilles <meyomesse.gilles@gmail.com>

Maintainer
----------
Expand Down
5 changes: 1 addition & 4 deletions pos_cash_move_reason/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizard
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
'Odoo Community Association (OCA)',
'website': "http://acsone.eu",
'category': 'POS',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
],
'data': [
'wizard/pos_box.xml',
'views/product_template.xml',
],
}
1 change: 1 addition & 0 deletions pos_cash_move_reason/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
19 changes: 19 additions & 0 deletions pos_cash_move_reason/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- 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 product_template(models.Model):
_inherit = 'product.template'

income_pdt = fields.Boolean(string='Point of Sale Cash In',
help="Check if, this is a product you can "
"use to put cash into a statement for "
"the point of sale backend.")
expense_pdt = fields.Boolean(string='Point of Sale Cash Out',
help="Check if, this is a product you can use"
" to take cash from a statement for the "
"point of sale backend, example: money "
"lost, transfert to bank, etc.")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 0 additions & 4 deletions pos_cash_move_reason/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_pos_cash_move_reason
132 changes: 86 additions & 46 deletions pos_cash_move_reason/tests/test_pos_cash_move_reason.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,93 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests import common
from odoo import fields
from odoo.tests.common import SavepointCase


class TestPosCashMoveReason(common.TransactionCase):
class TestPosCashMoveReason(SavepointCase):

def setUp(self):
super(TestPosCashMoveReason, self).setUp()
self.pos_session_obj = self.env['pos.session']
self.aml_obj = self.env['account.move.line']
self.cash_in_obj = self.env['cash.box.in']
self.cash_out_obj = self.env['cash.box.out']
self.cash_move_reason_obj = self.env['product.template']
self.main_config = self.env.ref('point_of_sale.pos_config_main')
self.cash_journal = self.env.ref('account.cash_journal')
self.income_account = self.env.ref('account.o_income')
self.expense_account = self.env.ref('account.a_expense')
@classmethod
def setUpClass(cls):
super(TestPosCashMoveReason, cls).setUpClass()
cls.pos_session_obj = cls.env['pos.session']
cls.aml_obj = cls.env['account.move.line']
cls.cash_in_obj = cls.env['cash.box.in']
cls.cash_out_obj = cls.env['cash.box.out']
cls.cash_move_reason_obj = cls.env['product.template']
cls.main_config = cls.env.ref('point_of_sale.pos_config_main')
cls.account_journal = cls.env['account.journal']
cls.account_account = cls.env['account.account']

# MODELS
cls.account_account_rsa = cls.account_account.create(
{'code': 'X1113',
'name': 'Reserve and Profit/Loss - (test)',
'user_type_id': cls.env.ref(
'account.data_account_type_current_liabilities').id})
cls.account_account_cash = cls.account_account.create(
{'code': 'X1015',
'name': 'Cash - (test)',
'user_type_id': cls.env.ref(
'account.data_account_type_liquidity').id})
cls.income_account = cls.account_account.create(
{'code': 'X1016',
'name': 'Opening Income - (test)',
'user_type_id': cls.env.ref(
'account.data_account_type_other_income').id})
cls.expense_account = cls.account_account.create(
{'code': 'X2120',
'name': 'Expenses - (test)',
'user_type_id': cls.env.ref(
'account.data_account_type_expenses').id})
cls.cash_journal = cls.account_journal.create(
{'name': 'Cash Journal - (test)',
'code': 'TCSH',
'type': 'cash',
'profit_account_id': cls.account_account_rsa.id,
'loss_account_id': cls.account_account_rsa.id,
'default_debit_account_id': cls.account_account_cash.id,
'default_credit_account_id': cls.account_account_cash.id})

def test01(self):
self.main_config.write(
{'journal_ids': [(6, 0, [self.cash_journal.id])],
'cash_control': True})
# 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()

# I create one move reason
vals = {'name': 'Miscellaneous income',
'property_account_income': self.income_account.id,
'property_account_income_id': self.income_account.id,
'income_pdt': True}
move_reason = self.cash_move_reason_obj.create(vals)
# I set cash control on cash journal
self.cash_journal.cash_control = True
# I create and open a new session
self.session_01 = 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, [self.session_01.id], context=ctx)
ctx['active_ids'] = self.session_01.id
ctx['active_model'] = self.session_01._name
ctx['active_ids'] = self.session.id
ctx['active_model'] = self.session._name

# I put the session in validation control
self.session_01.signal_workflow('cashbox_control')
ctx['active_ids'] = self.session_01.id
ctx['active_model'] = self.session_01._name
self.session.write(
{'state': 'closing_control', 'stop_at': fields.Datetime.now()})

# I create a cash in
cash_in = self.cash_in_obj.with_context(ctx).create(
{'name': 'Initialization',
'product_id': move_reason.id,
'amount': 500.0})
cash_in.with_context(ctx).run()
# I close the session
self.session_01.signal_workflow('close')

# close session
self.session.action_pos_session_closing_control()

# I get the statement from the session
statement = self.env['account.bank.statement'].search(
[('pos_session_id', '=', self.session_01.id),
[('pos_session_id', '=', self.session.id),
('journal_id', '=', self.cash_journal.id)])
# I get all move lines of this statement
move_line_ids = statement.move_line_ids.ids
Expand All @@ -63,38 +99,42 @@ def test01(self):
self.assertEquals(len(move_line.ids), 1)

def test02(self):
self.main_config.write(
{'journal_ids': [(6, 0, [self.cash_journal.id])],
'cash_control': True})
# 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()

# I create one move reason
vals = {'name': 'Miscellaneous expense',
'property_account_expense': self.expense_account.id,
'property_account_expense_id': self.expense_account.id,
'expense_pdt': True}
move_reason = self.cash_move_reason_obj.create(vals)
# I set cash control on cash journal
self.cash_journal.cash_control = True
# I create and open a new session
self.session_01 = 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, [self.session_01.id], context=ctx)
ctx['active_ids'] = self.session_01.id
ctx['active_model'] = self.session_01._name
ctx['active_ids'] = self.session.id
ctx['active_model'] = self.session._name

# I put the session in validation control
self.session_01.signal_workflow('cashbox_control')
ctx['active_ids'] = self.session_01.id
ctx['active_model'] = self.session_01._name
self.session.write(
{'state': 'closing_control', 'stop_at': fields.Datetime.now()})

# I create a cash out
cash_out = self.cash_out_obj.with_context(ctx).create(
{'name': 'Miscellaneous expense',
'product_id': move_reason.id,
'amount': 500.0})
cash_out.with_context(ctx).run()
# I close the session
self.session_01.signal_workflow('close')

# close session
self.session.action_pos_session_closing_control()
# I get the statement from the session
statement = self.env['account.bank.statement'].search(
[('pos_session_id', '=', self.session_01.id),
[('pos_session_id', '=', self.session.id),
('journal_id', '=', self.cash_journal.id)])
# I get all move lines of this statement
move_line_ids = statement.move_line_ids.ids
Expand Down
16 changes: 16 additions & 0 deletions pos_cash_move_reason/views/product_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.form.inherit(pos cash move reason)</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="point_of_sale.product_template_form_view"/>
<field name="arch" type="xml">
<field name="to_weight" position="before">
<field name="income_pdt"/>
<field name="expense_pdt"/>
</field>
</field>
</record>
</odoo>
4 changes: 0 additions & 4 deletions pos_cash_move_reason/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import pos_box
45 changes: 24 additions & 21 deletions pos_cash_move_reason/wizard/pos_box.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, exceptions, fields, _
from openerp.addons.point_of_sale.wizard.pos_box import PosBox
from odoo import api, exceptions, fields, _
from odoo.addons.point_of_sale.wizard.pos_box import PosBox

from lxml import etree
import simplejson
try:
import simplejson as json
except ImportError:
import json


class PosBoxCashMoveReason(PosBox):
Expand All @@ -30,7 +33,7 @@ def fields_view_get(self, view_id=None, view_type='form',
modifiers = {'invisible': True, 'required': False}
node.set('invisible', '1')
node.set('required', '0')
node.set('modifiers', simplejson.dumps(modifiers))
node.set('modifiers', json.dumps(modifiers))
else:
for node in doc.xpath("//field[@name='name']"):
node.set('string', _('Description'))
Expand All @@ -45,15 +48,15 @@ class PosBoxIn(PosBoxCashMoveReason):
comodel_name='product.template', string='Reason',
domain="[('income_pdt', '=', True)]")

@api.model
def _compute_values_for_statement_line(self, box, record):
values = super(PosBoxIn, self)._compute_values_for_statement_line(
box, record)
@api.multi
def _calculate_values_for_statement_line(self, record):
values = \
super(PosBoxIn, self)._calculate_values_for_statement_line(record)
if self.env.context.get('active_model', '') == 'pos.session':
if box.product_id.id:
product = box.product_id
account_id = product.property_account_income.id or\
product.categ_id.property_account_income_categ.id
if self.product_id:
product = self.product_id
account_id = product.property_account_income_id.id or\
product.categ_id.property_account_income_categ_id.id
if account_id:
values['account_id'] = account_id
else:
Expand All @@ -69,15 +72,15 @@ class PosBoxOut(PosBoxCashMoveReason):
comodel_name='product.template', string='Reason',
domain="[('expense_pdt', '=', True)]")

@api.model
def _compute_values_for_statement_line(self, box, record):
values = super(PosBoxOut, self)._compute_values_for_statement_line(
box, record)
@api.multi
def _calculate_values_for_statement_line(self, record):
values = \
super(PosBoxOut, self)._calculate_values_for_statement_line(record)
if self.env.context.get('active_model', '') == 'pos.session':
if box.product_id.id:
product = box.product_id
account_id = product.property_account_expense.id or\
product.categ_id.property_account_expense_categ.id
if self.product_id:
product = self.product_id
account_id = product.property_account_expense_id.id or\
product.categ_id.property_account_expense_categ_id.id
if account_id:
values['account_id'] = account_id
else:
Expand Down
6 changes: 4 additions & 2 deletions pos_cash_move_reason/wizard/pos_box.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<!-- Copyright 2016 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<record model="ir.ui.view" id="cash_box_in_form">
<field name="name">cash.box.in.form</field>
Expand All @@ -23,4 +25,4 @@
</field>
</record>
</data>
</openerp>
</odoo>
1 change: 1 addition & 0 deletions setup/pos_cash_move_reason/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions setup/pos_cash_move_reason/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/pos_cash_move_reason/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit f575797

Please sign in to comment.