diff --git a/account_payment_mode_default_account/README.rst b/account_payment_mode_default_account/README.rst new file mode 100644 index 000000000000..c428fb997c38 --- /dev/null +++ b/account_payment_mode_default_account/README.rst @@ -0,0 +1,78 @@ +==================================== +Account Payment Mode Default Account +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5e6b935d02be3e279b161f28ed160f6a00ed4275cf053a5165a1e72435bbc874 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github + :target: https://github.com/OCA/bank-payment/tree/15.0/account_payment_mode_default_account + :alt: OCA/bank-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-payment-15-0/bank-payment-15-0-account_payment_mode_default_account + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to define default receivable and payable accounts +on payment mode to override the account selected on the customer +when computing payment terms lines on invoices. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Akim Juillerat + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/bank-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_mode_default_account/__init__.py b/account_payment_mode_default_account/__init__.py new file mode 100644 index 000000000000..1a9a001cf76a --- /dev/null +++ b/account_payment_mode_default_account/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook, uninstall_hook diff --git a/account_payment_mode_default_account/__manifest__.py b/account_payment_mode_default_account/__manifest__.py new file mode 100644 index 000000000000..9f1135e95891 --- /dev/null +++ b/account_payment_mode_default_account/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Account Payment Mode Default Account", + "summary": "Set Receivable or Payable account according to payment mode", + "version": "15.0.1.0.0", + "category": "Accounting/Accounting", + "website": "https://github.com/OCA/bank-payment", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "account_payment_partner", + ], + "data": [ + "views/account_payment_mode.xml", + ], + "post_init_hook": "post_init_hook", + "uninstall_hook": "uninstall_hook", +} diff --git a/account_payment_mode_default_account/hooks.py b/account_payment_mode_default_account/hooks.py new file mode 100644 index 000000000000..de2560c1429e --- /dev/null +++ b/account_payment_mode_default_account/hooks.py @@ -0,0 +1,39 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import SUPERUSER_ID, api + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + fields_mapping = [ + ("property_account_receivable_id", "property_stored_account_receivable_id"), + ("property_account_payable_id", "property_stored_account_payable_id"), + ] + for orig_fname, new_fname in fields_mapping: + orig_model_field = env["ir.model.fields"]._get("res.partner", orig_fname) + new_model_field = env["ir.model.fields"]._get("res.partner", new_fname) + sql = """ + UPDATE ir_property + SET name = %s, + fields_id = %s + WHERE fields_id = %s; + """ + cr.execute(sql, (new_fname, new_model_field.id, orig_model_field.id)) + + +def uninstall_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + fields_mapping = [ + ("property_account_receivable_id", "property_stored_account_receivable_id"), + ("property_account_payable_id", "property_stored_account_payable_id"), + ] + for orig_fname, new_fname in fields_mapping: + orig_model_field = env["ir.model.fields"]._get("res.partner", orig_fname) + new_model_field = env["ir.model.fields"]._get("res.partner", new_fname) + sql = """ + UPDATE ir_property + SET name = %s, + fields_id = %s + WHERE fields_id = %s; + """ + cr.execute(sql, (orig_fname, orig_model_field.id, new_model_field.id)) diff --git a/account_payment_mode_default_account/i18n/account_payment_mode_default_account.pot b/account_payment_mode_default_account/i18n/account_payment_mode_default_account.pot new file mode 100644 index 000000000000..2a11ec25f86c --- /dev/null +++ b/account_payment_mode_default_account/i18n/account_payment_mode_default_account.pot @@ -0,0 +1,123 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_mode_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \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: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_chart_template +msgid "Account Chart Template" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_account_payable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_account_payable_id +msgid "Account Payable" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_stored_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_stored_account_receivable_id +msgid "Account Receivable" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_stored_account_payable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_stored_account_payable_id +msgid "Account payable" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_res_partner +msgid "Contact" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__default_payable_account_id +msgid "Default Payable Account" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__default_receivable_account_id +msgid "Default Receivable Account" +msgstr "" + +#. module: account_payment_mode_default_account +#: model_terms:ir.ui.view,arch_db:account_payment_mode_default_account.account_payment_mode_form +msgid "Default accounts" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__display_name +msgid "Display Name" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__id +msgid "ID" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_payment_mode +msgid "Payment Modes" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_partner__property_account_payable_id +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_users__property_account_payable_id +msgid "" +"This account will be used instead of the default one as the payable account " +"for the current partner" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_account_payment_mode__default_payable_account_id +msgid "" +"This account will be used instead of the default one as the payable account " +"on invoices using this payment mode" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_partner__property_account_receivable_id +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_users__property_account_receivable_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account for the current partner" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_account_payment_mode__default_receivable_account_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account on invoices using this payment mode" +msgstr "" diff --git a/account_payment_mode_default_account/i18n/es.po b/account_payment_mode_default_account/i18n/es.po new file mode 100644 index 000000000000..bac2c65540aa --- /dev/null +++ b/account_payment_mode_default_account/i18n/es.po @@ -0,0 +1,134 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_mode_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-17 23:41+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_chart_template +msgid "Account Chart Template" +msgstr "Plantilla de Plan Contable" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_account_payable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_account_payable_id +msgid "Account Payable" +msgstr "Cuenta por Pagar" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_stored_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_stored_account_receivable_id +msgid "Account Receivable" +msgstr "Cuentas por cobrar" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_stored_account_payable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_stored_account_payable_id +msgid "Account payable" +msgstr "Cuenta a pagar" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__default_payable_account_id +msgid "Default Payable Account" +msgstr "Cuenta por defecto a pagar" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__default_receivable_account_id +msgid "Default Receivable Account" +msgstr "Cuenta por defecto a cobrar" + +#. module: account_payment_mode_default_account +#: model_terms:ir.ui.view,arch_db:account_payment_mode_default_account.account_payment_mode_form +msgid "Default accounts" +msgstr "Cuentas predeterminadas" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__id +msgid "ID" +msgstr "ID" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_move +msgid "Journal Entry" +msgstr "Entrada en el Diario" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_payment_mode +msgid "Payment Modes" +msgstr "Modalidades de Pago" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_partner__property_account_payable_id +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_users__property_account_payable_id +msgid "" +"This account will be used instead of the default one as the payable account " +"for the current partner" +msgstr "" +"Esta cuenta se utilizará en lugar de la cuenta por defecto como la cuenta " +"pendiente de pago del asociado actual" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_account_payment_mode__default_payable_account_id +msgid "" +"This account will be used instead of the default one as the payable account " +"on invoices using this payment mode" +msgstr "" +"Esta cuenta se utilizará en lugar de la cuenta por defecto como cuenta a " +"pagar en las facturas que utilicen este modo de pago" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_partner__property_account_receivable_id +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_users__property_account_receivable_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account for the current partner" +msgstr "" +"Esta cuenta se utilizará en lugar de la cuenta por defecto como la cuenta a " +"cobrar para la empresa actual" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_account_payment_mode__default_receivable_account_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account on invoices using this payment mode" +msgstr "" +"Esta cuenta se utilizará en lugar de la cuenta por defecto como cuenta a " +"cobrar en las facturas que utilicen este modo de pago" diff --git a/account_payment_mode_default_account/i18n/fr.po b/account_payment_mode_default_account/i18n/fr.po new file mode 100644 index 000000000000..4492ecfaf9ab --- /dev/null +++ b/account_payment_mode_default_account/i18n/fr.po @@ -0,0 +1,124 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_mode_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_chart_template +msgid "Account Chart Template" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_account_payable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_account_payable_id +msgid "Account Payable" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_stored_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_account_receivable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_stored_account_receivable_id +msgid "Account Receivable" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__property_stored_account_payable_id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_users__property_stored_account_payable_id +msgid "Account payable" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_res_partner +msgid "Contact" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__default_payable_account_id +msgid "Default Payable Account" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__default_receivable_account_id +msgid "Default Receivable Account" +msgstr "" + +#. module: account_payment_mode_default_account +#: model_terms:ir.ui.view,arch_db:account_payment_mode_default_account.account_payment_mode_form +msgid "Default accounts" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__display_name +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__display_name +msgid "Display Name" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode__id +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner__id +msgid "ID" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_chart_template____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_move____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_account_payment_mode____last_update +#: model:ir.model.fields,field_description:account_payment_mode_default_account.field_res_partner____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model,name:account_payment_mode_default_account.model_account_payment_mode +msgid "Payment Modes" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_partner__property_account_payable_id +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_users__property_account_payable_id +msgid "" +"This account will be used instead of the default one as the payable account " +"for the current partner" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_account_payment_mode__default_payable_account_id +msgid "" +"This account will be used instead of the default one as the payable account " +"on invoices using this payment mode" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_partner__property_account_receivable_id +#: model:ir.model.fields,help:account_payment_mode_default_account.field_res_users__property_account_receivable_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account for the current partner" +msgstr "" + +#. module: account_payment_mode_default_account +#: model:ir.model.fields,help:account_payment_mode_default_account.field_account_payment_mode__default_receivable_account_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account on invoices using this payment mode" +msgstr "" diff --git a/account_payment_mode_default_account/models/__init__.py b/account_payment_mode_default_account/models/__init__.py new file mode 100644 index 000000000000..fd2a02a8f58b --- /dev/null +++ b/account_payment_mode_default_account/models/__init__.py @@ -0,0 +1,4 @@ +from . import account_move +from . import account_payment_mode +from . import chart_template +from . import res_partner diff --git a/account_payment_mode_default_account/models/account_move.py b/account_payment_mode_default_account/models/account_move.py new file mode 100644 index 000000000000..e0bedca9c928 --- /dev/null +++ b/account_payment_mode_default_account/models/account_move.py @@ -0,0 +1,38 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, models + + +class AccountMove(models.Model): + + _inherit = "account.move" + + def _recompute_payment_terms_lines(self): + if self.payment_mode_id: + return super( + AccountMove, + self.with_context( + _partner_property_account_payment_mode=self.payment_mode_id.id + ), + )._recompute_payment_terms_lines() + else: + return super()._recompute_payment_terms_lines() + + def _get_payment_term_lines(self): + self.ensure_one() + return self.line_ids.filtered( + lambda line: line.account_id.user_type_id.type in ("receivable", "payable") + ) + + @api.onchange("payment_mode_id") + def _onchange_payment_mode_id(self): + if self.payment_mode_id and self.partner_id: + payment_term_lines = self._get_payment_term_lines() + partner = self.partner_id.with_context( + _partner_property_account_payment_mode=self.payment_mode_id.id + ) + # Retrieve account from partner. + if self.is_sale_document(include_receipts=True): + payment_term_lines.account_id = partner.property_account_receivable_id + else: + payment_term_lines.account_id = partner.property_account_payable_id diff --git a/account_payment_mode_default_account/models/account_payment_mode.py b/account_payment_mode_default_account/models/account_payment_mode.py new file mode 100644 index 000000000000..e6899765e3c2 --- /dev/null +++ b/account_payment_mode_default_account/models/account_payment_mode.py @@ -0,0 +1,19 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import fields, models + + +class AccountPaymentMode(models.Model): + + _inherit = "account.payment.mode" + + default_receivable_account_id = fields.Many2one( + "account.account", + domain="[('deprecated', '=', False),('company_id', '=', company_id),('user_type_id.type', '=', 'receivable')]", # noqa + help="This account will be used instead of the default one as the receivable account on invoices using this payment mode", # noqa + ) + default_payable_account_id = fields.Many2one( + "account.account", + domain="[('deprecated', '=', False), ('company_id', '=', company_id),('user_type_id.type', '=', 'payable')]", # noqa + help="This account will be used instead of the default one as the payable account on invoices using this payment mode", # noqa + ) diff --git a/account_payment_mode_default_account/models/chart_template.py b/account_payment_mode_default_account/models/chart_template.py new file mode 100644 index 000000000000..c6dc60626450 --- /dev/null +++ b/account_payment_mode_default_account/models/chart_template.py @@ -0,0 +1,32 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo import models + + +class AccountChartTemplate(models.Model): + _inherit = "account.chart.template" + + def generate_properties(self, acc_template_ref, company): + res = super().generate_properties(acc_template_ref, company) + # Make sure a property with stored in its name is created as default for the company + # so that _get_multi would fetch it if the partner does not have a property itself + PropertyObj = self.env["ir.property"] + todo_list = [ + ( + "property_account_receivable_id", + "property_stored_account_receivable_id", + "res.partner", + ), + ( + "property_account_payable_id", + "property_stored_account_payable_id", + "res.partner", + ), + ] + for chart_field, partner_field, model in todo_list: + account = self[chart_field] + value = acc_template_ref[account].id if account else False + if value: + PropertyObj._set_default(partner_field, model, value, company=company) + return res diff --git a/account_payment_mode_default_account/models/res_partner.py b/account_payment_mode_default_account/models/res_partner.py new file mode 100644 index 000000000000..62cd09f90bb0 --- /dev/null +++ b/account_payment_mode_default_account/models/res_partner.py @@ -0,0 +1,76 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, fields, models + + +class ResPartner(models.Model): + + _inherit = "res.partner" + + property_account_receivable_id = fields.Many2one( + company_dependent=False, + compute="_compute_property_account_receivable_id", + inverse="_inverse_property_account_receivable_id", + ) + + property_stored_account_receivable_id = fields.Many2one( + "account.account", + company_dependent=True, + string="Account Receivable", + domain="[('internal_type', '=', 'receivable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", # noqa + ) + + property_account_payable_id = fields.Many2one( + company_dependent=False, + compute="_compute_property_account_payable_id", + inverse="_inverse_property_account_payable_id", + ) + + property_stored_account_payable_id = fields.Many2one( + "account.account", + company_dependent=True, + string="Account Payable", + domain="[('internal_type', '=', 'payable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", # noqa + ) + + @api.depends("property_stored_account_receivable_id") + @api.depends_context("_partner_property_account_payment_mode") + def _compute_property_account_receivable_id(self): + payment_mode_id = self.env.context.get("_partner_property_account_payment_mode") + if payment_mode_id: + payment_mode = self.env["account.payment.mode"].browse(payment_mode_id) + rec_account = payment_mode.default_receivable_account_id + if rec_account: + self.update({"property_account_receivable_id": rec_account}) + return + for partner in self: + partner.property_account_receivable_id = ( + partner.property_stored_account_receivable_id + ) + + def _inverse_property_account_receivable_id(self): + for partner in self: + partner.property_stored_account_receivable_id = ( + partner.property_account_receivable_id + ) + + @api.depends("property_stored_account_payable_id") + @api.depends_context("_partner_property_account_payment_mode") + def _compute_property_account_payable_id(self): + payment_mode_id = self.env.context.get("_partner_property_account_payment_mode") + if payment_mode_id: + payment_mode = self.env["account.payment.mode"].browse(payment_mode_id) + rec_account = payment_mode.default_payable_account_id + if rec_account: + self.update({"property_account_payable_id": rec_account}) + return + for partner in self: + partner.property_account_payable_id = ( + partner.property_stored_account_payable_id + ) + + def _inverse_property_account_payable_id(self): + for partner in self: + partner.property_stored_account_payable_id = ( + partner.property_account_payable_id + ) diff --git a/account_payment_mode_default_account/readme/CONTRIBUTORS.rst b/account_payment_mode_default_account/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..e31e2f0c4fcf --- /dev/null +++ b/account_payment_mode_default_account/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Akim Juillerat diff --git a/account_payment_mode_default_account/readme/DESCRIPTION.rst b/account_payment_mode_default_account/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..0cf1a90006c1 --- /dev/null +++ b/account_payment_mode_default_account/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module allows to define default receivable and payable accounts +on payment mode to override the account selected on the customer +when computing payment terms lines on invoices. diff --git a/account_payment_mode_default_account/static/description/icon.png b/account_payment_mode_default_account/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/account_payment_mode_default_account/static/description/icon.png differ diff --git a/account_payment_mode_default_account/static/description/index.html b/account_payment_mode_default_account/static/description/index.html new file mode 100644 index 000000000000..73157e5d684a --- /dev/null +++ b/account_payment_mode_default_account/static/description/index.html @@ -0,0 +1,422 @@ + + + + + +Account Payment Mode Default Account + + + +
+

