From ba967516aa5f3a471e3fabe6173033da432ae554 Mon Sep 17 00:00:00 2001 From: Ludovic CHEVALIER Date: Fri, 29 May 2020 09:14:23 +0200 Subject: [PATCH] [PYTHON][TRANS][VIEW] ~pos order is_cpv status based on cpv payment method --- __init__.py | 1 + __openerp__.py | 2 +- account.py | 18 ++++++++++++++++ i18n/coup_de_pouce_velo.pot | 27 +++++++++++++++++------ i18n/fr.po | 43 ++++++++++++++++++++++++++----------- point_of_sale.py | 33 +++++++++++----------------- view/account_statement.xml | 16 ++++++++++++++ view/point_of_sale.xml | 16 -------------- wizard/__init__.py | 1 + wizard/pos_payment.py | 24 +++++++++++++++++++++ wizard/pos_receipt.py | 13 +++++++---- 11 files changed, 134 insertions(+), 60 deletions(-) create mode 100644 account.py create mode 100644 view/account_statement.xml delete mode 100644 view/point_of_sale.xml create mode 100644 wizard/pos_payment.py diff --git a/__init__.py b/__init__.py index 5b2378b..9a731c5 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,7 @@ # Copyright 2020 L'Heureux Cyclage # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import account import point_of_sale import report import wizard diff --git a/__openerp__.py b/__openerp__.py index 0c05283..892295a 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -23,7 +23,7 @@ This module adds features to OpenERP POS module for french bikecoops for "Coup d 'init_xml': [ ], 'update_xml': [ - 'view/point_of_sale.xml', + 'view/account_statement.xml', ], 'installable': True, 'auto_install': False, diff --git a/account.py b/account.py new file mode 100644 index 0000000..40d8581 --- /dev/null +++ b/account.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 L'Heureux Cyclage +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.osv import osv +from openerp.osv import orm +from openerp.osv import fields + + +class account_journal(orm.Model): + _inherit = 'account.journal' + + _columns = { + 'is_cpv': fields.boolean( + '«Coup de Pouce Vélo» payment method', + help='Check this box if this is a «Coup de Pouce Vélo» payment method' + ), + } diff --git a/i18n/coup_de_pouce_velo.pot b/i18n/coup_de_pouce_velo.pot index a57cbdd..327b714 100644 --- a/i18n/coup_de_pouce_velo.pot +++ b/i18n/coup_de_pouce_velo.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-05-27 11:00+0000\n" -"PO-Revision-Date: 2020-05-27 11:00+0000\n" +"POT-Creation-Date: 2020-05-28 19:52+0000\n" +"PO-Revision-Date: 2020-05-28 19:52+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -16,13 +16,23 @@ msgstr "" "Plural-Forms: \n" #. module: coup_de_pouce_velo -#: field:pos.order,is_cpv:0 -msgid "\"Coup de Pouce Velo\"?" +#: field:account.journal,is_cpv:0 +msgid "«Coup de Pouce Vélo» payment method" msgstr "" #. module: coup_de_pouce_velo -#: model:ir.model,name:coup_de_pouce_velo.model_pos_order -msgid "Point of Sale" +#: model:ir.model,name:coup_de_pouce_velo.model_pos_make_payment +msgid "Point of Sale Payment" +msgstr "" + +#. module: coup_de_pouce_velo +#: model:ir.model,name:coup_de_pouce_velo.model_account_journal +msgid "Journal" +msgstr "" + +#. module: coup_de_pouce_velo +#: help:account.journal,is_cpv:0 +msgid "Check this box if this is a «Coup de Pouce Vélo» payment method" msgstr "" #. module: coup_de_pouce_velo @@ -31,6 +41,11 @@ msgstr "" msgid "Warning!" msgstr "" +#. module: coup_de_pouce_velo +#: model:ir.model,name:coup_de_pouce_velo.model_pos_order +msgid "Point of Sale" +msgstr "" + #. module: coup_de_pouce_velo #: code:addons/coup_de_pouce_velo/point_of_sale.py:21 #, python-format diff --git a/i18n/fr.po b/i18n/fr.po index fc9cb04..905c38b 100644 --- a/i18n/fr.po +++ b/i18n/fr.po @@ -6,10 +6,9 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-05-27 11:00+0000\n" -"PO-Revision-Date: 2020-05-27 13:07+0200\n" -"Last-Translator: Ludovic CHEVALIER \n" +"POT-Creation-Date: 2020-05-28 19:52+0000\n" +"PO-Revision-Date: 2020-05-28 21:54+0200\n" +"Last-Translator: Ludovic CHEVALIER \n" "Language-Team: \n" "Language: fr\n" "MIME-Version: 1.0\n" @@ -19,14 +18,26 @@ msgstr "" "X-Generator: Poedit 2.3.1\n" #. module: coup_de_pouce_velo -#: field:pos.order,is_cpv:0 -msgid "\"Coup de Pouce Velo\"?" -msgstr "\"Coup de Pouce Vélo\"?" +#: field:account.journal,is_cpv:0 +msgid "«Coup de Pouce Vélo» payment method" +msgstr "Moyen de paiement type «Coup de Pouce Vélo»" #. module: coup_de_pouce_velo -#: model:ir.model,name:coup_de_pouce_velo.model_pos_order -msgid "Point of Sale" -msgstr "Atelier" +#: model:ir.model,name:coup_de_pouce_velo.model_pos_make_payment +msgid "Point of Sale Payment" +msgstr "Paiement en point de vente" + +#. module: coup_de_pouce_velo +#: model:ir.model,name:coup_de_pouce_velo.model_account_journal +msgid "Journal" +msgstr "Journal" + +#. module: coup_de_pouce_velo +#: help:account.journal,is_cpv:0 +msgid "Check this box if this is a «Coup de Pouce Vélo» payment method" +msgstr "" +"Cocher cette case s'il s'agit d'un moyen de paiement de type «Coup de Pouce " +"Vélo»" #. module: coup_de_pouce_velo #: code:addons/coup_de_pouce_velo/point_of_sale.py:26 @@ -34,6 +45,11 @@ msgstr "Atelier" msgid "Warning!" msgstr "Avertissement!" +#. module: coup_de_pouce_velo +#: model:ir.model,name:coup_de_pouce_velo.model_pos_order +msgid "Point of Sale" +msgstr "Atelier" + #. module: coup_de_pouce_velo #: code:addons/coup_de_pouce_velo/point_of_sale.py:21 #, python-format @@ -41,10 +57,13 @@ msgid "" "Mobile is required to print a «Coup de Pouce» receipt. Add " "mobile number to this partner: %s." msgstr "" -"Le portable est nécessaire pour imprimer un reçu «Coup de Pouce». Ajouter " -"un numéro de portable à ce contact: %s." +"Le portable est nécessaire pour imprimer un reçu «Coup de Pouce». Ajouter un " +"numéro de portable à ce contact: %s." #. module: coup_de_pouce_velo #: model:ir.model,name:coup_de_pouce_velo.model_pos_receipt msgid "Point of sale receipt" msgstr "Reçu de l'atelier" + +#~ msgid "\"Coup de Pouce Velo\"?" +#~ msgstr "\"Coup de Pouce Vélo\"?" diff --git a/point_of_sale.py b/point_of_sale.py index 30a1b2c..9c9a016 100644 --- a/point_of_sale.py +++ b/point_of_sale.py @@ -11,12 +11,12 @@ from openerp.tools.translate import _ class pos_order(orm.Model): _inherit = 'pos.order' - def check_partner_mobile(self, cr, uid, partner_id, context=None): + def check_partner_mobile(self, cr, uid, order_id, context=None): """Check if a partner mobile number is defined and display warning message if not.""" - partner_obj = self.pool.get('res.partner') - partner = partner_obj.browse(cr, uid, partner_id, context=context) - is_mobile = partner.mobile + order = self.browse(cr, uid, order_id, context=context) + is_mobile = order.partner_id.mobile + partner = order.partner_id if not is_mobile: warn_message = _( """Mobile is required to print a «Coup de Pouce» receipt.\ @@ -27,26 +27,17 @@ class pos_order(orm.Model): warn_message) return True - _columns = { - 'is_cpv': fields.boolean('"Coup de Pouce Velo"?', change_default=True), - } - - def create(self, cr, uid, vals, context=None): - if 'partner_id' in vals: - partner_id = vals['partner_id'] - if 'is_cpv' in vals: - if vals['is_cpv']: - self.check_partner_mobile(cr, uid, partner_id, context) - return super(pos_order, self).create( - cr, uid, vals, context=context - ) - def write(self, cr, uid, ids, vals, context=None): order = self.browse(cr, uid, ids[0], context=context) + order_id = order.id partner_id = order.partner_id.id - if 'is_cpv' in vals: - if vals['is_cpv']: - self.check_partner_mobile(cr, uid, partner_id, context) + statements = order.statement_ids + is_cpv = 0 + for statement in statements: + if statement.journal_id.is_cpv: + is_cpv +=1 + if is_cpv: + self.check_partner_mobile(cr, uid, order_id, context) return super(pos_order, self).write( cr, uid, ids, vals, context=context ) diff --git a/view/account_statement.xml b/view/account_statement.xml new file mode 100644 index 0000000..7b062cf --- /dev/null +++ b/view/account_statement.xml @@ -0,0 +1,16 @@ + + + + + account.journal.form + account.journal + + + + + + + + + + diff --git a/view/point_of_sale.xml b/view/point_of_sale.xml deleted file mode 100644 index 267b332..0000000 --- a/view/point_of_sale.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - pos.order.form - pos.order - - - - - - - - - - diff --git a/wizard/__init__.py b/wizard/__init__.py index 630cf01..97759c6 100644 --- a/wizard/__init__.py +++ b/wizard/__init__.py @@ -1,4 +1,5 @@ # Copyright 2020 L'Heureux Cyclage # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import pos_payment import pos_receipt diff --git a/wizard/pos_payment.py b/wizard/pos_payment.py new file mode 100644 index 0000000..a3efb0e --- /dev/null +++ b/wizard/pos_payment.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 L'Heureux Cyclage +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.osv import osv +from openerp.osv import orm +from openerp.osv import fields + + +class pos_make_payment(orm.Model): + _inherit = 'pos.make.payment' + + def check(self, cr, uid, ids, context=None): + """Add a check of partner mobile number to the check method.""" + pmps = self.browse(cr, uid, ids, context=context) + for pmp in pmps: + journal = pmp.journal_id + if journal.is_cpv: + order_obj = self.pool.get('pos.order') + order_id = context['active_id'] + order_obj.check_partner_mobile(cr, uid, order_id, context=None) + return super(pos_make_payment, self).check( + cr, uid, ids, context=context + ) diff --git a/wizard/pos_receipt.py b/wizard/pos_receipt.py index 71e715a..e327e5d 100644 --- a/wizard/pos_receipt.py +++ b/wizard/pos_receipt.py @@ -10,17 +10,22 @@ class pos_receipt(orm.Model): _inherit = 'pos.receipt' def print_report(self, cr, uid, ids, context=None): - """Check if partner mobile number is defined before printing receipt.""" + """Check if partner mobile number is defined before printing + receipt.""" order_id = context['active_id'] order_obj = self.pool.get('pos.order') order = order_obj.browse(cr, uid, order_id, context=context) - partner_id = order.partner_id.id + statements = order.statement_ids if context is None: context = {} datas = {'ids': context.get('active_ids', [])} report_name = 'bikecoop_l10n_fr.receipt' - if order.is_cpv: - order_obj.check_partner_mobile(cr, uid, partner_id, context=None) + is_cpv = 0 + for statement in statements: + if statement.journal_id.is_cpv: + is_cpv += 1 + if is_cpv: + order_obj.check_partner_mobile(cr, uid, order_id, context=None) report_name = 'coup_de_pouce_velo.receipt' return { 'type': 'ir.actions.report.xml', -- 2.20.1