Browse Source

[WIP] porting pos_change_payment from V7;

pull/54/head
Sylvain LE GAL 9 years ago
parent
commit
e6431f5a17
  1. 72
      pos_change_payment/README.rst
  2. 3
      pos_change_payment/__init__.py
  3. 39
      pos_change_payment/__openerp__.py
  4. 168
      pos_change_payment/i18n/fr.po
  5. 9
      pos_change_payment/model/__init__.py
  6. 97
      pos_change_payment/model/account_bank_statement_line.py
  7. 59
      pos_change_payment/model/account_journal.py
  8. 98
      pos_change_payment/model/pos_change_payments_wizard.py
  9. 43
      pos_change_payment/model/pos_change_payments_wizard_line.py
  10. 79
      pos_change_payment/model/pos_make_payment.py
  11. 80
      pos_change_payment/model/pos_order.py
  12. 145
      pos_change_payment/model/pos_switch_journal_wizard.py
  13. BIN
      pos_change_payment/static/src/description/bank_statement_change_journal.png
  14. BIN
      pos_change_payment/static/src/description/icon.png
  15. BIN
      pos_change_payment/static/src/description/pos_order_change_journal.png
  16. 42
      pos_change_payment/view/action.xml
  17. 105
      pos_change_payment/view/view.xml

72
pos_change_payment/README.rst

@ -0,0 +1,72 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
Improve payment changes when user did a mistake and disable some actions on POS
Bank Statement Line
===============================================================================
====================
Functionality:
--------------
* Add the possibility to switch a POS payment (account.bank.statement.line)
of a POS Order from a Journal to another. This feature is usefull when
the user realized that he did a mistake, during the close of the session,
or just after he marked the POS as paid;
(Only if entries has not been generated)
* Add the possibility to change all payments (method and amount) of a POS;
(Only if entries has not been generated)
Bug Fixes / Improvement:
------------------------
* In the pos.payment wizard, display only the payment methods defined in
the current POS session;
* Disable the possibility to edit / delete a bank statement line on a POS
Order that has generated his entries, except using the wizard of this
module. This will prevent the generation of bad account move during
the close of the session; (mainly unbalanced moves)
* All the cash payment are merged into a single one statement line. this
feature is usefull if the user use OpenERP as a calculator, writing
for a payment:
* Payment 1/ Cash 50 €;
* Payment 2/ Cash -3,56 €;
* With this module, the final statement line is a single line
Payment 1/ Cash 46,44 €
Usage
=====
Installation
============
Nothing special is needed to install this module.
Configuration
=============
No configuration needed.
Credits
=======
Contributors
------------
* Sylvain LE GAL (https://twitter.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.

3
pos_change_payment/__init__.py

@ -0,0 +1,3 @@
# -*- encoding: utf-8 -*-
from . import model

39
pos_change_payment/__openerp__.py

@ -0,0 +1,39 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2013-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Point Of Sale - Change Payment',
'summary': """Improve payment changes when user did a mistake and"""
""" disable some actions on POS Bank Statement Line""",
'version': '8.0.1.0.0',
'category': 'Point Of Sale',
'author': 'GRAP',
'website': 'http://www.grap.coop',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
],
'data': [
'view/action.xml',
'view/view.xml',
],
}

168
pos_change_payment/i18n/fr.po