Account Payment Mode Default Account

+ + +

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runboat

+

This module allows to define default receivable and payable accounts +on payment mode to override the account selected on the customer +when computing payment terms lines on invoices.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/bank-payment project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_payment_mode_default_account/tests/__init__.py b/account_payment_mode_default_account/tests/__init__.py new file mode 100644 index 000000000000..533358fca2f7 --- /dev/null +++ b/account_payment_mode_default_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_payment_mode_default_account diff --git a/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py b/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py new file mode 100644 index 000000000000..691a66cf270d --- /dev/null +++ b/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py @@ -0,0 +1,150 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestAccountPaymentModeDefaultAccount(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + chart_template = cls.env.company.chart_template_id + chart_template.try_loading(company=cls.env.company) + receivable_code = chart_template["property_account_receivable_id"].code + cls.receivable_account = cls.env["account.account"].search( + [ + ("company_id", "=", cls.env.company.id), + ("user_type_id.type", "=", "receivable"), + ("code", "=like", receivable_code + "%"), + ], + limit=1, + ) + cls.payable_account = cls.env["account.account"].search( + [ + ("company_id", "=", cls.env.company.id), + ("user_type_id.type", "=", "payable"), + ], + limit=1, + ) + cls.receivable_account2 = cls.receivable_account.copy( + {"code": cls.receivable_account.code + "2"} + ) + cls.payable_account2 = cls.payable_account.copy( + {"code": cls.payable_account.code + "2"} + ) + cls.partner_1 = cls.env.ref("base.res_partner_1") + + cls.payment_mode = cls.env.ref("account_payment_mode.payment_mode_inbound_dd1") + cls.payment_mode.write( + { + "default_receivable_account_id": cls.receivable_account2.id, + "default_payable_account_id": cls.payable_account2.id, + } + ) + cls.payment_mode_without_default = cls.env.ref( + "account_payment_mode.payment_mode_inbound_ct1" + ) + + @classmethod + def _create_invoice(cls, move_type="out_invoice", payment_mode=None): + move_form = Form( + cls.env["account.move"].with_context(default_move_type=move_type) + ) + move_form.partner_id = cls.partner_1 + if payment_mode is not None: + move_form.payment_mode_id = payment_mode + with move_form.invoice_line_ids.new() as line_form: + line_form.name = "test" + line_form.quantity = 1.0 + line_form.price_unit = 100 + invoice = move_form.save() + return invoice + + def test_create_customer_invoice_payment_mode_default(self): + invoice = self._create_invoice(payment_mode=self.payment_mode) + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.receivable_account2) + + def test_create_supplier_invoice_payment_mode_default(self): + invoice = self._create_invoice( + move_type="in_invoice", payment_mode=self.payment_mode + ) + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.payable_account2) + + def test_change_customer_invoice_payment_mode_default(self): + invoice = self._create_invoice() + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.receivable_account) + with Form(invoice) as move_form: + move_form.payment_mode_id = self.payment_mode + self.assertEqual(payment_term_line.account_id, self.receivable_account2) + + def test_change_supplier_invoice_payment_mode_default(self): + invoice = self._create_invoice(move_type="in_invoice") + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.payable_account) + with Form(invoice) as move_form: + move_form.payment_mode_id = self.payment_mode + self.assertEqual(payment_term_line.account_id, self.payable_account2) + + def test_create_customer_invoice_payment_mode_without_default(self): + invoice = self._create_invoice(payment_mode=self.payment_mode_without_default) + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.receivable_account) + + def test_create_supplier_invoice_payment_mode_without_default(self): + invoice = self._create_invoice( + move_type="in_invoice", payment_mode=self.payment_mode_without_default + ) + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.payable_account) + + def test_change_customer_invoice_payment_mode_without_default(self): + invoice = self._create_invoice() + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.receivable_account) + with Form(invoice) as move_form: + move_form.payment_mode_id = self.payment_mode_without_default + self.assertEqual(payment_term_line.account_id, self.receivable_account) + + def test_change_supplier_invoice_payment_mode_without_default(self): + invoice = self._create_invoice(move_type="in_invoice") + payment_term_line = invoice._get_payment_term_lines() + self.assertEqual(payment_term_line.account_id, self.payable_account) + with Form(invoice) as move_form: + move_form.payment_mode_id = self.payment_mode_without_default + self.assertEqual(payment_term_line.account_id, self.payable_account) + + def test_partner_compute_inverse(self): + self.assertEqual( + self.partner_1.property_account_receivable_id, self.receivable_account + ) + self.assertEqual( + self.partner_1.property_account_payable_id, self.payable_account + ) + self.assertEqual( + self.partner_1.with_context( + _partner_property_account_payment_mode=self.payment_mode.id + ).property_account_receivable_id, + self.receivable_account2, + ) + self.assertEqual( + self.partner_1.with_context( + _partner_property_account_payment_mode=self.payment_mode.id + ).property_account_payable_id, + self.payable_account2, + ) + self.partner_1.write( + { + "property_account_receivable_id": self.receivable_account2.id, + "property_account_payable_id": self.payable_account2.id, + } + ) + self.assertEqual( + self.partner_1.property_account_receivable_id, self.receivable_account2 + ) + self.assertEqual( + self.partner_1.property_account_payable_id, self.payable_account2 + ) diff --git a/account_payment_mode_default_account/views/account_payment_mode.xml b/account_payment_mode_default_account/views/account_payment_mode.xml new file mode 100644 index 000000000000..26034d3675cc --- /dev/null +++ b/account_payment_mode_default_account/views/account_payment_mode.xml @@ -0,0 +1,16 @@ + + + + account.payment.mode.form.inherit + account.payment.mode + + + + + + + + + + + diff --git a/setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account b/setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account new file mode 120000 index 000000000000..ba233810d697 --- /dev/null +++ b/setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account @@ -0,0 +1 @@ +../../../../account_payment_mode_default_account \ No newline at end of file diff --git a/setup/account_payment_mode_default_account/setup.py b/setup/account_payment_mode_default_account/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/account_payment_mode_default_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)