diff --git a/README.md b/README.md index 9310348..30ab60e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ addon | version | summary [account_payment_sale](account_payment_sale/) | 2.0.1.0.0| Adds payment mode on sale orders [account_payment_purchase_stock](account_payment_purchase_stock/) | 2.0.1.0.0| Integrate Account Payment Purchase with Stock [account_payment_purchase](account_payment_purchase/) | 2.0.1.0.0| Adds Bank Account and Payment Mode on Purchase Orders -[account_payment_partner](account_payment_partner/) | 2.0.1.1.2| Adds payment mode on partners and invoices +[account_payment_partner](account_payment_partner/) | 2.0.1.2.0| Adds payment mode on partners and invoices [account_banking_pain_base](account_banking_pain_base/) | 2.0.1.0.0| Base module for PAIN file generation [account_banking_sepa_direct_debit](account_banking_sepa_direct_debit/) | 2.0.1.1.0| Create SEPA files for Direct Debit [account_banking_sepa_credit_transfer](account_banking_sepa_credit_transfer/) | 2.0.1.0.0| Create SEPA XML files for Credit Transfers diff --git a/account_payment_partner/COPYRIGHT b/account_payment_partner/COPYRIGHT index 02bd266..9918ccc 100644 --- a/account_payment_partner/COPYRIGHT +++ b/account_payment_partner/COPYRIGHT @@ -9,8 +9,8 @@ Most of the files are Copyright 2014-2016 Akretion (http://www.akretion.com/) Copyright 2016 Akretion (http://www.akretion.com/) Copyright 2017 ForgeFlow S.L. - Copyright 2018 Carlos Dauden - Tecnativa Copyright 2018 Tecnativa - Carlos Dauden + Copyright 2021 Tecnativa - Víctor Martínez Copyright 2018 Flectra Community Many files also contain contributions from third diff --git a/account_payment_partner/README.rst b/account_payment_partner/README.rst index 6c7abdf..2d22dda 100644 --- a/account_payment_partner/README.rst +++ b/account_payment_partner/README.rst @@ -104,8 +104,9 @@ Contributors * Angel Moya * `Tecnativa `_: - * Pedro M. Baeza - * Carlos Dauden + * Pedro M. Baeza + * Carlos Dauden + * Víctor Martínez * `DynApps `_: * Raf Ven diff --git a/account_payment_partner/__manifest__.py b/account_payment_partner/__manifest__.py index a080a5d..a83ca12 100644 --- a/account_payment_partner/__manifest__.py +++ b/account_payment_partner/__manifest__.py @@ -1,15 +1,16 @@ # Copyright 2014 Akretion - Alexis de Lattre # Copyright 2014 Tecnativa - Pedro M. Baeza # Copyright 2018 Tecnativa - Carlos Dauden +# Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Account Payment Partner", - "version": "2.0.1.1.2", + "version": "2.0.1.2.0", "category": "Banking addons", "license": "AGPL-3", "summary": "Adds payment mode on partners and invoices", - "author": "Akretion, " "Tecnativa, " "Odoo Community Association (OCA)", + "author": "Akretion, Tecnativa, Odoo Community Association (OCA)", "website": "https://gitlab.com/flectra-community/bank-payment", "depends": ["account_payment_mode"], "data": [ diff --git a/account_payment_partner/i18n/account_payment_partner.pot b/account_payment_partner/i18n/account_payment_partner.pot index 91559d1..b37a341 100644 --- a/account_payment_partner/i18n/account_payment_partner.pot +++ b/account_payment_partner/i18n/account_payment_partner.pot @@ -162,6 +162,11 @@ msgstr "" msgid "Payment Modes" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -206,6 +211,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/ca.po b/account_payment_partner/i18n/ca.po index 52d2a95..b19bce5 100644 --- a/account_payment_partner/i18n/ca.po +++ b/account_payment_partner/i18n/ca.po @@ -173,6 +173,11 @@ msgstr "" msgid "Payment Modes" msgstr "Modes de pagament" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -217,6 +222,13 @@ msgstr "Mostra en les factures el número de compte bancari parcial o complet" msgid "Supplier Payment Mode" msgstr "Mode de pagament del proveïdor" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, fuzzy, python-format diff --git a/account_payment_partner/i18n/da_DK.po b/account_payment_partner/i18n/da_DK.po index b2aaacd..ffbd4bb 100644 --- a/account_payment_partner/i18n/da_DK.po +++ b/account_payment_partner/i18n/da_DK.po @@ -168,6 +168,11 @@ msgstr "" msgid "Payment Modes" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -212,6 +217,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/de.po b/account_payment_partner/i18n/de.po index 8d3e625..55a362e 100644 --- a/account_payment_partner/i18n/de.po +++ b/account_payment_partner/i18n/de.po @@ -169,6 +169,11 @@ msgstr "" msgid "Payment Modes" msgstr "Zahlungsmodi" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -213,6 +218,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "Zahlungsmethode des Lieferanten" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/es.po b/account_payment_partner/i18n/es.po index ef057da..67fd83b 100644 --- a/account_payment_partner/i18n/es.po +++ b/account_payment_partner/i18n/es.po @@ -8,16 +8,16 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 11.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-11-23 03:38+0000\n" -"PO-Revision-Date: 2021-04-18 16:46+0000\n" +"POT-Creation-Date: 2021-05-25 12:38+0000\n" +"PO-Revision-Date: 2021-05-25 14:40+0200\n" "Last-Translator: Nelson Ramírez Sánchez \n" "Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.3.2\n" +"X-Generator: Poedit 2.3\n" #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.account_payment_mode_form @@ -173,6 +173,11 @@ msgstr "Dominio de Tipo de Pago Modo Filtro" msgid "Payment Modes" msgstr "Modos de pago" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "Modo de pago para rectificaciones" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -221,6 +226,15 @@ msgstr "Mostrar en facturas nº de cuenta bancaria parcial o completo" msgid "Supplier Payment Mode" msgstr "Modo de pago de proveedor" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" +"Este modo de pago se utilizará cuando se realicen facturas rectificativas " +"provenientes del modo de pago actual." + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/es_AR.po b/account_payment_partner/i18n/es_AR.po index 748602a..b5fd467 100644 --- a/account_payment_partner/i18n/es_AR.po +++ b/account_payment_partner/i18n/es_AR.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2021-04-01 03:48+0000\n" +"PO-Revision-Date: 2021-05-30 19:48+0000\n" "Last-Translator: Ignacio Buioli \n" "Language-Team: none\n" "Language: es_AR\n" @@ -170,6 +170,11 @@ msgstr "Tipo de Filtro Dominio de Modo de Pago" msgid "Payment Modes" msgstr "Modos de Pago" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "Modo de pago para reembolsos" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -214,6 +219,15 @@ msgstr "Mostrar en las facturas el número de cuenta bancaria parcial o total" msgid "Supplier Payment Mode" msgstr "Modo de Pago del Proveedor" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" +"Este modo de pago se utilizará cuando se realicen reembolsos provenientes " +"del modo de pago actual." + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/es_CL.po b/account_payment_partner/i18n/es_CL.po index 25769bc..7128725 100644 --- a/account_payment_partner/i18n/es_CL.po +++ b/account_payment_partner/i18n/es_CL.po @@ -170,6 +170,11 @@ msgstr "Modo de pago Tipo de filtro Dominio" msgid "Payment Modes" msgstr "Modos de pago" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -214,6 +219,13 @@ msgstr "Mostrar en las facturas el número de cuenta bancaria total o parcial" msgid "Supplier Payment Mode" msgstr "Modo de pago del proveedor" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/fr.po b/account_payment_partner/i18n/fr.po index 9eb23c4..b928ed9 100644 --- a/account_payment_partner/i18n/fr.po +++ b/account_payment_partner/i18n/fr.po @@ -171,6 +171,11 @@ msgstr "" msgid "Payment Modes" msgstr "Mode de paiement" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -215,6 +220,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "Mode de règlement fournisseur" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, fuzzy, python-format diff --git a/account_payment_partner/i18n/fr_FR.po b/account_payment_partner/i18n/fr_FR.po index 11d42e4..4c8b19b 100644 --- a/account_payment_partner/i18n/fr_FR.po +++ b/account_payment_partner/i18n/fr_FR.po @@ -170,6 +170,11 @@ msgstr "Filtre de mode de paiement de type domaine" msgid "Payment Modes" msgstr "Mode de paiement" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -216,6 +221,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "Mode de règlement fournisseur" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/hr.po b/account_payment_partner/i18n/hr.po index 8dd61bd..9720a48 100644 --- a/account_payment_partner/i18n/hr.po +++ b/account_payment_partner/i18n/hr.po @@ -168,6 +168,11 @@ msgstr "" msgid "Payment Modes" msgstr "Modeli plaćanja" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -212,6 +217,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/nb_NO.po b/account_payment_partner/i18n/nb_NO.po index 9726e88..ac3d8a2 100644 --- a/account_payment_partner/i18n/nb_NO.po +++ b/account_payment_partner/i18n/nb_NO.po @@ -169,6 +169,11 @@ msgstr "" msgid "Payment Modes" msgstr "Betalinger" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -213,6 +218,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/nl.po b/account_payment_partner/i18n/nl.po index 41ed2a9..8280e87 100644 --- a/account_payment_partner/i18n/nl.po +++ b/account_payment_partner/i18n/nl.po @@ -173,6 +173,11 @@ msgstr "" msgid "Payment Modes" msgstr "Betaalwijze" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -217,6 +222,13 @@ msgstr "Toon op facturen een gedeeltelijk of volledig bankrekeningnummer" msgid "Supplier Payment Mode" msgstr "Betaalwijze leverancier" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/pt_BR.po b/account_payment_partner/i18n/pt_BR.po index 2e553a4..8cddc2b 100644 --- a/account_payment_partner/i18n/pt_BR.po +++ b/account_payment_partner/i18n/pt_BR.po @@ -168,6 +168,11 @@ msgstr "" msgid "Payment Modes" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -212,6 +217,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "Modo de Pagamento do Fornecedor" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/i18n/sl.po b/account_payment_partner/i18n/sl.po index c661963..f714356 100644 --- a/account_payment_partner/i18n/sl.po +++ b/account_payment_partner/i18n/sl.po @@ -168,6 +168,11 @@ msgstr "" msgid "Payment Modes" msgstr "" +#. module: account_payment_partner +#: model:ir.model.fields,field_description:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "Payment mode for refunds" +msgstr "" + #. module: account_payment_partner #: model_terms:ir.ui.view,arch_db:account_payment_partner.view_move_line_form msgid "Payments" @@ -212,6 +217,13 @@ msgstr "" msgid "Supplier Payment Mode" msgstr "Metoda plačila dobavitelja" +#. module: account_payment_partner +#: model:ir.model.fields,help:account_payment_partner.field_account_payment_mode__refund_payment_mode_id +msgid "" +"This payment mode will be used when doing refunds coming from the current " +"payment mode." +msgstr "" + #. module: account_payment_partner #: code:addons/account_payment_partner/models/account_payment_mode.py:0 #, python-format diff --git a/account_payment_partner/models/account_move.py b/account_payment_partner/models/account_move.py index 6b3ce72..f9bfa7c 100644 --- a/account_payment_partner/models/account_move.py +++ b/account_payment_partner/models/account_move.py @@ -1,5 +1,6 @@ # Copyright 2014-16 Akretion - Alexis de Lattre # Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza +# Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from flectra import api, fields, models @@ -57,14 +58,27 @@ class AccountMove(models.Model): for move in self: move.payment_mode_id = False if move.partner_id: + partner = move.with_company(move.company_id.id).partner_id if move.move_type == "in_invoice": - move.payment_mode_id = move.with_company( - move.company_id.id - ).partner_id.supplier_payment_mode_id + move.payment_mode_id = partner.supplier_payment_mode_id elif move.move_type == "out_invoice": - move.payment_mode_id = move.with_company( - move.company_id.id - ).partner_id.customer_payment_mode_id + move.payment_mode_id = partner.customer_payment_mode_id + elif ( + move.move_type in ["out_refund", "in_refund"] + and move.reversed_entry_id + ): + move.payment_mode_id = ( + move.reversed_entry_id.payment_mode_id.refund_payment_mode_id + ) + elif not move.reversed_entry_id: + if move.move_type == "out_refund": + move.payment_mode_id = ( + partner.customer_payment_mode_id.refund_payment_mode_id + ) + elif move.move_type == "in_refund": + move.payment_mode_id = ( + partner.supplier_payment_mode_id.refund_payment_mode_id + ) @api.depends("partner_id", "payment_mode_id") def _compute_partner_bank(self): @@ -90,13 +104,9 @@ class AccountMove(models.Model): bank_id = get_bank_id() move.partner_bank_id = bank_id - # I think copying payment mode from invoice to refund by default - # is a good idea because the most common way of "paying" a refund is to - # deduct it on the payment of the next invoice (and OCA/bank-payment - # allows to have negative payment lines since March 2016) def _reverse_move_vals(self, default_values, cancel=True): move_vals = super()._reverse_move_vals(default_values, cancel=cancel) - move_vals["payment_mode_id"] = self.payment_mode_id.id + move_vals["payment_mode_id"] = self.payment_mode_id.refund_payment_mode_id.id if self.move_type == "in_invoice": move_vals["partner_bank_id"] = self.partner_bank_id.id return move_vals diff --git a/account_payment_partner/models/account_payment_mode.py b/account_payment_partner/models/account_payment_mode.py index 82f29b4..1a0b100 100644 --- a/account_payment_partner/models/account_payment_mode.py +++ b/account_payment_partner/models/account_payment_mode.py @@ -1,5 +1,6 @@ # Copyright 2017 ForgeFlow S.L. -# Copyright 2018 Carlos Dauden - Tecnativa +# Copyright 2018 Tecnativa - Carlos Dauden +# Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from flectra import _, api, fields, models @@ -24,6 +25,13 @@ class AccountPaymentMode(models.Model): show_bank_account_chars = fields.Integer( string="# of digits for customer bank account" ) + refund_payment_mode_id = fields.Many2one( + comodel_name="account.payment.mode", + domain="[('payment_type', '!=', payment_type)]", + string="Payment mode for refunds", + help="This payment mode will be used when doing " + "refunds coming from the current payment mode.", + ) @api.constrains("company_id") def account_invoice_company_constrains(self): diff --git a/account_payment_partner/models/res_partner.py b/account_payment_partner/models/res_partner.py index 705651b..e93a6eb 100644 --- a/account_payment_partner/models/res_partner.py +++ b/account_payment_partner/models/res_partner.py @@ -9,13 +9,13 @@ class ResPartner(models.Model): _inherit = "res.partner" supplier_payment_mode_id = fields.Many2one( - "account.payment.mode", + comodel_name="account.payment.mode", company_dependent=True, domain="[('payment_type', '=', 'outbound')]", help="Select the default payment mode for this supplier.", ) customer_payment_mode_id = fields.Many2one( - "account.payment.mode", + comodel_name="account.payment.mode", company_dependent=True, domain="[('payment_type', '=', 'inbound')]", help="Select the default payment mode for this customer.", diff --git a/account_payment_partner/static/description/index.html b/account_payment_partner/static/description/index.html index ea175ab..cb35ea8 100644 --- a/account_payment_partner/static/description/index.html +++ b/account_payment_partner/static/description/index.html @@ -447,8 +447,9 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Danimar Ribeiro
  • Angel Moya <angel.moya@domatix.com>
  • Tecnativa:
  • DynApps:
      diff --git a/account_payment_partner/tests/test_account_payment_partner.py b/account_payment_partner/tests/test_account_payment_partner.py index 0dd10f8..8ea098a 100644 --- a/account_payment_partner/tests/test_account_payment_partner.py +++ b/account_payment_partner/tests/test_account_payment_partner.py @@ -1,12 +1,14 @@ # Copyright 2017 ForgeFlow S.L. +# Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from flectra import _, fields from flectra.exceptions import UserError, ValidationError -from flectra.tests import common +from flectra.fields import Date +from flectra.tests.common import Form, SavepointCase -class TestAccountPaymentPartner(common.SavepointCase): +class TestAccountPaymentPartner(SavepointCase): @classmethod def setUpClass(cls): super().setUpClass() @@ -20,6 +22,7 @@ class TestAccountPaymentPartner(common.SavepointCase): # Refs cls.company = cls.env.ref("base.main_company") cls.acct_type_payable = cls.env.ref("account.data_account_type_payable") + cls.acct_type_receivable = cls.env.ref("account.data_account_type_receivable") cls.acct_type_expenses = cls.env.ref("account.data_account_type_expenses") cls.company_2 = cls.env["res.company"].create({"name": "Company 2"}) @@ -106,9 +109,13 @@ class TestAccountPaymentPartner(common.SavepointCase): "payment_method_id": cls.manual_in.id, "company_id": cls.company.id, "fixed_journal_id": cls.journal_c1.id, + "refund_payment_mode_id": cls.supplier_payment_mode.id, "variable_journal_ids": [(6, 0, [cls.journal_c1.id])], } ) + cls.supplier_payment_mode.write( + {"refund_payment_mode_id": cls.customer_payment_mode.id} + ) cls.customer = ( cls.env["res.partner"] @@ -186,33 +193,19 @@ class TestAccountPaymentPartner(common.SavepointCase): } ) - def _create_invoice(self): - invoice = self.move_model.create( - { - "partner_id": self.supplier.id, - "journal_id": self.journal_purchase.id, - "move_type": "in_invoice", - "invoice_date": fields.Date.today(), - "company_id": self.company.id, - "payment_mode_id": self.env.ref( - "account_payment_mode.payment_mode_outbound_ct1" - ).id, - "invoice_line_ids": [ - ( - 0, - None, - { - "product_id": self.env.ref("product.product_product_4").id, - "quantity": 1.0, - "price_unit": 100.0, - "name": "product that cost 100", - "account_id": self.invoice_line_account.id, - }, - ) - ], - } + def _create_invoice(self, default_move_type, partner): + move_form = Form( + self.env["account.move"].with_context(default_move_type=default_move_type) ) - return invoice + move_form.partner_id = partner + move_form.invoice_date = Date.today() + with move_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.env.ref("product.product_product_4") + line_form.name = "product that cost 100" + line_form.quantity = 1.0 + line_form.price_unit = 100.0 + line_form.account_id = self.invoice_line_account + return move_form.save() def test_create_partner(self): customer = ( @@ -282,14 +275,48 @@ class TestAccountPaymentPartner(common.SavepointCase): self.assertEqual(invoice.payment_mode_id, self.payment_mode_model) self.assertEqual(invoice.partner_bank_id, self.partner_bank_model) - def test_invoice_create(self): - invoice = self._create_invoice() + def test_invoice_create_in_invoice(self): + invoice = self._create_invoice( + default_move_type="in_invoice", partner=self.supplier + ) invoice.action_post() aml = invoice.line_ids.filtered( lambda l: l.account_id.user_type_id == self.acct_type_payable ) self.assertEqual(invoice.payment_mode_id, aml[0].payment_mode_id) + def test_invoice_create_out_invoice(self): + invoice = self._create_invoice( + default_move_type="out_invoice", partner=self.customer + ) + invoice.action_post() + aml = invoice.line_ids.filtered( + lambda l: l.account_id.user_type_id == self.acct_type_receivable + ) + self.assertEqual(invoice.payment_mode_id, aml[0].payment_mode_id) + + def test_invoice_create_out_refund(self): + self.manual_out.bank_account_required = False + invoice = self._create_invoice( + default_move_type="out_refund", partner=self.customer + ) + invoice.action_post() + self.assertEqual( + invoice.payment_mode_id, + self.customer.customer_payment_mode_id.refund_payment_mode_id, + ) + + def test_invoice_create_in_refund(self): + self.manual_in.bank_account_required = False + invoice = self._create_invoice( + default_move_type="in_refund", partner=self.supplier + ) + invoice.action_post() + self.assertEqual( + invoice.payment_mode_id, + self.supplier.supplier_payment_mode_id.refund_payment_mode_id, + ) + def test_invoice_constrains(self): with self.assertRaises(UserError): self.move_model.create( @@ -351,8 +378,38 @@ class TestAccountPaymentPartner(common.SavepointCase): with self.assertRaises(UserError): self.supplier_payment_mode.company_id = self.company_2 - def test_invoice_refund(self): - invoice = self._create_invoice() + def test_invoice_in_refund(self): + invoice = self._create_invoice( + default_move_type="in_invoice", partner=self.supplier + ) + invoice.partner_bank_id = False + invoice.action_post() + # Lets create a refund invoice for invoice_1. + # I refund the invoice Using Refund Button. + refund_invoice_wizard = ( + self.env["account.move.reversal"] + .with_context( + { + "active_ids": [invoice.id], + "active_id": invoice.id, + "active_model": "account.move", + } + ) + .create({"refund_method": "refund", "reason": "reason test create"}) + ) + refund_invoice = self.move_model.browse( + refund_invoice_wizard.reverse_moves()["res_id"] + ) + self.assertEqual( + refund_invoice.payment_mode_id, + invoice.payment_mode_id.refund_payment_mode_id, + ) + self.assertEqual(refund_invoice.partner_bank_id, invoice.partner_bank_id) + + def test_invoice_out_refund(self): + invoice = self._create_invoice( + default_move_type="out_invoice", partner=self.customer + ) invoice.partner_bank_id = False invoice.action_post() # Lets create a refund invoice for invoice_1. @@ -372,7 +429,10 @@ class TestAccountPaymentPartner(common.SavepointCase): refund_invoice_wizard.reverse_moves()["res_id"] ) - self.assertEqual(refund_invoice.payment_mode_id, invoice.payment_mode_id) + self.assertEqual( + refund_invoice.payment_mode_id, + invoice.payment_mode_id.refund_payment_mode_id, + ) self.assertEqual(refund_invoice.partner_bank_id, invoice.partner_bank_id) def test_partner(self): @@ -388,14 +448,22 @@ class TestAccountPaymentPartner(common.SavepointCase): self.assertEqual(customer_invoice.payment_mode_id, self.customer_payment_mode) self.assertEqual(self.supplier_invoice.partner_bank_id, self.supplier_bank) + vals = {"partner_id": self.customer.id, "move_type": "out_refund"} + invoice = self.move_model.new(vals) + self.assertEqual(invoice.payment_mode_id, self.supplier_payment_mode) + vals = {"partner_id": self.supplier.id, "move_type": "in_refund"} + invoice = self.move_model.new(vals) + self.assertEqual(invoice.payment_mode_id, self.customer_payment_mode) vals = {"partner_id": False, "move_type": "out_invoice"} invoice = self.move_model.new(vals) self.assertFalse(invoice.payment_mode_id) - vals = { - "partner_id": False, - "move_type": "in_invoice", - "invoice_date": fields.Date.today(), - } + vals = {"partner_id": False, "move_type": "out_refund"} + invoice = self.move_model.new(vals) + self.assertFalse(invoice.partner_bank_id) + vals = {"partner_id": False, "move_type": "in_invoice"} + invoice = self.move_model.new(vals) + self.assertFalse(invoice.partner_bank_id) + vals = {"partner_id": False, "move_type": "in_refund"} invoice = self.move_model.new(vals) self.assertFalse(invoice.partner_bank_id) diff --git a/account_payment_partner/views/account_payment_mode.xml b/account_payment_partner/views/account_payment_mode.xml index 2f68550..9cb47be 100644 --- a/account_payment_partner/views/account_payment_mode.xml +++ b/account_payment_partner/views/account_payment_mode.xml @@ -6,6 +6,9 @@ account.payment.mode + + +