@ -0,0 +1,168 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * pos_change_payment
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-04-01 14:25+0000\n"
"PO-Revision-Date: 2015-04-01 14:25+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_change_payment
#: field:pos.change.payments.wizard.line,amount:0
#: field:pos.switch.journal.wizard,amount:0
msgid "Amount"
msgstr "Montant"
#. module: pos_change_payment
#: code:_description:0
#: model:ir.model,name:pos_change_payment.model_account_bank_statement_line
#, python-format
msgid "Bank Statement Line"
msgstr "Ligne de relevé de banque"
#. module: pos_change_payment
#: view:pos.change.payments.wizard:0
#: view:pos.switch.journal.wizard:0
msgid "Cancel"
msgstr "Annuler"
#. module: pos_change_payment
#: model:ir.actions.act_window,name:pos_change_payment.action_pos_change_payments_wizard
#: view:pos.change.payments.wizard:0
#: view:pos.order:0
msgid "Change Payments"
msgstr "Changer les paiements"
#. module: pos_change_payment
#: code:addons/pos_change_payment/model/pos_change_payments_wizard.py:77
#, python-format
msgid "Differences between the two values for the POS Order '%s':\n"
"\n"
" * Total of all the new payments %s;\n"
" * Total of the POS Order %s;\n"
"\n"
"Please change the payments."
msgstr "Différences entre les deux valeurs pour la vente '%s':\n"
"\n"
" * Total des nouveaux paiements %s;\n"
" * Total de la vente %s;\n"
"\n"
"Veuillez changer les paiements."
#. module: pos_change_payment
#: code:addons/pos_change_payment/model/account_bank_statement_line.py:78
#: code:addons/pos_change_payment/model/pos_change_payments_wizard.py:36
#: code:addons/pos_change_payment/model/pos_change_payments_wizard.py:72
#: code:addons/pos_change_payment/model/pos_order.py:76
#: code:addons/pos_change_payment/model/pos_switch_journal_wizard.py:64
#, python-format
msgid "Error!"
msgstr "Erreur !"
#. module: pos_change_payment
#: code:addons/pos_change_payment/model/pos_change_payments_wizard.py:36
#: code:addons/pos_change_payment/model/pos_switch_journal_wizard.py:64
#, python-format
msgid "Incorrect Call!"
msgstr "Appel incorrect !"
#. module: pos_change_payment
#: code:_description:0
#: model:ir.model,name:pos_change_payment.model_account_journal
#: field:pos.change.payments.wizard.line,journal_id:0
#, python-format
msgid "Journal"
msgstr "Journal"
#. module: pos_change_payment
#: field:pos.switch.journal.wizard,new_statement_id:0
msgid "New Journal"
msgstr "Nouveau journal"
#. module: pos_change_payment
#: field:pos.switch.journal.wizard,old_journal_id:0
msgid "Old Journal"
msgstr "Ancien journal"
#. module: pos_change_payment
#: field:pos.change.payments.wizard,order_id:0
msgid "POS Order"
msgstr "Vente"
#. module: pos_change_payment
#: view:pos.order:0
msgid "Payment"
msgstr "Paiement"
#. module: pos_change_payment
#: view:pos.change.payments.wizard:0
msgid "Payment Lines"
msgstr "Lignes de paiement"
#. module: pos_change_payment
#: code:_description:0
#: model:ir.model,name:pos_change_payment.model_pos_order
#, python-format
msgid "Point of Sale"
msgstr "Point de Vente"
#. module: pos_change_payment
#: code:_description:0
#: model:ir.model,name:pos_change_payment.model_pos_make_payment
#, python-format
msgid "Point of Sale Payment"
msgstr "Paiement du ticket"
#. module: pos_change_payment
#: field:pos.switch.journal.wizard,statement_line_id:0
msgid "Statement"
msgstr "Relevé bancaire"
#. module: pos_change_payment
#: view:account.bank.statement:0
#: model:ir.actions.act_window,name:pos_change_payment.action_pos_switch_journal_wizard
#: view:pos.order:0
#: view:pos.switch.journal.wizard:0
msgid "Switch Journal"
msgstr "Changer de Journal"
#. module: pos_change_payment
#: field:pos.change.payments.wizard,amount_total:0
msgid "Total"
msgstr "Total"
#. module: pos_change_payment
#: field:pos.change.payments.wizard,line_ids:0
msgid "Wizard Lines"
msgstr "Lignes"
#. module: pos_change_payment
#: field:pos.change.payments.wizard.line,wizard_id:0
msgid "Wizard Ref"
msgstr "Référence"
#. module: pos_change_payment
#: code:addons/pos_change_payment/model/account_bank_statement_line.py:79
#, python-format
msgid "You can not change payments of POS by this way. Please use the regular wizard in POS view!"
msgstr "Vous ne pouvez pas changer les paiements de cette vente de cette façon. Veuillez utiliser l'interface prévue à cet effet dans la vue de la vente !"
#. module: pos_change_payment
#: code:addons/pos_change_payment/model/pos_order.py:78
#, python-format
msgid "You can not change payments of the POS '%s' because the associated session '%s' has been closed!"
msgstr "Vous ne pouvez pas changer les paiements de la Vente '%s' car la session associée '%s' a été clôturé !"
#. module: pos_change_payment
#: view:pos.change.payments.wizard:0
#: view:pos.switch.journal.wizard:0
msgid "or"
msgstr "ou"

