From 1de11e7e120b6a0c965850a2963eb38b687e027a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Oct 2013 10:22:48 +0100 Subject: [PATCH 1/6] [FIX] account_statement: crash when creating a new bank statement without any lines --- account_statement_ext/statement.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index f8762054..03e1c31c 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -31,9 +31,10 @@ def fixed_write(self, cr, uid, ids, vals, context=None): I will do it when I have time.""" res = super(stat_mod.account_bank_statement, self).write(cr, uid, ids, vals, context=context) - cr.execute("UPDATE account_bank_statement_line" - " SET sequence = account_bank_statement_line.id + 1" - " where statement_id in %s", (tuple(ids),)) + if ids: # will be false for an new empty bank statement + cr.execute("UPDATE account_bank_statement_line" + " SET sequence = account_bank_statement_line.id + 1" + " where statement_id in %s", (tuple(ids),)) return res stat_mod.account_bank_statement.write = fixed_write From 572f28a20196d668d000e65cfb5ccf284bc755c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Oct 2013 10:23:29 +0100 Subject: [PATCH 2/6] [ADD] new module makine Point Of Sale compatible with bank profiles --- .../__init__.py | 22 +++++ .../__openerp__.py | 43 +++++++++ .../point_of_sale.py | 95 +++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 account_statement_ext_point_of_sale/__init__.py create mode 100644 account_statement_ext_point_of_sale/__openerp__.py create mode 100644 account_statement_ext_point_of_sale/point_of_sale.py diff --git a/account_statement_ext_point_of_sale/__init__.py b/account_statement_ext_point_of_sale/__init__.py new file mode 100644 index 00000000..2f5d1c8e --- /dev/null +++ b/account_statement_ext_point_of_sale/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# +# 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 . +# +############################################################################## + +import point_of_sale diff --git a/account_statement_ext_point_of_sale/__openerp__.py b/account_statement_ext_point_of_sale/__openerp__.py new file mode 100644 index 00000000..9e06022c --- /dev/null +++ b/account_statement_ext_point_of_sale/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Nicolas Bessi, Joel Grand-Guillaume +# Copyright 2011-2013 Camptocamp SA +# +# 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 . +# +############################################################################## + +{'name': "Bank statement extension and profiles for Point of Sale", + 'version': '1.0.0', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'category': 'Point Of Sale', + 'complexity': 'normal', + 'depends': ['point_of_sale', + 'account_statement_ext', + ], + 'description': """ + Update the point of sale code to work with improved bank statements. + """, + 'website': 'http://www.camptocamp.com', + 'data': [], + 'demo': [], + 'test': [], + 'installable': True, + 'images': [], + 'auto_install': True, + 'license': 'AGPL-3', + 'active': False, + } diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py new file mode 100644 index 00000000..a765a596 --- /dev/null +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# +# 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 . +# +############################################################################## +from openerp.addons.point_of_sale.point_of_sale import pos_session as std_pos_session +from openerp.osv import orm, osv +from openerp.tools.translate import _ + +if not hasattr(std_pos_session, '_prepare_bank_statement'): + # monkey patch to fix lp:1245375 + def mp_prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): + bank_values = { + 'journal_id' : journal.id, + 'user_id' : uid, + 'company_id' : pos_config.shop_id.company_id.id + } + return bank_values + + def mp_create(self, cr, uid, values, context=None): + context = context or {} + config_id = values.get('config_id', False) or context.get('default_config_id', False) + if not config_id: + raise osv.except_osv( _('Error!'), + _("You should assign a Point of Sale to your session.")) + + # journal_id is not required on the pos_config because it does not + # exists at the installation. If nothing is configured at the + # installation we do the minimal configuration. Impossible to do in + # the .xml files as the CoA is not yet installed. + jobj = self.pool.get('pos.config') + pos_config = jobj.browse(cr, uid, config_id, context=context) + context.update({'company_id': pos_config.shop_id.company_id.id}) + if not pos_config.journal_id: + jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] + if jid: + jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context) + else: + raise osv.except_osv( _('error!'), + _("Unable to open the session. You have to assign a sale journal to your point of sale.")) + + # define some cash journal if no payment method exists + if not pos_config.journal_ids: + journal_proxy = self.pool.get('account.journal') + cashids = journal_proxy.search(cr, uid, [('journal_user', '=', True), ('type','=','cash')], context=context) + if not cashids: + cashids = journal_proxy.search(cr, uid, [('type', '=', 'cash')], context=context) + if not cashids: + cashids = journal_proxy.search(cr, uid, [('journal_user','=',True)], context=context) + + jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) + + + pos_config = jobj.browse(cr, uid, config_id, context=context) + bank_statement_ids = [] + print pos_config.journal_ids + for journal in pos_config.journal_ids: + bank_values = self._prepare_bank_statement(cr, uid, pos_config, journal, context) + statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) + bank_statement_ids.append(statement_id) + + values.update({ + 'name' : pos_config.sequence_id._next(), + 'statement_ids' : [(6, 0, bank_statement_ids)], + 'config_id': config_id + }) + return super(std_pos_session, self).create(cr, uid, values, context=context) + + std_pos_session._prepare_bank_statement = mp_prepare_bank_statement + std_pos_session.create = mp_create + + +class pos_session(orm.Model): + _inherit = 'pos.session' + + def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): + bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, pos_config, journal, context) + defaults = self.pool['account.bank.statement'].default_get(cr, uid, ['profile_id', 'period_id'], context=context) + bank_values.update(defaults) + return bank_values From 1542a46695ef2efe4e8038467edd66f57df8462b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Nov 2013 16:57:28 +0100 Subject: [PATCH 3/6] [FIX] select the correct profile when creating the bank statement --- account_statement_ext_point_of_sale/point_of_sale.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py index a765a596..06384dd3 100644 --- a/account_statement_ext_point_of_sale/point_of_sale.py +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -68,7 +68,6 @@ if not hasattr(std_pos_session, '_prepare_bank_statement'): pos_config = jobj.browse(cr, uid, config_id, context=context) bank_statement_ids = [] - print pos_config.journal_ids for journal in pos_config.journal_ids: bank_values = self._prepare_bank_statement(cr, uid, pos_config, journal, context) statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) @@ -90,6 +89,12 @@ class pos_session(orm.Model): def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, pos_config, journal, context) + user_obj = self.pool.get('res.users') + profile_obj = self.pool.get('account.statement.profile') + user = user_obj.browse(cr, uid, uid, context=context) defaults = self.pool['account.bank.statement'].default_get(cr, uid, ['profile_id', 'period_id'], context=context) + profile_ids = profile_obj.search(cr, uid, [('company_id', '=', user.company_id.id), ('journal_id', '=', bank_values['journal_id'])], context=context) + if profile_ids: + defaults['profile_id'] = profile_ids[0] bank_values.update(defaults) return bank_values From 1c4a105a5f28f734e9e76c40726aef6ccca209b0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2013 08:04:05 +0100 Subject: [PATCH 4/6] [PEP8] --- account_statement_ext_point_of_sale/__init__.py | 2 +- account_statement_ext_point_of_sale/__openerp__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/account_statement_ext_point_of_sale/__init__.py b/account_statement_ext_point_of_sale/__init__.py index 2f5d1c8e..05435f81 100644 --- a/account_statement_ext_point_of_sale/__init__.py +++ b/account_statement_ext_point_of_sale/__init__.py @@ -19,4 +19,4 @@ # ############################################################################## -import point_of_sale +from . import point_of_sale diff --git a/account_statement_ext_point_of_sale/__openerp__.py b/account_statement_ext_point_of_sale/__openerp__.py index 9e06022c..6d4b7a8f 100644 --- a/account_statement_ext_point_of_sale/__openerp__.py +++ b/account_statement_ext_point_of_sale/__openerp__.py @@ -29,7 +29,7 @@ 'account_statement_ext', ], 'description': """ - Update the point of sale code to work with improved bank statements. + Update the point of sale code to work with improved bank statements. """, 'website': 'http://www.camptocamp.com', 'data': [], From 93e04e145ab9d7f357da51b81bbc6f2c75d33d39 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2013 08:16:39 +0100 Subject: [PATCH 5/6] [IMP] explain what the monkey patching bit is about --- account_statement_ext_point_of_sale/point_of_sale.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py index 06384dd3..729a53b3 100644 --- a/account_statement_ext_point_of_sale/point_of_sale.py +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -24,6 +24,16 @@ from openerp.tools.translate import _ if not hasattr(std_pos_session, '_prepare_bank_statement'): # monkey patch to fix lp:1245375 + # + # We replace pos_session.create with the implementation in + # mp_create below which is essentially the same, only with a call + # to self._prepare_bank_statement. + # + # The default implementation has been extracted in + # mp_prepare_bank_statement below, and can be overridden in models + # which _inherit pos.session + # + # This change has been proposed for merging to fix lp:125375 def mp_prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): bank_values = { 'journal_id' : journal.id, From 369de56d845502fd7e742d4e065452e0edee4407 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2013 08:31:36 +0100 Subject: [PATCH 6/6] [IMP][PEP8] fixed + add a doc string to explicit fact _prepare_statement does not originally exist on base model --- .../point_of_sale.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py index 729a53b3..31e23418 100644 --- a/account_statement_ext_point_of_sale/point_of_sale.py +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -98,12 +98,25 @@ class pos_session(orm.Model): _inherit = 'pos.session' def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): - bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, pos_config, journal, context) + """ Override the function _mp_create. To add the bank profile to the statement + + Function That was previously added to pos.session model using monkey patching + + """ + + bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, + pos_config, + journal, context) user_obj = self.pool.get('res.users') profile_obj = self.pool.get('account.statement.profile') user = user_obj.browse(cr, uid, uid, context=context) - defaults = self.pool['account.bank.statement'].default_get(cr, uid, ['profile_id', 'period_id'], context=context) - profile_ids = profile_obj.search(cr, uid, [('company_id', '=', user.company_id.id), ('journal_id', '=', bank_values['journal_id'])], context=context) + defaults = self.pool['account.bank.statement'].default_get(cr, uid, + ['profile_id', 'period_id'], + context=context) + profile_ids = profile_obj.search(cr, uid, + [('company_id', '=', user.company_id.id), + ('journal_id', '=', bank_values['journal_id'])], + context=context) if profile_ids: defaults['profile_id'] = profile_ids[0] bank_values.update(defaults)