Browse Source

[ADD] new module pos_keep_draft_orders to manage Slate

pull/17/head
Sylvain LE GAL 10 years ago
parent
commit
05573d753a
  1. 24
      pos_keep_draft_orders/__init__.py
  2. 75
      pos_keep_draft_orders/__openerp__.py
  3. 24
      pos_keep_draft_orders/demo/pos_config.yml
  4. 55
      pos_keep_draft_orders/i18n/fr.po
  5. 26
      pos_keep_draft_orders/model/__init__.py
  6. 39
      pos_keep_draft_orders/model/pos_config.py
  7. 43
      pos_keep_draft_orders/model/pos_order.py
  8. 65
      pos_keep_draft_orders/model/pos_session.py
  9. BIN
      pos_keep_draft_orders/static/src/img/icon.png
  10. 28
      pos_keep_draft_orders/tests/__init__.py
  11. 133
      pos_keep_draft_orders/tests/test_pos_keep_draft_orders.py
  12. 49
      pos_keep_draft_orders/view/view.xml

24
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model

75
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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',
],
}

24
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
- !record {model: pos.config, id: point_of_sale.pos_config_main}:
allow_slate: True

55
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."

26
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import pos_order
from . import pos_session
from . import pos_config

39
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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."),
}

43
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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'),
}

65
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

BIN
pos_keep_draft_orders/static/src/img/icon.png

After

Width: 64  |  Height: 64  |  Size: 4.5 KiB

28
pos_keep_draft_orders/tests/__init__.py

@ -0,0 +1,28 @@
# -*- 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_pos_keep_draft_orders
fast_suite = [
test_pos_keep_draft_orders,
]

133
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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.""")

49
pos_keep_draft_orders/view/view.xml

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ********************************************************************** -->
<!--Point Of Sale - 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 <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_order_tree"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="is_partial_paid" invisible="1" />
</field>
<xpath expr="//tree[@string='POS Orders']" position="attributes">
<attribute name="colors">red: is_partial_paid==True; blue: state=='draft'; gray: state in ('done','cancel'); black: state not in ('done','cancel')</attribute>
</xpath>
</field>
</record>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form"/>
<field name="arch" type="xml">
<field name="group_by" position="after">
<field name="allow_slate"/>
</field>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save