9
pos_change_payment/model/__init__.py

@ -0,0 +1,9 @@
# -*- encoding: utf-8 -*-
from . import account_journal
from . import pos_order
from . import account_bank_statement_line
from . import pos_make_payment
from . import pos_switch_journal_wizard
from . import pos_change_payments_wizard
from . import pos_change_payments_wizard_line

97
pos_change_payment/model/account_bank_statement_line.py

@ -0,0 +1,97 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Multiple Cash Control module for Odoo
# Copyright (C) 2015-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv.orm import Model
from openerp.osv.osv import except_osv
from openerp.tools.translate import _
class account_bank_statement_line(Model):
_inherit = 'account.bank.statement.line'
_POS_PAYMENT_ALLOW_WRITE = [
'sequence', 'move_ids',
]
# Private Function Section
def _check_allow_change_pos_payment(
self, cr, uid, ids, vals, context=None):
"""Allow or block change of account bank statement line, linked to
a non draft POS Order.
* if 'change_pos_payment' is in the context, changes are allowed;
* otherwise:
* allow write of some fields only;
* forbid deletion;"""
context = context or {}
values = vals.copy() if vals else {}
check_pos_order = False
po_obj = self.pool['pos.order']
if not ids:
return True
if values:
# Allow some write
for key in self._POS_PAYMENT_ALLOW_WRITE:
if key in values:
del values[key]
if not values:
return True
# Allow changes, if user use the wizard
if context.get('change_pos_payment', False):
check_pos_order = True
for absl in self.browse(cr, uid, ids, context=context):
if absl.pos_statement_id:
if absl.pos_statement_id.state != 'draft':
if check_pos_order:
po_obj._allow_change_payments(
cr, uid, [absl.pos_statement_id.id],
context=context)
else:
if values.keys() == ['partner_id']:
po_obj._allow_change_payments(
cr, uid, [absl.pos_statement_id.id],
context=context)
else:
raise except_osv(
_('Error!'),
_("""You can not change payments of POS by"""
""" this way. Please use the regular"""
""" wizard in POS view!"""))
return True
# Overload Section
def write(self, cr, uid, ids, vals, context=None):
self._check_allow_change_pos_payment(
cr, uid, ids, vals, context=context)
res = super(account_bank_statement_line, self).write(
cr, uid, ids, vals, context=context)
return res
def unlink(self, cr, uid, ids, context=None):
self._check_allow_change_pos_payment(
cr, uid, ids, None, context=context)
res = super(account_bank_statement_line, self).unlink(
cr, uid, ids, context=context)
return res

59
pos_change_payment/model/account_journal.py

