Browse Source

[FIX] error in balance computation if change is done during closing control ; [ADD] display old payment lines

pull/480/head
Sylvain LE GAL 5 years ago
parent
commit
396b7a9783
  1. 68
      pos_payment_change/i18n/fr.po
  2. 63
      pos_payment_change/i18n/pos_payment_change.pot
  3. BIN
      pos_payment_change/static/description/pos_payment_change_wizard_form.png
  4. 8
      pos_payment_change/tests/test_module.py
  5. 3
      pos_payment_change/wizards/__init__.py
  6. 39
      pos_payment_change/wizards/pos_payment_change_wizard.py
  7. 11
      pos_payment_change/wizards/pos_payment_change_wizard_new_line.py
  8. 23
      pos_payment_change/wizards/pos_payment_change_wizard_old_line.py
  9. 14
      pos_payment_change/wizards/view_pos_payment_change_wizard.xml

68
pos_payment_change/i18n/fr.po

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-27 10:44+0000\n"
"PO-Revision-Date: 2020-04-27 10:44+0000\n"
"POT-Creation-Date: 2020-05-18 17:33+0000\n"
"PO-Revision-Date: 2020-05-18 17:33+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -16,7 +16,7 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: pos_payment_change #. module: pos_payment_change
#: code:addons/pos_payment_change/models/pos_order.py:78
#: code:addons/pos_payment_change/models/pos_order.py:79
#, python-format #, python-format
msgid " (Refund Order: %s ; Resale Order: %s)" msgid " (Refund Order: %s ; Resale Order: %s)"
msgstr " (Remboursement: %s ; Revente : %s)" msgstr " (Remboursement: %s ; Revente : %s)"
@ -27,7 +27,8 @@ msgid "<span class=\"o_form_label\">Payment Change Policy</span>"
msgstr "<span class=\"o_form_label\">Méthode de changement de paiement</span>" msgstr "<span class=\"o_form_label\">Méthode de changement de paiement</span>"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__amount
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__amount
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__amount
msgid "Amount" msgid "Amount"
msgstr "Montant" msgstr "Montant"
@ -45,18 +46,20 @@ msgstr "Changer les paiements"
#. module: pos_payment_change #. 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__create_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__create_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__create_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__create_uid
msgid "Created by" msgid "Created by"
msgstr "Créé par" msgstr "Créé par"
#. module: pos_payment_change #. 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__create_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__create_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__create_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__create_date
msgid "Created on" msgid "Created on"
msgstr "Créé le" msgstr "Créé le"
#. module: pos_payment_change #. module: pos_payment_change
#: code:addons/pos_payment_change/wizards/pos_payment_change_wizard.py:54
#: code:addons/pos_payment_change/wizards/pos_payment_change_wizard.py:69
#, python-format #, python-format
msgid "Differences between the two values for the POS Order '%s':\n" msgid "Differences between the two values for the POS Order '%s':\n"
"\n" "\n"
@ -73,39 +76,55 @@ msgstr "Différences entre les deux valeurs pour la vente '%s':\n"
#. module: pos_payment_change #. 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__display_name
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__display_name
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__display_name
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__display_name
msgid "Display Name" msgid "Display Name"
msgstr "Nom affiché" msgstr "Nom affiché"
#. module: pos_payment_change #. 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__id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__id
msgid "ID" msgid "ID"
msgstr "ID" msgstr "ID"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__new_journal_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__new_journal_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__old_journal_id
msgid "Journal" msgid "Journal"
msgstr "Journal" msgstr "Journal"
#. module: pos_payment_change #. 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____last_update
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line____last_update
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line____last_update
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line____last_update
msgid "Last Modified on" msgid "Last Modified on"
msgstr "Dernière modification le" msgstr "Dernière modification le"
#. module: pos_payment_change #. 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__write_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__write_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__write_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__write_uid
msgid "Last Updated by" msgid "Last Updated by"
msgstr "Dernière mise à jour par" msgstr "Dernière mise à jour par"
#. module: pos_payment_change #. 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__write_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__write_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__write_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__write_date
msgid "Last Updated on" msgid "Last Updated on"
msgstr "Dernière mise à jour le" msgstr "Dernière mise à jour le"
#. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__new_line_ids
msgid "New Payment Lines"
msgstr "Nouveaux paiements"
#. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__old_line_ids
msgid "Old Payment Lines"
msgstr "Anciens paiements"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__order_id #: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__order_id
msgid "Order" msgid "Order"
@ -129,21 +148,20 @@ msgstr "Méthode de changement de paiement quand les utilisateurs veulent change
"\n" "\n"
"Note : dans certains pays, l'option 'Modifier les paiements' n'est pas autorisé par la loi, parce que l'historique des ventes ne doit pas être altéré." "Note : dans certains pays, l'option 'Modifier les paiements' n'est pas autorisé par la loi, parce que l'historique des ventes ne doit pas être altéré."
#. 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 "Lignes de paiement"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard #: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard
msgid "PoS Payment Change Wizard" msgid "PoS Payment Change Wizard"
msgstr "Assistant de changement de paiement du Point de Vente" msgstr "Assistant de changement de paiement du Point de Vente"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_line
msgid "PoS Payment Change Wizard Line"
msgstr "Ligne d'assistant de changement de paiement du Point de Vente"
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_new_line
msgid "PoS Payment Change Wizard New Line"
msgstr "Nouvelle ligne de l'ssistant de changement de paiement du Point de Vente"
#. module: pos_payment_change
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_old_line
msgid "PoS Payment Change Wizard Old Line"
msgstr "Ancienne ligne de l'ssistant de changement de paiement du Point de Vente"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model,name:pos_payment_change.model_pos_config #: model:ir.model,name:pos_payment_change.model_pos_config
@ -184,12 +202,14 @@ msgid "Update Payments"
msgstr "Modifier les paiements" msgstr "Modifier les paiements"
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__wizard_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__wizard_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__wizard_id
msgid "Wizard" msgid "Wizard"
msgstr "Assistant" msgstr "Assistant"
#. module: pos_payment_change #. module: pos_payment_change
#: code:addons/pos_payment_change/models/pos_order.py:96
#: code:addons/pos_payment_change/models/pos_order.py:97
#, python-format #, python-format
msgid "You can not change payments of the POS '%s' because the associated session '%s' has been closed!" 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é !" msgstr "Vous ne pouvez pas changer les paiements de la Vente '%s' car la session associée '%s' a été clôturé !"

