From 05573d753a3cd0f6e2caa479bf7f8fd8d05f314b Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Tue, 10 Mar 2015 16:00:20 +0100 Subject: [PATCH] [ADD] new module pos_keep_draft_orders to manage Slate --- pos_keep_draft_orders/__init__.py | 24 ++++ pos_keep_draft_orders/__openerp__.py | 75 ++++++++++ pos_keep_draft_orders/demo/pos_config.yml | 24 ++++ pos_keep_draft_orders/i18n/fr.po | 55 ++++++++ pos_keep_draft_orders/model/__init__.py | 26 ++++ pos_keep_draft_orders/model/pos_config.py | 39 +++++ pos_keep_draft_orders/model/pos_order.py | 43 ++++++ pos_keep_draft_orders/model/pos_session.py | 65 +++++++++ pos_keep_draft_orders/static/src/img/icon.png | Bin 0 -> 4639 bytes pos_keep_draft_orders/tests/__init__.py | 28 ++++ .../tests/test_pos_keep_draft_orders.py | 133 ++++++++++++++++++ pos_keep_draft_orders/view/view.xml | 49 +++++++ 12 files changed, 561 insertions(+) create mode 100644 pos_keep_draft_orders/__init__.py create mode 100644 pos_keep_draft_orders/__openerp__.py create mode 100644 pos_keep_draft_orders/demo/pos_config.yml create mode 100644 pos_keep_draft_orders/i18n/fr.po create mode 100644 pos_keep_draft_orders/model/__init__.py create mode 100644 pos_keep_draft_orders/model/pos_config.py create mode 100644 pos_keep_draft_orders/model/pos_order.py create mode 100644 pos_keep_draft_orders/model/pos_session.py create mode 100644 pos_keep_draft_orders/static/src/img/icon.png create mode 100644 pos_keep_draft_orders/tests/__init__.py create mode 100644 pos_keep_draft_orders/tests/test_pos_keep_draft_orders.py create mode 100644 pos_keep_draft_orders/view/view.xml diff --git a/pos_keep_draft_orders/__init__.py b/pos_keep_draft_orders/__init__.py new file mode 100644 index 00000000..e1d5cb5b --- /dev/null +++ b/pos_keep_draft_orders/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# POS Keep Draft Orders module for Odoo +# Copyright (C) 2013-2014 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 . +# +############################################################################## + +from . import model diff --git a/pos_keep_draft_orders/__openerp__.py b/pos_keep_draft_orders/__openerp__.py new file mode 100644 index 00000000..f840178c --- /dev/null +++ b/pos_keep_draft_orders/__openerp__.py @@ -0,0 +1,75 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Point Of Sale - Keep Draft Orders 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 . +# +############################################################################## + +{ + 'name': 'Point Of Sale - Keep Draft Orders ', + 'version': '2.1', + 'category': 'Point of Sale', + 'description': """ +Allow to close a Session even if there are some PoS Orders in draft state +========================================================================= + +By default, in Odoo, All PoS Orders must be in 'paid' or 'invoiced' state to +allow user to close the session; + +This module can be usefull to manage Orders in slate for some customers; + +Features: +--------- +With this Module: + * if a PoS order is in a 'draft' mode (without any payment), the PoS order + will be unassociated to the current session, when closing the session; + * When opening a new session, the PoS Orders in 'draft' state will be + associated to the new session, based on the user_id; + * Add a new computed field 'is_partial_paid' on PoS Order: + * This field is True, if the PoS order is in a draft mode with + some payments; + * In the tree view, the partial_paid orders are displayed in red + colors; + * Forbid to close a session if there is a partial paid Order, to avoid + to have Account Move Lines that can not be reconciled; + + * A new field 'allow_slate' is available in PoS Config Model, to allow + or block the user to let Orders in slate; + +Copyright, Authors and Licence: +------------------------------- + * Copyright: + * 2013-Today, GRAP: Groupement Régional Alimentaire de Proximité; + * Author: + * Julien WESTE; + * Sylvain LE GAL (https://twitter.com/legalsylvain); + * Licence: AGPL-3 (http://www.gnu.org/licenses/);""", + 'author': 'GRAP', + 'website': 'http://www.grap.coop', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'view/view.xml', + ], + 'demo': [ + 'demo/pos_config.yml', + ], +} diff --git a/pos_keep_draft_orders/demo/pos_config.yml b/pos_keep_draft_orders/demo/pos_config.yml new file mode 100644 index 00000000..13c4c095 --- /dev/null +++ b/pos_keep_draft_orders/demo/pos_config.yml @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# POS Keep Draft Orders 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 . +# +############################################################################## + +- !record {model: pos.config, id: point_of_sale.pos_config_main}: + allow_slate: True diff --git a/pos_keep_draft_orders/i18n/fr.po b/pos_keep_draft_orders/i18n/fr.po new file mode 100644 index 00000000..f5f9b1de --- /dev/null +++ b/pos_keep_draft_orders/i18n/fr.po @@ -0,0 +1,55 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * pos_keep_draft_orders +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-03-10 14:52+0000\n" +"PO-Revision-Date: 2015-03-10 14:52+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_keep_draft_orders +#: field:pos.config,allow_slate:0 +msgid "Allow Slate" +msgstr "Autoriser les ardoises" + +#. module: pos_keep_draft_orders +#: code:addons/pos_keep_draft_orders/model/pos_session.py:43 +#, python-format +msgid "Error!" +msgstr "Erreur !" + +#. module: pos_keep_draft_orders +#: help:pos.config,allow_slate:0 +msgid "If you check this field, users will have the possibility to let some PoS orders in the slate, and allow the customer to paid later.\n" +"Order in the slate will not generate entries during the close of the session." +msgstr "Si vous cochez cette case, les utilisateurs auront la possibilité de laisser certaines vente en ardoise, et autorisera le client à payer plus tard.\n les ventes en ardoise ne génère pas d'écriture lors de la fermeture de la session." + +#. module: pos_keep_draft_orders +#: field:pos.order,is_partial_paid:0 +msgid "Is Partially Paid" +msgstr "Est partiellement payé" + +#. module: pos_keep_draft_orders +#: code:_description:0 +#: model:ir.model,name:pos_keep_draft_orders.model_pos_order +#, python-format +msgid "Point of Sale" +msgstr "Point de Vente" + +#. module: pos_keep_draft_orders +#: code:addons/pos_keep_draft_orders/model/pos_session.py:46 +#, python-format +msgid "You cannot confirm this session, because '%s' is in a 'draft' state with payments.\n" +"\n" +"Please finish to pay this Order." +msgstr "Vous ne pouvez pas fermer cette session car '%s' est en brouillon avec des paiments.\n" +"\n" +"Merci de compléter les paiments." diff --git a/pos_keep_draft_orders/model/__init__.py b/pos_keep_draft_orders/model/__init__.py new file mode 100644 index 00000000..2701b308 --- /dev/null +++ b/pos_keep_draft_orders/model/__init__.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Point Of Sale - Keep Draft Orders 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 . +# +############################################################################## + +from . import pos_order +from . import pos_session +from . import pos_config diff --git a/pos_keep_draft_orders/model/pos_config.py b/pos_keep_draft_orders/model/pos_config.py new file mode 100644 index 00000000..2131cc01 --- /dev/null +++ b/pos_keep_draft_orders/model/pos_config.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# POS Keep Draft Orders module for Odoo +# Copyright (C) 2013-2014 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 . +# +############################################################################## + +from openerp.osv import fields +from openerp.osv.orm import Model + + +class pos_config(Model): + _inherit = 'pos.config' + + # Column Section + _columns = { + 'allow_slate': fields.boolean( + 'Allow Slate', help="If you check this field, users will have" + " the possibility to let some PoS orders in the slate, and allow" + " the customer to paid later.\n" + "Order in the slate will not generate entries during the close" + " of the session."), + } diff --git a/pos_keep_draft_orders/model/pos_order.py b/pos_keep_draft_orders/model/pos_order.py new file mode 100644 index 00000000..6c2f862b --- /dev/null +++ b/pos_keep_draft_orders/model/pos_order.py @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Point Of Sale - Keep Draft Orders 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 . +# +############################################################################## + +from openerp.osv import fields +from openerp.osv.orm import Model + + +class pos_order(Model): + _inherit = 'pos.order' + + # Functional Field Section + def _get_is_partial_paid( + self, cr, uid, ids, name, arg, context=None): + res = {} + for po in self.browse(cr, uid, ids, context=context): + res[po.id] = (po.state == 'draft') and len(po.statement_ids) != 0 + return res + + # Column Section + _columns = { + 'is_partial_paid': fields.function( + _get_is_partial_paid, string='Is Partially Paid'), + } diff --git a/pos_keep_draft_orders/model/pos_session.py b/pos_keep_draft_orders/model/pos_session.py new file mode 100644 index 00000000..36b8dcda --- /dev/null +++ b/pos_keep_draft_orders/model/pos_session.py @@ -0,0 +1,65 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# POS Keep Draft Orders module for Odoo +# Copyright (C) 2013-2014 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 . +# +############################################################################## + +from osv.osv import except_osv +from openerp.osv.orm import Model +from openerp.tools.translate import _ + + +class pos_session(Model): + _inherit = 'pos.session' + + # Overload Section + def wkf_action_closing_control(self, cr, uid, ids, context=None): + """Remove all PoS Orders in 'draft' to the sessions we want + to close. + Check if there is Partial Paid Orders""" + po_obj = self.pool['pos.order'] + for ps in self.browse(cr, uid, ids, context=context): + for po in ps.order_ids: + # Check if there is a partial payment + if po.is_partial_paid: + raise except_osv( + _('Error!'), + _("You cannot confirm this session, because '%s'" + " is in a 'draft' state with payments.\n\n" + "Please finish to pay this Order." % ( + po.name))) + # remove session id on the current PoS if it is in draft mode + if po.state == 'draft' and ps.config_id.allow_slate: + po_obj.write(cr, uid, po.id, { + 'session_id': None}, context=context) + return super(pos_session, self).wkf_action_closing_control( + cr, uid, ids, context=context) + + def create(self, cr, uid, values, context=None): + """Recover all PoS Order in 'draft' mode and associate them to the new + Pos Session""" + po_obj = self.pool['pos.order'] + ps_id = super(pos_session, self).create(cr, uid, values, context) + po_ids = po_obj.search(cr, uid, [ + ('state', '=', 'draft'), ('user_id', '=', uid)], + context=context) + po_obj.write( + cr, uid, po_ids, {'session_id': ps_id}, context=context) + return ps_id diff --git a/pos_keep_draft_orders/static/src/img/icon.png b/pos_keep_draft_orders/static/src/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..97ba7908f87c2e792f6a76fc95c4bf78ab2bf711 GIT binary patch literal 4639 zcmZ`-byO2j7awyXB@IrI?(S~M(KQ4m28`{zj@Qd#6-mUo!xU{>PdtJv=ByGv|=9nqD{?&BfHm1F3viS z%KwPlSX#q`UR~eg7!e>TE8B-U*%Qk#I4a>IcvWObO6~mPp zRV!S-IJrYbO$PBr8;)u^03i@vGyeQii-kTTZ>*TQGs7b&4L#93Lle;N5p{tf?2 zT&NqhXz zcAtiIko;v=u~cKeHoz9tB}Pp{Pahe(?zm{BMAYo?_K5;xe6*WTqN>;{j5`?BVIwzu zkh8qu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hX;(bww@Ca2afZ=6$Y zlDgfT32WZ8>3jBHo^V7WEs^{4+>aZ*(7gG95B}vi&b0t-C3Gq~J?GSy2q7o{IQ+Bs z!9K0I6|T!gJ25xMXZPXZ=H{lRW=UC@js+C`mteGan_KJo_xSJvQ0wXZ6JWpc**8ws z?&fEEpyai_q#^sg6}!+AD8GO}Dh9)Y|9+?aoE=y_<@>3j0pjdj3OM{8FRDk#Ta ze+PTe_V-F+OzY{_F*M2^kPHGv;8Hi8Kc-kVq7YHd-=2e;lfH{YwACJSkL$pi)` z!zHj|2_ZH7_;!V_Lv=D<-*nB*(||Ruqb#`ga8<>CpP-eT<%>;68*3X-$o>=iVhjcq zuoUzPhqDHtUcCxBTMWRS%sj^KU~(80YN?PuXf*mu!Q<~UGnTM6@?(4m>#kh*QO@$O z&j+F2t2p~X1)mkb-?M|V($eT#tRcxSZ&8W#qI;bD{LEN_e~4oV*l^zZnl~{v#@2$| zPsL)f?eiT(KNeda*45W. +# +############################################################################## + + +from . import test_pos_keep_draft_orders + +fast_suite = [ + test_pos_keep_draft_orders, +] diff --git a/pos_keep_draft_orders/tests/test_pos_keep_draft_orders.py b/pos_keep_draft_orders/tests/test_pos_keep_draft_orders.py new file mode 100644 index 00000000..27c0a1af --- /dev/null +++ b/pos_keep_draft_orders/tests/test_pos_keep_draft_orders.py @@ -0,0 +1,133 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# POS Keep Draft Orders 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 . +# +############################################################################## + +from openerp import netsvc + +from openerp.tests.common import TransactionCase + + +class TestPosKeepDraftOrders(TransactionCase): + """Tests for 'Point Of Sale - Keep Draft Orders' Module""" + + def setUp(self): + super(TestPosKeepDraftOrders, self).setUp() + cr, uid = self.cr, self.uid + + self.imd_obj = self.registry('ir.model.data') + self.ps_obj = self.registry('pos.session') + self.po_obj = self.registry('pos.order') + self.pmp_obj = self.registry('pos.make.payment') + self.wf_service = netsvc.LocalService('workflow') + + self.pos_config_id = self.imd_obj.get_object_reference( + cr, uid, 'point_of_sale', 'pos_config_main')[1] + self.product_1 = self.imd_obj.get_object_reference( + cr, uid, 'product', 'product_product_48')[1] + self.cash_journal_id = self.imd_obj.get_object_reference( + cr, uid, 'account', 'cash_journal')[1] + + # Test Section + def test_01_allow_draft_order_unpaid(self): + """Test the possibility to let a PoS Order in a slate if it is not + paid at all.""" + cr, uid = self.cr, self.uid + + # Open a new session + ps1_id = self.ps_obj.create(cr, uid, { + 'config_id': self.pos_config_id, + }) + + # Create Order + po_id = self.po_obj.create(cr, uid, { + 'session_id': ps1_id, + 'lines': [ + [0, False, { + 'discount': 0, + 'price_unit': 10, + 'product_id': self.product_1, + 'qty': 1}]] + }) + + # Close Session + self.wf_service.trg_validate( + uid, 'pos.session', ps1_id, 'close', cr) + + ps1 = self.ps_obj.browse(cr, uid, ps1_id) + + self.assertEquals( + ps1.state, 'closed', + """Draft Orders without Payment must not block the closing + process of the associated session.""") + + # Open a second session + ps2_id = self.ps_obj.create(cr, uid, { + 'config_id': self.pos_config_id, + }) + + po = self.po_obj.browse(cr, uid, po_id) + + self.assertEquals( + po.session_id.id, ps2_id, + """Draft Orders of a previous session must be associated to the + new opened session to allow payment.""") + + # Test Section + def test_01_block_draft_order_partial_paid(self): + """Test the unpossibility to let a PoS Order in a slate if it is + in a partial paid state.""" + cr, uid = self.cr, self.uid + + # Open a new session + ps_id = self.ps_obj.create(cr, uid, { + 'config_id': self.pos_config_id, + }) + + # Create Order + po_id = self.po_obj.create(cr, uid, { + 'session_id': ps_id, + 'lines': [ + [0, False, { + 'discount': 0, + 'price_unit': 10, + 'product_id': self.product_1, + 'qty': 3}]] + }) + + # Make partial payment + pmp_id = self.pmp_obj.create(cr, uid, { + 'journal_id': self.cash_journal_id, + 'amount': 1, + }) + self.pmp_obj.check(cr, uid, [pmp_id], {'active_id': po_id}) + + # Try Close Session + try: + self.wf_service.trg_validate( + uid, 'pos.session', ps_id, 'close', cr) + raise_exception = False + except: + raise_exception = True + + self.assertEquals( + raise_exception, True, + """Draft Orders with partial Payment must block the closing + process of the associated session.""") diff --git a/pos_keep_draft_orders/view/view.xml b/pos_keep_draft_orders/view/view.xml new file mode 100644 index 00000000..238e13de --- /dev/null +++ b/pos_keep_draft_orders/view/view.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + pos.order + + + + + + + red: is_partial_paid==True; blue: state=='draft'; gray: state in ('done','cancel'); black: state not in ('done','cancel') + + + + + + pos.config + + + + + + + + + + +