[MODULE] +init
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Mon, 27 Jun 2016 10:20:41 +0000 (12:20 +0200)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Mon, 27 Jun 2016 10:20:41 +0000 (12:20 +0200)
__init__.py [new file with mode: 0644]
__openerp__.py [new file with mode: 0644]
i18n/fr.po [new file with mode: 0644]
i18n/nrt_point_of_sale.pot [new file with mode: 0644]
point_of_sale.py [new file with mode: 0644]
view/point_of_sale.xml [new file with mode: 0644]

diff --git a/__init__.py b/__init__.py
new file mode 100644 (file)
index 0000000..d44fe1d
--- /dev/null
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Non-real time point of sale module for OpenERP, Permit user to record his
+#    sales in point of sale interface in non-real time.
+#    Copyright (C) 2016 L'Heureux Cyclage (<http://www.heureux-cyclage>)
+#    Ludovic CHEVALIER
+#
+#    This file is a part of Non-real time point of sale
+#
+#    Non-real time point of sale is free software: you can redistribute it
+#    and/or modify it under the terms of the GNU General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    Non-real time point of sale 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 General
+#    Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+import point_of_sale
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/__openerp__.py b/__openerp__.py
new file mode 100644 (file)
index 0000000..c7bb6d1
--- /dev/null
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Non-real time point of sale module for OpenERP, Allow user to record his
+#    sales in point of sale interface in non-real time.  Copyright (C) 2016
+#    L'Heureux Cyclage (<http://www.heureux-cyclage>) Ludovic CHEVALIER
+#
+#    This file is a part of Non-real time point of sale
+#
+#    Non-real time point of sale is free software: you can redistribute it
+#    and/or modify it under the terms of the GNU General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    Non-real time point of sale 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 General
+#    Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+    'name': 'Non-real time point of sale',
+    'version': '0.1',
+    'category': 'Point Of Sale',
+    'description': """
+    This module allow user to record his sales in point of sale interface in
+    non-real time.
+    """,
+    'author': 'L\'Heureux Cyclage',
+    'website': 'http://www.heureux-cyclage.org',
+    'depends': [
+        'point_of_sale'
+    ],
+    'init_xml': [],
+    'data': [],
+    'update_xml': [
+        'view/point_of_sale.xml',
+    ],
+    'demo_xml': [],
+    'test': [],
+    'installable': True,
+    'active': False,
+
+}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/i18n/fr.po b/i18n/fr.po
new file mode 100644 (file)
index 0000000..2f447bf
--- /dev/null
@@ -0,0 +1,38 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#      * nrt_point_of_sale
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2016-06-27 12:07+0200\n"
+"PO-Revision-Date: 2016-06-27 12:07+0200\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+"X-Generator: Poedit 1.8.8\n"
+"Last-Translator: Ludovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>\n"
+"Language: fr\n"
+
+#. module: nrt_point_of_sale
+#: view:pos.session:0
+msgid "Date"
+msgstr "Date"
+
+#. module: nrt_point_of_sale
+#: model:ir.model,name:nrt_point_of_sale.model_pos_session
+msgid "pos.session"
+msgstr "pos.session"
+
+#. module: nrt_point_of_sale
+#: model:ir.model,name:nrt_point_of_sale.model_pos_order
+msgid "Point of Sale"
+msgstr "Point de vente"
+
+#. module: nrt_point_of_sale
+#: view:pos.order:0
+msgid "onchange_session_id(session_id, context)"
+msgstr "onchange_session_id(session_id, context)"
diff --git a/i18n/nrt_point_of_sale.pot b/i18n/nrt_point_of_sale.pot
new file mode 100644 (file)
index 0000000..40a437e
--- /dev/null
@@ -0,0 +1,37 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#      * nrt_point_of_sale
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2016-06-27 10:05+0000\n"
+"PO-Revision-Date: 2016-06-27 10:05+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: nrt_point_of_sale
+#: view:pos.session:0
+msgid "Date"
+msgstr ""
+
+#. module: nrt_point_of_sale
+#: model:ir.model,name:nrt_point_of_sale.model_pos_session
+msgid "pos.session"
+msgstr ""
+
+#. module: nrt_point_of_sale
+#: model:ir.model,name:nrt_point_of_sale.model_pos_order
+msgid "Point of Sale"
+msgstr ""
+
+#. module: nrt_point_of_sale
+#: view:pos.order:0
+msgid "onchange_session_id(session_id, context)"
+msgstr ""
+
diff --git a/point_of_sale.py b/point_of_sale.py
new file mode 100644 (file)
index 0000000..70f7c3f
--- /dev/null
@@ -0,0 +1,140 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Non-real time point of sale module for OpenERP, Permit user to record his
+#    sales in point of sale interface in non-real time.
+#    Copyright (C) 2016 L'Heureux Cyclage (<http://www.heureux-cyclage>)
+#    Ludovic CHEVALIER
+#
+#    This file is a part of Non-real time point of sale
+#
+#    Non-real time point of sale is free software: you can redistribute it
+#    and/or modify it under the terms of the GNU General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    Non-real time point of sale 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 General
+#    Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv import osv
+from openerp.osv import orm
+from openerp.osv import fields
+
+
+class pos_session(orm.Model):
+    _inherit = 'pos.session'
+
+    _columns = {
+        'start_at': fields.datetime('Opening date'),
+        'stop_at': fields.datetime('Closing date'),
+    }
+
+    def create(self, cr, uid, values, context=None):
+        """
+        Put the same date in bank statements as pos session and define the
+        appropriate period
+        """
+        context = context or {}
+        bank_st_obj = self.pool.get('account.bank.statement')
+        period_obj = self.pool.get('account.period')
+        context = dict(context, account_period_prefer_normal=True)
+
+        id = super(pos_session, self).create(cr, uid, values, context=context)
+        for session in self.browse(cr, uid, [id], context=context):
+            default_date = session.start_at
+        bank_st_ids = bank_st_obj.search(cr, uid, [('pos_session_id', '=', id)], context=context)
+        period = period_obj.find(cr, uid, dt=default_date, context=dict(context or {}, account_period_prefer_normal=True))[0]
+        bank_st_obj.write(cr, uid, bank_st_ids, {'date': default_date, 'period_id': period}, context=context)
+        return id
+
+    def _confirm_orders(self, cr, uid, ids, context=None):
+        """Put the same date in sale account move as pos session"""
+        account_move_obj = self.pool.get('account.move')
+        order_obj = self.pool.get('pos.order')
+        period_obj = self.pool.get('account.period')
+        super(pos_session, self)._confirm_orders(cr, uid, ids, context=context)
+
+        for session in self.browse(cr, uid, ids, context=context):
+            account_move_ids = []
+            order_ids = [order.id for order in session.order_ids if order.state == 'done']
+            company_id = order_obj.browse(cr, uid, order_ids, context=context)[0].company_id.id
+            for order in order_obj.browse(cr, uid, order_ids, context=context):
+                if order.account_move.id not in account_move_ids:
+                    account_move_ids.append(order.account_move.id)
+            period = period_obj.find(cr, uid, dt=session.start_at, context=dict(context or {}, company_id=company_id, account_period_prefer_normal=True))[0]
+            account_move_obj.write(cr, uid, account_move_ids, {'date': session.start_at, 'period_id': period}, context=context)
+
+        return True
+
+    def wkf_action_closing_control(self, cr, uid, ids, context=None):
+        """
+        Disable default start_at date
+        Piece of this code was copied from
+        addons/point_of_sale/point_of_sale.py:397
+        """
+        for session in self.browse(cr, uid, ids, context=context):
+            for statement in session.statement_ids:
+                if (statement != session.cash_register_id) and (statement.balance_end != statement.balance_end_real):
+                    self.pool.get('account.bank.statement').write(cr, uid, [statement.id], {'balance_end_real': statement.balance_end})
+        return True
+
+    def onchange_start_at(self, cr, uid, ids, start_at, context=None):
+        """Define same stop_at as start_at"""
+        if not ids:
+            return {'value': {'stop_at': start_at}}
+        else:
+            for session in self.browse(cr, uid, ids, context=context):
+                return {'value': {'stop_at': start_at}}
+
+
+class pos_order(orm.Model):
+    _inherit = 'pos.order'
+
+    def create(self, cr, uid, vals, context=None):
+        session_obj = self.pool.get('pos.session')
+        vals.update({'date_order': session_obj.browse(cr, uid, vals['session_id'], context=context).start_at})
+        res = super(pos_order, self).create(cr, uid, vals, context=context)
+        return res
+
+
+    def write(self, cr, uid, ids, vals, context=None):
+        session_obj = self.pool.get('pos.session')
+        for order in self.browse(cr, uid, ids, context=context):
+            default_date_order = order.session_id.start_at
+        vals.update({'date_order': default_date_order})
+        res = super(pos_order, self).write(cr, uid, ids, vals, context=context)
+        return res
+
+    def onchange_session_id(self, cr, uid, ids, session_id, context=None):
+        """Define date order by start date of current session"""
+        res_obj = self.pool.get('pos.session')
+        data = {}
+        if not session_id:
+            return {'value': data}
+        else:
+            for session in res_obj.browse(cr, uid, [session_id],
+                                          context=context):
+                default_date_order = session.start_at
+            return {'value': {'date_order': default_date_order}}
+
+    def add_payment(self, cr, uid, order_id, data, context=None):
+        """Define payment date by the order date"""
+        statement_obj = self.pool.get('account.bank.statement.line')
+        statement_ids = []
+        order = self.browse(cr, uid, [order_id], context=context)[0]
+        date_order = order.date_order
+        super(pos_order, self).add_payment(cr, uid, order_id, data, context=context)
+
+        for statement in order.statement_ids:
+            statement_ids.append(statement.id)
+        statement_obj.write(cr, uid, statement_ids, {'date': date_order}, context=context)
+        return order_id
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/view/point_of_sale.xml b/view/point_of_sale.xml
new file mode 100644 (file)
index 0000000..9dd2fdd
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <record id="view_pos_session_form" model="ir.ui.view">
+            <field name="name">pos.session.form</field>
+            <field name="model">pos.session</field>
+            <field name="inherit_id" ref="point_of_sale.view_pos_session_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='start_at']" position="replace">
+                    <field name="start_at" required="1" string="Date" on_change="onchange_start_at(start_at, context)" attrs="{'readonly': [('state','!=', 'opening_control')]}"/>
+                </xpath>
+                <xpath expr="//field[@name='stop_at']" position="replace">
+                    <field name="stop_at" required="1" invisible="1"/>
+                </xpath>
+            </field>
+        </record>
+        <record id="view_pos_session_tree" model="ir.ui.view">
+            <field name="name">pos.session.tree</field>
+            <field name="model">pos.session</field>
+            <field name="inherit_id" ref="point_of_sale.view_pos_session_tree"/>
+            <field name="priority" eval="8"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='start_at']" position="replace">
+                    <field name="start_at" string="Date"/>
+                </xpath>
+                <field name="stop_at" position="replace"/>
+            </field>
+        </record>
+        <record id="view_pos_pos_form" model="ir.ui.view">
+            <field name="name">pos.order.form</field>
+            <field name="model">pos.order</field>
+            <field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
+            <field name="priority" eval="8"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='session_id']" position="attributes">
+                    <attribute name="on_change">onchange_session_id(session_id, context)</attribute>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>