63
pos_payment_change/i18n/pos_payment_change.pot

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \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"
"POT-Creation-Date: 2020-05-18 17:33+0000\n"
"PO-Revision-Date: 2020-05-18 17:33+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -16,7 +16,7 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: pos_payment_change #. module: pos_payment_change
#: code:addons/pos_payment_change/models/pos_order.py:78
#: code:addons/pos_payment_change/models/pos_order.py:79
#, python-format #, python-format
msgid " (Refund Order: %s ; Resale Order: %s)" msgid " (Refund Order: %s ; Resale Order: %s)"
msgstr "" msgstr ""
@ -27,7 +27,8 @@ msgid "<span class=\"o_form_label\">Payment Change Policy</span>"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__amount
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__amount
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__amount
msgid "Amount" msgid "Amount"
msgstr "" msgstr ""
@ -45,18 +46,20 @@ msgstr ""
#. module: pos_payment_change #. 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__create_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__create_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__create_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__create_uid
msgid "Created by" msgid "Created by"
msgstr "" msgstr ""
#. module: pos_payment_change #. 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__create_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__create_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__create_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__create_date
msgid "Created on" msgid "Created on"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: code:addons/pos_payment_change/wizards/pos_payment_change_wizard.py:54
#: code:addons/pos_payment_change/wizards/pos_payment_change_wizard.py:69
#, python-format #, python-format
msgid "Differences between the two values for the POS Order '%s':\n" msgid "Differences between the two values for the POS Order '%s':\n"
"\n" "\n"
@ -68,39 +71,55 @@ msgstr ""
#. module: pos_payment_change #. 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__display_name
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__display_name
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__display_name
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__display_name
msgid "Display Name" msgid "Display Name"
msgstr "" msgstr ""
#. module: pos_payment_change #. 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__id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__id
msgid "ID" msgid "ID"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__new_journal_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__new_journal_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__old_journal_id
msgid "Journal" msgid "Journal"
msgstr "" msgstr ""
#. module: pos_payment_change #. 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____last_update
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line____last_update
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line____last_update
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line____last_update
msgid "Last Modified on" msgid "Last Modified on"
msgstr "" msgstr ""
#. module: pos_payment_change #. 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__write_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__write_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__write_uid
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__write_uid
msgid "Last Updated by" msgid "Last Updated by"
msgstr "" msgstr ""
#. module: pos_payment_change #. 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__write_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__write_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__write_date
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__write_date
msgid "Last Updated on" msgid "Last Updated on"
msgstr "" msgstr ""
#. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__new_line_ids
msgid "New Payment Lines"
msgstr ""
#. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__old_line_ids
msgid "Old Payment Lines"
msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__order_id #: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard__order_id
msgid "Order" msgid "Order"
@ -121,19 +140,18 @@ msgid "Payment Change Policy when users want to change the payment lines of a gi
msgstr "" msgstr ""
#. module: pos_payment_change #. 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"
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard
msgid "PoS Payment Change Wizard"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard
msgid "PoS Payment Change Wizard"
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_new_line
msgid "PoS Payment Change Wizard New Line"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_line
msgid "PoS Payment Change Wizard Line"
#: model:ir.model,name:pos_payment_change.model_pos_payment_change_wizard_old_line
msgid "PoS Payment Change Wizard Old Line"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
@ -175,12 +193,13 @@ msgid "Update Payments"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_line__wizard_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_new_line__wizard_id
#: model:ir.model.fields,field_description:pos_payment_change.field_pos_payment_change_wizard_old_line__wizard_id
msgid "Wizard" msgid "Wizard"
msgstr "" msgstr ""
#. module: pos_payment_change #. module: pos_payment_change
#: code:addons/pos_payment_change/models/pos_order.py:96
#: code:addons/pos_payment_change/models/pos_order.py:97
#, python-format #, python-format
msgid "You can not change payments of the POS '%s' because the associated session '%s' has been closed!" msgid "You can not change payments of the POS '%s' because the associated session '%s' has been closed!"
msgstr "" msgstr ""