@ -0,0 +1,59 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2013-Today GRAP (http://www.grap.coop)
# @author Julien WESTE
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv.orm import Model
class account_journal(Model):
_inherit = 'account.journal'
# Private Function Section
def _get_pos_journal_selection(
self, cr, uid, context=None):
"""Return Account Journal available for payment in PoS Module"""
if not context or not context.get('pos_session_id', False):
return False
aj_obj = self.pool['account.journal']
ps_obj = self.pool['pos.session']
# Get Session of the Current PoS
ps = ps_obj.browse(
cr, uid, context.get('pos_session_id'), context=context)
aj_ids = [j.id for j in ps.journal_ids]
# Get Journals, order by type (cash before), and name
aj_cash_ids = aj_obj.search(cr, uid, [
('id', 'in', aj_ids), ('type', '=', 'cash')], context=context)
cash_res = aj_obj.read(
cr, uid, aj_cash_ids, ['name', 'id'], context=context)
cash_res = [(r['id'], r['name']) for r in cash_res]
aj_other_ids = aj_obj.search(
cr, uid, [
('id', 'in', aj_ids), ('type', '!=', 'cash')
], context=context)
other_res = aj_obj.read(
cr, uid, aj_other_ids, ['name', 'id'], context=context)
other_res = [(r['id'], r['name']) for r in other_res]
return cash_res + other_res

98
pos_change_payment/model/pos_change_payments_wizard.py

@ -0,0 +1,98 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2015-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields
from openerp.osv.osv import except_osv
from openerp.osv.orm import TransientModel
from openerp.tools.translate import _
class pos_change_payments_wizard(TransientModel):
_name = 'pos.change.payments.wizard'
# View Section
def default_get(self, cr, uid, fields, context=None):
po_obj = self.pool['pos.order']
if context.get('active_model', False) != 'pos.order':
raise except_osv(_('Error!'), _('Incorrect Call!'))
res = super(pos_change_payments_wizard, self).default_get(
cr, uid, fields, context=context)
po = po_obj.browse(
cr, uid, context.get('active_id'), context=context)
res.update({'order_id': po.id})
res.update({'amount_total': po.amount_total})
return res
# Column Section
_columns = {
'order_id': fields.many2one(
'pos.order', 'POS Order', required=True, readonly=True),
'line_ids': fields.one2many(
'pos.change.payments.wizard.line', 'wizard_id', 'Wizard Lines'),
'amount_total': fields.float(
'Total', readonly=True),
}
# Action section
def button_change_payments(self, cr, uid, ids, context=None):
po_obj = self.pool['pos.order']
absl_obj = self.pool['account.bank.statement.line']
ctx = context.copy()
ctx['change_pos_payment'] = True
for pcpw in self.browse(cr, uid, ids, context=context):
po = po_obj.browse(cr, uid, pcpw.order_id.id, context=context)
# Check if the total is correct
total = 0
for line in pcpw.line_ids:
total += line.amount
if total != pcpw.amount_total:
raise except_osv(
_('Error!'),
_("""Differences between the two values for the POS"""
""" Order '%s':\n\n"""
""" * Total of all the new payments %s;\n"""
""" * Total of the POS Order %s;\n\n"""
"""Please change the payments.""" % (
po.name, total, po.amount_total)))
# Check if change payments is allowed
po_obj._allow_change_payments(
cr, uid, [po.id], context=context)
# Remove old statements
absl_obj.unlink(
cr, uid, [x.id for x in po.statement_ids], context=ctx)
# Create new payment
for line in pcpw.line_ids:
po_obj.add_payment(cr, uid, po.id, {
'journal': int(line.journal_id),
'amount': line.amount,
}, context=context)
return {
'type': 'ir.actions.client',
'tag': 'reload',
}

43
pos_change_payment/model/pos_change_payments_wizard_line.py

@ -0,0 +1,43 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2015-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields
from openerp.osv.orm import TransientModel
class pos_change_payments_wizard_line(TransientModel):
_name = 'pos.change.payments.wizard.line'
# Selection Section
def _select_journals(self, cr, uid, context=None):
aj_obj = self.pool['account.journal']
return aj_obj._get_pos_journal_selection(cr, uid, context=context)
# Column Section
_columns = {
'wizard_id': fields.many2one(
'pos.change.payments.wizard', 'Wizard Ref', ondelete='cascade'),
'journal_id': fields.selection(
_select_journals, 'Journal', required=True),
'amount': fields.float(
'Amount'),
}

79
pos_change_payment/model/pos_make_payment.py

@ -0,0 +1,79 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2013-Today GRAP (http://www.grap.coop)
# @author Julien WESTE
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv.orm import TransientModel
from openerp.osv import fields
from openerp import netsvc
class pos_make_payment(TransientModel):
_inherit = 'pos.make.payment'
def check(self, cr, uid, ids, context=None):
"""Check the order:
if the order is not paid: continue payment,
if the order is paid print ticket.
"""
context = context or {}
order_obj = self.pool.get('pos.order')
active_id = context and context.get('active_id', False)
order = order_obj.browse(cr, uid, active_id, context=context)
amount = order.amount_total - order.amount_paid
data = self.read(cr, uid, ids, context=context)[0]
data['journal'] = data['journal_id']
if amount != 0.0:
order_obj.add_payment(cr, uid, active_id, data, context=context)
if order_obj.test_paid(cr, uid, [active_id]):
wf_service = netsvc.LocalService('workflow')
wf_service.trg_validate(uid, 'pos.order', active_id, 'paid', cr)
return {'type': 'ir.actions.act_window_close'}
return self.launch_payment(cr, uid, ids, context=context)
# Selection Section
def _select_journals(self, cr, uid, context=None):
aj_obj = self.pool['account.journal']
return aj_obj._get_pos_journal_selection(cr, uid, context=context)
# Column Section
_columns = {
# Redefine journal_id from many2one to selection
'journal_id': fields.selection(
_select_journals, 'Journal', required=True, size=-1),
}
# Default Section
def _default_journal(self, cr, uid, context=None):
aj_obj = self.pool['account.journal']
res = aj_obj._get_pos_journal_selection(cr, uid, context=context)
if res and len(res) > 1:
return res[0][0]
else:
return False
_defaults = {
'journal_id': _default_journal,
}

80
pos_change_payment/model/pos_order.py

@ -0,0 +1,80 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2013-Today GRAP (http://www.grap.coop)
# @author Julien WESTE
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv.orm import Model
from openerp.osv.osv import except_osv
from openerp.tools.translate import _
class pos_order(Model):
_inherit = 'pos.order'
def _merge_cash_payment(self, cr, uid, ids, context=None):
absl_obj = self.pool['account.bank.statement.line']
for po in self.browse(cr, uid, ids, context=context):
absl_cash_ids = [
x.id for x in po.statement_ids
if x.statement_id.journal_id.type == 'cash']
new_payments = {}
for line in absl_obj.read(
cr, uid, absl_cash_ids,
['statement_id', 'amount'],
context=context):
if line['statement_id'][0] in new_payments.keys():
new_payments[line['statement_id'][0]] += line['amount']
else:
new_payments[line['statement_id'][0]] = line['amount']
# Delete all obsolete account bank statement line
absl_obj.unlink(cr, uid, absl_cash_ids, context=context)
# Create a new ones
for k, v in new_payments.items():
self.add_payment(cr, uid, po.id, {
'statement_id': k,
'amount': v
}, context=context)
# Overload Section
def action_paid(self, cr, uid, ids, context=None):
""" Merge all cash statement line of the Order"""
context = context or {}
ctx = context.copy()
ctx['change_pos_payment'] = True
self._merge_cash_payment(cr, uid, ids, context=ctx)
return super(pos_order, self).action_paid(
cr, uid, ids, context=context)
# Private Function Section
def _allow_change_payments(
self, cr, uid, ids, context=None):
"""Return True if the user can change the payment of a POS, depending
of the state of the current session."""
for po in self.browse(cr, uid, ids, context=context):
if po.session_id.state == 'closed':
raise except_osv(
_('Error!'),
_("""You can not change payments of the POS '%s' because"""
""" the associated session '%s' has been closed!""" % (
po.name, po.session_id.name)))
return True

145
pos_change_payment/model/pos_switch_journal_wizard.py

@ -0,0 +1,145 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Point Of Sale - Change Payment module for Odoo
# Copyright (C) 2015-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#from openerp.osv import fields
#from openerp.osv.osv import except_osv
from openerp.exceptions import ValidationError
from openerp import models, api, fields
from openerp.tools.translate import _
class PosSwitchJournalWizard(models.TransientModel):
_name = 'pos.switch.journal.wizard'
# Default Section
def _default_statement_line_id(self):
return self._context.get('active_id')
# Column Section
statement_line_id = fields.Many2one(
comodel_name='account.bank.statement.line', string='Statement',
required=True, readonly=True, default=_default_statement_line_id)
old_journal_id = fields.Many2one(
comodel_name='account.journal', string='Old Journal', required=True,
readonly=True)
available_journal_ids = fields.Many2many(
comodel_name='account.journal',
compute='_compute_available_journal_ids')
new_journal_id = fields.Many2one(
comodel_name='account.journal', string='New Journal',
domain="[('id', 'in', available_journal_ids)]")
amount = fields.Float(string='Amount', readonly=True)
new_statement_id = fields.Many2one()
# Compute Section
@api.one
@api.depends('statement_line_id')
def _compute_available_journal_ids(self):
res = []
for statement in self.statement_line_id.pos_statement_id\
.session_id.statement_ids:
res.append(statement.journal_id.id)
self.available_journal_ids = res
# selection='_get_new_statement_id', string='New Journal',
# required=True),
# @api.model
# def _get_new_statement_id(self, cr, uid, context=None):
# absl_obj = self.pool['account.bank.statement.line']
# abs_obj = self.pool['account.bank.statement']
# if context.get('active_model', False) != 'account.bank.statement.line':
# return True
# absl = absl_obj.browse(
# cr, uid, context.get('active_id'), context=context)
# abs_ids = [
# x.id for x in absl.pos_statement_id.session_id.statement_ids]
# res = abs_obj.read(
# cr, uid, abs_ids, ['id', 'journal_id'], context=context)
# res = [(
# r['id'], r['journal_id'][1])
# for r in res if r['id'] != absl.statement_id.id]
# return res
# _columns = {
# }
# View Section
# @api.model
# def default_get(self, fields):
# statement_line_obj = self.env['account.bank.statement.line']
# res = super(PosSwitchJournalWizard, self).default_get(fields)
# statement_line = statement_line_obj.browse(
# self._context.get('active_id'))
# self.statement_line_id = statement_line.id
# res.update({
## 'statement_line_id': statement_line.id,
# 'old_journal_id': statement_line.journal_id.id,
# 'amount': statement_line.amount,
# })
# return res
# Action section
@api.one
def button_switch_journal(self):
# if self.statement_line_id.pos_statement_id:
self.statement_line_id.pos_statement_id._allow_change_payments()
# TODO : FIXME when upstream is fixed.
# We do 2 write, one in the old statement, one in the new, with
# 'amount' value each time to recompute all the functional fields
# of the Account Bank Statements
# self.statement_line_id.with_context(change_pos_payment=True).write({
# 'amount': 0,
# })
# self.statement_line_id.with_context(change_pos_payment=True).write({
# 'amount': self.statement_line_id.amount,
# 'statement_id': self.new_statement_id.id,
# })
# amount = absl.amount
# ctx = context.copy()
# ctx['change_pos_payment'] = True
# absl_obj.write(cr, uid, [absl.id], {
# 'amount': 0,
# }, context=ctx)
# # Change statement of the statement line
# absl_obj.write(cr, uid, [absl.id], {
# 'amount': amount,
# 'statement_id': int(psjw.new_statement_id),
# }, context=ctx)
return {
'type': 'ir.actions.client',
'tag': 'reload',
}

BIN
pos_change_payment/static/src/description/bank_statement_change_journal.png

After

Width: 854  |  Height: 380  |  Size: 27 KiB

BIN
pos_change_payment/static/src/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 8.6 KiB

BIN
pos_change_payment/static/src/description/pos_order_change_journal.png

After

Width: 876  |  Height: 348  |  Size: 21 KiB

42
pos_change_payment/view/action.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ********************************************************************** -->
<!--Point Of Sale - Change Payment module for Odoo -->
<!--Copyright (C) 2015-Today GRAP (http://www.grap.coop) -->
<!--@author Sylvain LE GAL (https://twitter.com/legalsylvain) -->
<!--This program is free software: you can redistribute it and/or modify -->
<!--it under the terms of the GNU Affero General Public License as -->
<!--published by the Free Software Foundation, either version 3 of the -->
<!--License, or (at your option) any later version. -->
<!--This program is distributed in the hope that it will be useful, -->
<!--but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!--GNU Affero General Public License for more details. -->
<!--You should have received a copy of the GNU Affero General Public License-->
<!--along with this program. If not, see <http://www.gnu.org/licenses/>. -->
<!-- ********************************************************************** -->
<openerp>
<data>
<!-- Model: pos.switch.journal.wizard-->
<record id="action_pos_switch_journal_wizard" model="ir.actions.act_window">
<field name="name">Switch Journal</field>
<field name="res_model">pos.switch.journal.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- Model: pos.change.payments.wizard-->
<record id="action_pos_change_payments_wizard" model="ir.actions.act_window">
<field name="name">Change Payments</field>
<field name="res_model">pos.change.payments.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>

105
pos_change_payment/view/view.xml

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ********************************************************************** -->
<!--Point Of Sale - Change Payment module for Odoo -->
<!--Copyright (C) 2015-Today GRAP (http://www.grap.coop) -->
<!--@author Sylvain LE GAL (https://twitter.com/legalsylvain) -->
<!--This program is free software: you can redistribute it and/or modify -->
<!--it under the terms of the GNU Affero General Public License as -->
<!--published by the Free Software Foundation, either version 3 of the -->
<!--License, or (at your option) any later version. -->
<!--This program is distributed in the hope that it will be useful, -->
<!--but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!--GNU Affero General Public License for more details. -->
<!--You should have received a copy of the GNU Affero General Public License-->
<!--along with this program. If not, see <http://www.gnu.org/licenses/>. -->
<!-- ********************************************************************** -->
<openerp>
<data>
<!-- Model: pos.order -->
<record id="view_pos_order_form" model="ir.ui.view">
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form" />
<field name="arch" type="xml">
<button string="Payment" position="attributes">
<attribute name="context">{'pos_session_id' : session_id}</attribute>
</button>
<button name="refund" position="before">
<button name="%(action_pos_change_payments_wizard)d"
context="{'pos_session_id' : session_id}"
string="Change Payments" type="action" states="paid,invoiced"/>
</button>
<field name="journal_id" position="after">
<button name="%(action_pos_switch_journal_wizard)d" string="Switch Journal"
type="action" icon="gtk-index"/>
</field>
</field>
</record>
<!-- Model: account.bank.statement -->
<record id="view_account_bank_statement_form" model="ir.ui.view">
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='line_ids']/tree/field[@name='amount']" position="after">
<field name="pos_statement_id" invisible="1" />
<button name="%(action_pos_switch_journal_wizard)d" string="Switch Journal" type="action" icon="gtk-index" attrs="{'invisible':[('pos_statement_id', '=', False)]}"/>
</xpath>
</field>
</record>
<!-- Model: pos.switch.journal.wizard-->
<record id="view_pos_switch_journal_wizard_form" model="ir.ui.view">
<field name="model">pos.switch.journal.wizard</field>
<field name="arch" type="xml">
<form string="Switch Journal">
<group col="4">
<field name="statement_line_id" />
<field name="old_journal_id" />
<field name="new_journal_id" />
<field name="available_journal_ids" />
<field name="new_statement_id" />
<field name="amount" />
</group>
<footer>
<button name="button_switch_journal" string="Switch Journal" type="object" class="oe_highlight"/>
<label string="or" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Model: pos.switch.journal.wizard-->
<record id="view_pos_change_payments_wizard_form" model="ir.ui.view">
<field name="model">pos.change.payments.wizard</field>
<field name="arch" type="xml">
<form string="Change Payments" version="7.0">
<group col="4">
<field name="order_id" />
<field name="amount_total" />
<field name="line_ids" colspan="4">
<tree string="Payment Lines" editable="bottom">
<field name="journal_id" />
<field name="amount" />
</tree>
</field>
</group>
<footer>
<button name="button_change_payments" string="Change Payments" type="object" class="oe_highlight"/>
<label string="or" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save