From 72fe25042c12a865510836739a83b7ab68c336c9 Mon Sep 17 00:00:00 2001 From: Ludovic CHEVALIER Date: Mon, 27 Jun 2016 12:20:41 +0200 Subject: [PATCH] [MODULE] +init --- __init__.py | 27 +++++++ __openerp__.py | 50 +++++++++++++ i18n/fr.po | 38 ++++++++++ i18n/nrt_point_of_sale.pot | 37 ++++++++++ point_of_sale.py | 140 +++++++++++++++++++++++++++++++++++++ view/point_of_sale.xml | 41 +++++++++++ 6 files changed, 333 insertions(+) create mode 100644 __init__.py create mode 100644 __openerp__.py create mode 100644 i18n/fr.po create mode 100644 i18n/nrt_point_of_sale.pot create mode 100644 point_of_sale.py create mode 100644 view/point_of_sale.xml diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d44fe1d --- /dev/null +++ b/__init__.py @@ -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 () +# 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 . +# +############################################################################## +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 index 0000000..c7bb6d1 --- /dev/null +++ b/__openerp__.py @@ -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 () 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 . +# +############################################################################## + +{ + '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 index 0000000..2f447bf --- /dev/null +++ b/i18n/fr.po @@ -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 \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 index 0000000..40a437e --- /dev/null +++ b/i18n/nrt_point_of_sale.pot @@ -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 index 0000000..70f7c3f --- /dev/null +++ b/point_of_sale.py @@ -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 () +# 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 . +# +############################################################################## + +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 index 0000000..9dd2fdd --- /dev/null +++ b/view/point_of_sale.xml @@ -0,0 +1,41 @@ + + + + + pos.session.form + pos.session + + + + + + + + + + + + pos.session.tree + pos.session + + + + + + + + + + + pos.order.form + pos.order + + + + + onchange_session_id(session_id, context) + + + + + -- 2.20.1