BIN
pos_payment_change/static/description/pos_payment_change_wizard_form.png

Before

Width: 971  |  Height: 375  |  Size: 24 KiB

After

Width: 969  |  Height: 498  |  Size: 30 KiB

8
pos_payment_change/tests/test_module.py

@ -17,8 +17,8 @@ class TestModule(TransactionCase):
self.AccountJournal = self.env["account.journal"] self.AccountJournal = self.env["account.journal"]
self.PosMakePayment = self.env['pos.make.payment'] self.PosMakePayment = self.env['pos.make.payment']
self.PosPaymentChangeWizard = self.env["pos.payment.change.wizard"] self.PosPaymentChangeWizard = self.env["pos.payment.change.wizard"]
self.PosPaymentChangeWizardLine = self.env[
"pos.payment.change.wizard.line"
self.PosPaymentChangeWizardNewLine = self.env[
"pos.payment.change.wizard.new.line"
] ]
self.product = self.env.ref("product.product_product_3") self.product = self.env.ref("product.product_product_3")
self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy() self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()
@ -91,7 +91,7 @@ class TestModule(TransactionCase):
wizard = self.PosPaymentChangeWizard.with_context( wizard = self.PosPaymentChangeWizard.with_context(
active_id=order.id active_id=order.id
).create({}) ).create({})
self.PosPaymentChangeWizardLine.with_context(
self.PosPaymentChangeWizardNewLine.with_context(
active_id=order.id active_id=order.id
).create( ).create(
{ {
@ -101,7 +101,7 @@ class TestModule(TransactionCase):
} }
) )
if journal_2: if journal_2:
self.PosPaymentChangeWizardLine.with_context(
self.PosPaymentChangeWizardNewLine.with_context(
active_id=order.id active_id=order.id
).create( ).create(
{ {

3
pos_payment_change/wizards/__init__.py

@ -1,2 +1,3 @@
from . import pos_payment_change_wizard from . import pos_payment_change_wizard
from . import pos_payment_change_wizard_line
from . import pos_payment_change_wizard_new_line
from . import pos_payment_change_wizard_old_line

39
pos_payment_change/wizards/pos_payment_change_wizard.py

@ -15,10 +15,17 @@ class PosPaymentChangeWizard(models.TransientModel):
comodel_name="pos.order", string="Order", readonly=True comodel_name="pos.order", string="Order", readonly=True
) )
line_ids = fields.One2many(
comodel_name="pos.payment.change.wizard.line",
old_line_ids = fields.One2many(
comodel_name="pos.payment.change.wizard.old.line",
inverse_name="wizard_id", inverse_name="wizard_id",
string="Payment Lines",
string="Old Payment Lines",
readonly=True,
)
new_line_ids = fields.One2many(
comodel_name="pos.payment.change.wizard.new.line",
inverse_name="wizard_id",
string="New Payment Lines",
) )
amount_total = fields.Float(string="Total", readonly=True) amount_total = fields.Float(string="Total", readonly=True)
@ -29,8 +36,18 @@ class PosPaymentChangeWizard(models.TransientModel):
PosOrder = self.env["pos.order"] PosOrder = self.env["pos.order"]
res = super().default_get(fields) res = super().default_get(fields)
order = PosOrder.browse(self._context.get("active_id")) order = PosOrder.browse(self._context.get("active_id"))
res.update({"order_id": order.id})
res.update({"amount_total": order.amount_total})
old_lines_vals = []
for statement_line in order.statement_ids:
old_lines_vals.append((0, 0, {
"old_journal_id": statement_line.statement_id.journal_id.id,
"amount": statement_line.amount
}
))
res.update({
"order_id": order.id,
"amount_total": order.amount_total,
"old_line_ids": old_lines_vals,
})
return res return res
# View section # View section
@ -40,9 +57,7 @@ class PosPaymentChangeWizard(models.TransientModel):
order = self.order_id order = self.order_id
# Check if the total is correct # Check if the total is correct
total = 0
for line in self.line_ids:
total += line.amount
total = sum(self.mapped("new_line_ids.amount"))
if total != self.amount_total: if total != self.amount_total:
raise UserError( raise UserError(
_( _(
@ -60,10 +75,16 @@ class PosPaymentChangeWizard(models.TransientModel):
"journal": line.new_journal_id.id, "journal": line.new_journal_id.id,
"amount": line.amount, "amount": line.amount,
"payment_date": fields.Date.context_today(self), "payment_date": fields.Date.context_today(self),
} for line in self.line_ids]
} for line in self.new_line_ids]
orders = order.change_payment(new_payments) orders = order.change_payment(new_payments)
# Note. Because of the poor design of the closing session process
# in Odoo, we call _check_pos_session_balance() that sets
# balance_end_real with balance_end for "non cash" journals
if order.session_id.state == "closing_control":
order.session_id._check_pos_session_balance()
if len(orders) == 1: if len(orders) == 1:
# if policy is 'update', only close the pop up # if policy is 'update', only close the pop up
action = {'type': 'ir.actions.act_window_close'} action = {'type': 'ir.actions.act_window_close'}

11
pos_payment_change/wizards/pos_payment_change_wizard_line.py → pos_payment_change/wizards/pos_payment_change_wizard_new_line.py

@ -6,8 +6,8 @@ from odoo import api, fields, models
class PosPaymentChangeWizardLine(models.TransientModel): class PosPaymentChangeWizardLine(models.TransientModel):
_name = "pos.payment.change.wizard.line"
_description = "PoS Payment Change Wizard Line"
_name = "pos.payment.change.wizard.new.line"
_description = "PoS Payment Change Wizard New Line"
wizard_id = fields.Many2one( wizard_id = fields.Many2one(
comodel_name="pos.payment.change.wizard", required=True, comodel_name="pos.payment.change.wizard", required=True,
@ -26,7 +26,6 @@ class PosPaymentChangeWizardLine(models.TransientModel):
def _domain_new_journal_id(self): def _domain_new_journal_id(self):
PosOrder = self.env["pos.order"] PosOrder = self.env["pos.order"]
order = PosOrder.browse(self.env.context.get("active_id")) order = PosOrder.browse(self.env.context.get("active_id"))
# return [("id", "in", order.session_id.journal_ids.ids)]
return [("id", "in", order.mapped( return [("id", "in", order.mapped(
"session_id.statement_ids.journal_id").ids)] "session_id.statement_ids.journal_id").ids)]
@ -34,12 +33,12 @@ class PosPaymentChangeWizardLine(models.TransientModel):
@api.model @api.model
def default_get(self, fields): def default_get(self, fields):
res = super().default_get(fields) res = super().default_get(fields)
if "line_ids" not in self._context:
if "new_line_ids" not in self._context:
return res return res
balance = self._context.get("amount_total", 0.0) balance = self._context.get("amount_total", 0.0)
for line in self.wizard_id.resolve_2many_commands( for line in self.wizard_id.resolve_2many_commands(
"line_ids",
self._context["line_ids"],
"new_line_ids",
self._context["new_line_ids"],
fields=["amount"]): fields=["amount"]):
balance -= line.get("amount") balance -= line.get("amount")
res.update({'amount': balance}) res.update({'amount': balance})

23
pos_payment_change/wizards/pos_payment_change_wizard_old_line.py

@ -0,0 +1,23 @@
# Copyright (C) 2015 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class PosPaymentChangeWizardOldLine(models.TransientModel):
_name = "pos.payment.change.wizard.old.line"
_description = "PoS Payment Change Wizard Old Line"
wizard_id = fields.Many2one(
comodel_name="pos.payment.change.wizard", required=True,
)
old_journal_id = fields.Many2one(
comodel_name="account.journal",
string="Journal",
required=True,
readonly=True,
)
amount = fields.Float(string="Amount", required=True, readonly=True)

14
pos_payment_change/wizards/view_pos_payment_change_wizard.xml

@ -13,11 +13,17 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<form> <form>
<group col="4"> <group col="4">
<field name="order_id" /> <field name="order_id" />
<field name="amount_total" />
<field name="amount_total" invisible="1"/>
<field name="old_line_ids" colspan="4">
<tree>
<field name="old_journal_id"/>
<field name="amount" sum="Total"/>
</tree>
</field>
<newline /> <newline />
<field name="line_ids" colspan="4"
context="{'line_ids': line_ids, 'amount_total': amount_total}">
<tree string="Payment Lines" editable="bottom">
<field name="new_line_ids" colspan="4"
context="{'new_line_ids': new_line_ids, 'amount_total': amount_total}">
<tree editable="bottom">
<field name="new_journal_id" options="{'no_open': True, 'no_create_edit': True}"/> <field name="new_journal_id" options="{'no_open': True, 'no_create_edit': True}"/>
<field name="amount" sum="Total"/> <field name="amount" sum="Total"/>
</tree> </tree>

Loading…
Cancel
Save