From 3aac740aa7a876e30c76af5b1408c071f0939961 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 27 Apr 2020 12:50:19 +0200 Subject: [PATCH] [IMP] use refund() to resale order (in 'refund' mode) ; [ADD] a note on PoS Order(s) to know the history of the payments --- pos_payment_change/__manifest__.py | 4 +- pos_payment_change/i18n/fr.po | 18 +- .../i18n/pos_payment_change.pot | 187 ++++++++++++++++++ pos_payment_change/models/pos_order.py | 26 ++- .../wizards/pos_payment_change_wizard.py | 6 +- 5 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 pos_payment_change/i18n/pos_payment_change.pot diff --git a/pos_payment_change/__manifest__.py b/pos_payment_change/__manifest__.py index a3bfd8b1..a905910b 100644 --- a/pos_payment_change/__manifest__.py +++ b/pos_payment_change/__manifest__.py @@ -2,8 +2,10 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - "name": "Point Of Sale - Change Payment", + "name": "Point Of Sale - Change Payments", "version": "12.0.1.0.0", + "summary": "Allow cashier to change order payments, as long as" + " the session is not closed", "category": "Point Of Sale", "author": "GRAP, Odoo Community Association (OCA)", "website": "https://www.github.com/OCA/pos", diff --git a/pos_payment_change/i18n/fr.po b/pos_payment_change/i18n/fr.po index 8dbda29d..9e146502 100644 --- a/pos_payment_change/i18n/fr.po +++ b/pos_payment_change/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-04-21 02:33+0000\n" -"PO-Revision-Date: 2020-04-21 02:33+0000\n" +"POT-Creation-Date: 2020-04-27 10:44+0000\n" +"PO-Revision-Date: 2020-04-27 10:44+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,6 +15,12 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: pos_payment_change +#: code:addons/pos_payment_change/models/pos_order.py:78 +#, python-format +msgid " (Refund Order: %s ; Resale Order: %s)" +msgstr " (Remboursement: %s ; Revente : %s)" + #. module: pos_payment_change #: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_config_form msgid "Payment Change Policy" @@ -154,6 +160,12 @@ msgstr "Commandes du point de vente" msgid "Refund and Resale" msgstr "Retourner et revendre" +#. module: pos_payment_change +#: code:addons/pos_payment_change/models/pos_order.py:43 +#, python-format +msgid "The payments of the Order %s (Ref: %s) has been changed by %s at %s." +msgstr "Les paiements de la commande %s (Réf: %s) ont été changés par %s à %s." + #. module: pos_payment_change #: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__amount_total #: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_payment_change_wizard_form @@ -177,7 +189,7 @@ msgid "Wizard" msgstr "Assistant" #. module: pos_payment_change -#: code:addons/pos_payment_change/models/pos_order.py:80 +#: code:addons/pos_payment_change/models/pos_order.py:96 #, python-format msgid "You can not change payments of the POS '%s' because the associated session '%s' has been closed!" msgstr "Vous ne pouvez pas changer les paiements de la Vente '%s' car la session associée '%s' a été clôturé !" diff --git a/pos_payment_change/i18n/pos_payment_change.pot b/pos_payment_change/i18n/pos_payment_change.pot new file mode 100644 index 00000000..94eb4b4c --- /dev/null +++ b/pos_payment_change/i18n/pos_payment_change.pot @@ -0,0 +1,187 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_change +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-27 10:48+0000\n" +"PO-Revision-Date: 2020-04-27 10:48+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_payment_change +#: code:addons/pos_payment_change/models/pos_order.py:78 +#, python-format +msgid " (Refund Order: %s ; Resale Order: %s)" +msgstr "" + +#. module: pos_payment_change +#: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_config_form +msgid "Payment Change Policy" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__amount +msgid "Amount" +msgstr "" + +#. module: pos_payment_change +#: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_payment_change_wizard_form +msgid "Cancel" +msgstr "" + +#. module: pos_payment_change +#: model:ir.actions.act_window,name:pos_payment_change.action_pos_payment_change_wizard +#: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_order_form +#: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_payment_change_wizard_form +msgid "Change Payments" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__create_uid +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__create_uid +msgid "Created by" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__create_date +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__create_date +msgid "Created on" +msgstr "" + +#. module: pos_payment_change +#: code:addons/pos_payment_change/wizards/pos_payment_change_wizard.py:54 +#, python-format +msgid "Differences between the two values for the POS Order '%s':\n" +"\n" +" * Total of all the new payments %s;\n" +" * Total of the POS Order %s;\n" +"\n" +"Please change the payments." +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__display_name +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__display_name +msgid "Display Name" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__id +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__id +msgid "ID" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__new_journal_id +msgid "Journal" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard____last_update +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__write_uid +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__write_date +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__write_date +msgid "Last Updated on" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__order_id +msgid "Order" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_config__payment_change_policy +msgid "Payment Change Policy" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,help:pos_payment_change.field_pos_config__payment_change_policy +msgid "Payment Change Policy when users want to change the payment lines of a given PoS Order.\n" +"* 'Refund and Resale': Odoo will refund the current Pos Order to cancel it, and create a new PoS Order with the correct payment lines.\n" +"* 'Update Payments': Odoo will change payment lines.\n" +"\n" +"Note : In some countries the 'Update Payments' Option is not allowed by law, because orders history shouldn't not be altered." +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__line_ids +#: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_payment_change_wizard_form +msgid "Payment Lines" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard +msgid "PoS Payment Change Wizard" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_line +msgid "PoS Payment Change Wizard Line" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model,name:pos_payment_change.model_pos_config +msgid "Point of Sale Configuration" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model,name:pos_payment_change.model_pos_order +msgid "Point of Sale Orders" +msgstr "" + +#. module: pos_payment_change +#: selection:pos.config,payment_change_policy:0 +msgid "Refund and Resale" +msgstr "" + +#. module: pos_payment_change +#: code:addons/pos_payment_change/models/pos_order.py:43 +#, python-format +msgid "The payments of the Order %s (Ref: %s) has been changed by %s at %s." +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__amount_total +#: model_terms:ir.ui.view,arch_db:pos_payment_change.view_pos_payment_change_wizard_form +msgid "Total" +msgstr "" + +#. module: pos_payment_change +#: code:addons/pos_payment_change/models/pos_config.py:43 +#, python-format +msgid "Unable to use the 'Update Payments' options for companies that have unalterable accounting." +msgstr "" + +#. module: pos_payment_change +#: selection:pos.config,payment_change_policy:0 +msgid "Update Payments" +msgstr "" + +#. module: pos_payment_change +#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__wizard_id +msgid "Wizard" +msgstr "" + +#. module: pos_payment_change +#: code:addons/pos_payment_change/models/pos_order.py:96 +#, python-format +msgid "You can not change payments of the POS '%s' because the associated session '%s' has been closed!" +msgstr "" + diff --git a/pos_payment_change/models/pos_order.py b/pos_payment_change/models/pos_order.py index 5589d1df..a0796a29 100644 --- a/pos_payment_change/models/pos_order.py +++ b/pos_payment_change/models/pos_order.py @@ -3,6 +3,8 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from datetime import datetime + from odoo import _, api, fields, models from odoo.tools import float_is_zero from odoo.exceptions import Warning as UserError @@ -21,7 +23,7 @@ class PosOrder(models.Model): payment_change_policy of the related pos_config. """ self.ensure_one() - order_ids = [self.id] + orders = self # Removing zero lines precision = self.pricelist_id.currency_id.decimal_places @@ -32,6 +34,16 @@ class PosOrder(models.Model): self._check_payment_change_allowed() + comment = _( + "The payments of the Order %s (Ref: %s) has been changed" + " by %s at %s." % ( + self.name, + self.pos_reference, + self.env.user.name, + datetime.today(), + ) + ) + if self.config_id.payment_change_policy == "update": self.statement_ids.with_context().unlink() @@ -55,14 +67,20 @@ class PosOrder(models.Model): # Resale order and mark it as paid # with the new payment - resale_order = self.copy() + resale_order = self.copy( + default={"pos_reference": self.pos_reference} + ) for line in payment_lines: resale_order.add_payment(line) resale_order.action_pos_order_paid() - order_ids += [refund_order.id, resale_order.id] - return order_ids + orders += refund_order + resale_order + comment += _(" (Refund Order: %s ; Resale Order: %s)" % ( + refund_order.name, resale_order.name)) + for order in orders: + order.note = "%s\n%s" % (order.note or "", comment) + return orders @api.multi def _check_payment_change_allowed(self): diff --git a/pos_payment_change/wizards/pos_payment_change_wizard.py b/pos_payment_change/wizards/pos_payment_change_wizard.py index f0294b9e..54f8e6d3 100644 --- a/pos_payment_change/wizards/pos_payment_change_wizard.py +++ b/pos_payment_change/wizards/pos_payment_change_wizard.py @@ -62,9 +62,9 @@ class PosPaymentChangeWizard(models.TransientModel): "payment_date": fields.Date.context_today(self), } for line in self.line_ids] - order_ids = order.change_payment(new_payments) + orders = order.change_payment(new_payments) - if len(order_ids) == 1: + if len(orders) == 1: # if policy is 'update', only close the pop up action = {'type': 'ir.actions.act_window_close'} else: @@ -72,6 +72,6 @@ class PosPaymentChangeWizard(models.TransientModel): action = self.env.ref( "point_of_sale.action_pos_pos_form" ).read()[0] - action['domain'] = [('id', 'in', order_ids)] + action['domain'] = [('id', 'in', orders.ids)] return action