diff --git a/account_payment_multi_deduction/README.rst b/account_payment_multi_deduction/README.rst new file mode 100644 index 000000000000..49333f629061 --- /dev/null +++ b/account_payment_multi_deduction/README.rst @@ -0,0 +1,124 @@ +======================================== +Payment Register with Multiple Deduction +======================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1bca9470543545949e88fa8c4196b434fccd4340f7d8f2c30f54d224bf0f27f0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Faccount--payment-lightgray.png?logo=github + :target: https://github.com/OCA/account-payment/tree/18.0/account_payment_multi_deduction + :alt: OCA/account-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-payment-18-0/account-payment-18-0-account_payment_multi_deduction + :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/account-payment&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extend invoice(s)'s register payment feature, from "Mark +invoice as fully paid" with a single writeoff amount, to "Mark invoice +as fully paid (multi deduct)" which allow multiple deduction amounts. + +**Note:** We use the word "Deduction", as the diff amount can be +anything not only to writeoff. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Select 1 invoice, either on form view or tree view +- Click to Register Payment, a payment wizard will open +- Reduce the amount to pay and payment difference amount will appear +- Choose "Mark invoice as fully paid (multi deduct)", and a new + deduction table will appear +- Add deduction amount, make sure total deduction amount is equal to the + payment difference +- Click validate to finish the payment + +Note: this feature only works for 1 invoice payment + +Changelog +========= + +13.0.1.0.0 (2020-01-27) +----------------------- + +- Migration to version 13 +- Following how Odoo 13 works with deduction, the multiple deduction + feature only works for one invoice at a time. + +12.0.1.0.0 (2019-05-05) +----------------------- + +- Start of the history + +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 +------- + +* Ecosoft + +Contributors +------------ + +- Kitti Upariphutthiphong. (http://ecosoft.co.th) +- Saran Lim. + +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. + +.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px + :target: https://github.com/kittiu + :alt: kittiu + +Current `maintainer `__: + +|maintainer-kittiu| + +This module is part of the `OCA/account-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_multi_deduction/__init__.py b/account_payment_multi_deduction/__init__.py new file mode 100644 index 000000000000..ceeb1a31d802 --- /dev/null +++ b/account_payment_multi_deduction/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import models +from . import wizard diff --git a/account_payment_multi_deduction/__manifest__.py b/account_payment_multi_deduction/__manifest__.py new file mode 100644 index 000000000000..4149821b328e --- /dev/null +++ b/account_payment_multi_deduction/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +{ + "name": "Payment Register with Multiple Deduction", + "version": "18.0.1.0.0", + "author": "Ecosoft, Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/account-payment", + "category": "Accounting", + "depends": ["account"], + "data": [ + "security/ir.model.access.csv", + "wizard/account_payment_register_views.xml", + ], + "installable": True, + "development_status": "Alpha", + "maintainers": ["kittiu"], +} diff --git a/account_payment_multi_deduction/i18n/account_payment_multi_deduction.pot b/account_payment_multi_deduction/i18n/account_payment_multi_deduction.pot new file mode 100644 index 000000000000..8859fa564401 --- /dev/null +++ b/account_payment_multi_deduction/i18n/account_payment_multi_deduction.pot @@ -0,0 +1,176 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_multi_deduction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__account_id +msgid "Account" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__analytic_distribution +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__analytic_distribution +msgid "Analytic" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__analytic_distribution_search +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__analytic_distribution_search +msgid "Analytic Distribution Search" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__analytic_precision +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__analytic_precision +msgid "Analytic Precision" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__create_uid +msgid "Created by" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__create_date +msgid "Created on" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__currency_id +msgid "Currency" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__deduct_analytic_distribution +msgid "Deduct Analytic Distribution" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__amount +msgid "Deduction Amount" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__deduction_ids +msgid "Deductions" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__display_name +msgid "Display Name" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__id +msgid "ID" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment__is_multi_deduction +msgid "Is Multi Deduction" +msgstr "" + +#. module: account_payment_multi_deduction +#. odoo-python +#: code:addons/account_payment_multi_deduction/wizard/account_payment_deduction.py:0 +#, python-format +msgid "Keep open" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,help:account_payment_multi_deduction.field_account_payment_deduction__is_open +msgid "Keep this line open" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__name +msgid "Label" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__write_date +msgid "Last Updated on" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields.selection,name:account_payment_multi_deduction.selection__account_payment_register__payment_difference_handling__reconcile_multi_deduct +msgid "Mark invoice as fully paid (multi deduct)" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__is_open +msgid "Open" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__payment_id +msgid "Payment" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model,name:account_payment_multi_deduction.model_account_payment_deduction +msgid "Payment Deduction" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__payment_difference_handling +msgid "Payment Difference Handling" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model,name:account_payment_multi_deduction.model_account_payment +msgid "Payments" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model,name:account_payment_multi_deduction.model_account_payment_register +msgid "Register Payment" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__deduct_residual +msgid "Remainings" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,help:account_payment_multi_deduction.field_account_payment_register__deduction_ids +msgid "Sum of deduction amount(s) must equal to the payment difference" +msgstr "" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,help:account_payment_multi_deduction.field_account_payment_deduction__currency_id +msgid "The payment's currency." +msgstr "" + +#. module: account_payment_multi_deduction +#. odoo-python +#: code:addons/account_payment_multi_deduction/wizard/account_payment_register.py:0 +#, python-format +msgid "The total deduction should be %s" +msgstr "" + +#. module: account_payment_multi_deduction +#: model_terms:ir.ui.view,arch_db:account_payment_multi_deduction.view_account_payment_register_form +msgid "Total Deduction" +msgstr "" diff --git a/account_payment_multi_deduction/i18n/it.po b/account_payment_multi_deduction/i18n/it.po new file mode 100644 index 000000000000..01e482cfecf4 --- /dev/null +++ b/account_payment_multi_deduction/i18n/it.po @@ -0,0 +1,181 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_multi_deduction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-11-06 14:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\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 5.6.2\n" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__account_id +msgid "Account" +msgstr "Conto" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__analytic_distribution +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__analytic_distribution +msgid "Analytic" +msgstr "Analitica" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__analytic_distribution_search +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__analytic_distribution_search +msgid "Analytic Distribution Search" +msgstr "Ricerca distribuzione analitica" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__analytic_precision +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__analytic_precision +msgid "Analytic Precision" +msgstr "Precisione analitica" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__create_uid +msgid "Created by" +msgstr "Creato da" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__create_date +msgid "Created on" +msgstr "Creato il" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__currency_id +msgid "Currency" +msgstr "Valuta" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__deduct_analytic_distribution +msgid "Deduct Analytic Distribution" +msgstr "Detrai distribuzione analitica" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__amount +msgid "Deduction Amount" +msgstr "Valore detrazione" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__deduction_ids +msgid "Deductions" +msgstr "Detrazioni" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__id +msgid "ID" +msgstr "ID" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment__is_multi_deduction +msgid "Is Multi Deduction" +msgstr "È detrazione multipla" + +#. module: account_payment_multi_deduction +#. odoo-python +#: code:addons/account_payment_multi_deduction/wizard/account_payment_deduction.py:0 +#, python-format +msgid "Keep open" +msgstr "Mantenere aperto" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,help:account_payment_multi_deduction.field_account_payment_deduction__is_open +msgid "Keep this line open" +msgstr "Mantenere aperta questa riga" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__name +msgid "Label" +msgstr "Etichetta" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__write_uid +msgid "Last Updated by" +msgstr "Ultimo aggiornamento di" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__write_date +msgid "Last Updated on" +msgstr "Ultimo aggiornamento il" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields.selection,name:account_payment_multi_deduction.selection__account_payment_register__payment_difference_handling__reconcile_multi_deduct +msgid "Mark invoice as fully paid (multi deduct)" +msgstr "Segna fattura come completamente pagata (detrazione multipla)" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__is_open +msgid "Open" +msgstr "Apri" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_deduction__payment_id +msgid "Payment" +msgstr "Pagamento" + +#. module: account_payment_multi_deduction +#: model:ir.model,name:account_payment_multi_deduction.model_account_payment_deduction +msgid "Payment Deduction" +msgstr "Detrazione pagamento" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__payment_difference_handling +msgid "Payment Difference Handling" +msgstr "Gestione differenza pagamento" + +#. module: account_payment_multi_deduction +#: model:ir.model,name:account_payment_multi_deduction.model_account_payment +msgid "Payments" +msgstr "Pagamenti" + +#. module: account_payment_multi_deduction +#: model:ir.model,name:account_payment_multi_deduction.model_account_payment_register +msgid "Register Payment" +msgstr "Registra pagamento" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,field_description:account_payment_multi_deduction.field_account_payment_register__deduct_residual +msgid "Remainings" +msgstr "Residuo" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,help:account_payment_multi_deduction.field_account_payment_register__deduction_ids +msgid "Sum of deduction amount(s) must equal to the payment difference" +msgstr "" +"La somma degli importi dedotti deve essere uguale alla differenza di " +"pagamento" + +#. module: account_payment_multi_deduction +#: model:ir.model.fields,help:account_payment_multi_deduction.field_account_payment_deduction__currency_id +msgid "The payment's currency." +msgstr "La valuta del pagamento." + +#. module: account_payment_multi_deduction +#. odoo-python +#: code:addons/account_payment_multi_deduction/wizard/account_payment_register.py:0 +#, python-format +msgid "The total deduction should be %s" +msgstr "La detrazione totale dovrebbe essere %s" + +#. module: account_payment_multi_deduction +#: model_terms:ir.ui.view,arch_db:account_payment_multi_deduction.view_account_payment_register_form +msgid "Total Deduction" +msgstr "Detrazione totale" diff --git a/account_payment_multi_deduction/models/__init__.py b/account_payment_multi_deduction/models/__init__.py new file mode 100644 index 000000000000..7a5433f20773 --- /dev/null +++ b/account_payment_multi_deduction/models/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import account_payment diff --git a/account_payment_multi_deduction/models/account_payment.py b/account_payment_multi_deduction/models/account_payment.py new file mode 100644 index 000000000000..82751049b8ba --- /dev/null +++ b/account_payment_multi_deduction/models/account_payment.py @@ -0,0 +1,70 @@ +# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class AccountPayment(models.Model): + _inherit = "account.payment" + + is_multi_deduction = fields.Boolean() + + def _get_check_key_list(self): + return ["name", "account_id"] + + def _get_update_key_list(self): + return ["analytic_distribution"] + + def _update_vals_writeoff( + self, write_off_line_vals, line_vals_list, check_keys, update_keys + ): + for line_vals in line_vals_list: + if all( + line_vals[check_key] == write_off_line_vals[0][check_key] + for check_key in check_keys + ): + for update_key in update_keys: + line_vals[update_key] = write_off_line_vals[0][update_key] + break + + def _prepare_move_line_default_vals( + self, write_off_line_vals=None, force_balance=None + ): + """Split amount to multi payment deduction + Concept: + * Process by payment difference 'Mark as fully paid' and keep value is paid + * Process by each deduction and keep value is deduction + * Combine all process and return list + """ + self.ensure_one() + line_vals_list = super()._prepare_move_line_default_vals( + write_off_line_vals, force_balance + ) + # payment difference + if not self.is_multi_deduction and write_off_line_vals: + # update writeoff when edit value in payment + writeoff_lines = self._seek_for_lines()[2] + if not write_off_line_vals[0].get("analytic_distribution", False): + write_off_line_vals[0]["analytic_distribution"] = ( + writeoff_lines.analytic_distribution + ) + # add analytic on line_vals_list + check_keys = self._get_check_key_list() + update_keys = self._get_update_key_list() + self._update_vals_writeoff( + write_off_line_vals, line_vals_list, check_keys, update_keys + ) + return line_vals_list + + def _synchronize_from_moves(self, changed_fields): + if any(rec.is_multi_deduction for rec in self): + self = self.with_context(skip_account_move_synchronization=True) + return super()._synchronize_from_moves(changed_fields) + + def write(self, vals): + """Skip move synchronization when + edit payment with multi deduction + """ + if any(rec.is_multi_deduction for rec in self): + self = self.with_context(skip_account_move_synchronization=True) + return super().write(vals) diff --git a/account_payment_multi_deduction/pyproject.toml b/account_payment_multi_deduction/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/account_payment_multi_deduction/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_payment_multi_deduction/readme/CONTRIBUTORS.md b/account_payment_multi_deduction/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..a12dd3a77167 --- /dev/null +++ b/account_payment_multi_deduction/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Kitti Upariphutthiphong. \<\> + () +- Saran Lim. \<\> diff --git a/account_payment_multi_deduction/readme/DESCRIPTION.md b/account_payment_multi_deduction/readme/DESCRIPTION.md new file mode 100644 index 000000000000..2a9208f806fb --- /dev/null +++ b/account_payment_multi_deduction/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This module extend invoice(s)'s register payment feature, from "Mark +invoice as fully paid" with a single writeoff amount, to "Mark invoice +as fully paid (multi deduct)" which allow multiple deduction amounts. + +**Note:** We use the word "Deduction", as the diff amount can be +anything not only to writeoff. diff --git a/account_payment_multi_deduction/readme/HISTORY.md b/account_payment_multi_deduction/readme/HISTORY.md new file mode 100644 index 000000000000..0a07355f6a24 --- /dev/null +++ b/account_payment_multi_deduction/readme/HISTORY.md @@ -0,0 +1,9 @@ +## 13.0.1.0.0 (2020-01-27) + +- Migration to version 13 +- Following how Odoo 13 works with deduction, the multiple deduction + feature only works for one invoice at a time. + +## 12.0.1.0.0 (2019-05-05) + +- Start of the history diff --git a/account_payment_multi_deduction/readme/USAGE.md b/account_payment_multi_deduction/readme/USAGE.md new file mode 100644 index 000000000000..11e296653019 --- /dev/null +++ b/account_payment_multi_deduction/readme/USAGE.md @@ -0,0 +1,10 @@ +- Select 1 invoice, either on form view or tree view +- Click to Register Payment, a payment wizard will open +- Reduce the amount to pay and payment difference amount will appear +- Choose "Mark invoice as fully paid (multi deduct)", and a new + deduction table will appear +- Add deduction amount, make sure total deduction amount is equal to the + payment difference +- Click validate to finish the payment + +Note: this feature only works for 1 invoice payment diff --git a/account_payment_multi_deduction/security/ir.model.access.csv b/account_payment_multi_deduction/security/ir.model.access.csv new file mode 100644 index 000000000000..e13bf12d8b15 --- /dev/null +++ b/account_payment_multi_deduction/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_payment_deduction,account.payment.deduction,model_account_payment_deduction,account.group_account_invoice,1,1,1,1 diff --git a/account_payment_multi_deduction/static/description/icon.png b/account_payment_multi_deduction/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/account_payment_multi_deduction/static/description/icon.png differ diff --git a/account_payment_multi_deduction/static/description/index.html b/account_payment_multi_deduction/static/description/index.html new file mode 100644 index 000000000000..edf9cb402998 --- /dev/null +++ b/account_payment_multi_deduction/static/description/index.html @@ -0,0 +1,473 @@ + + + + + +Payment Register with Multiple Deduction + + + +
+

Payment Register with Multiple Deduction

+ + +

Alpha License: AGPL-3 OCA/account-payment Translate me on Weblate Try me on Runboat

+

This module extend invoice(s)’s register payment feature, from “Mark +invoice as fully paid” with a single writeoff amount, to “Mark invoice +as fully paid (multi deduct)” which allow multiple deduction amounts.

+

Note: We use the word “Deduction”, as the diff amount can be +anything not only to writeoff.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Usage

+
    +
  • Select 1 invoice, either on form view or tree view
  • +
  • Click to Register Payment, a payment wizard will open
  • +
  • Reduce the amount to pay and payment difference amount will appear
  • +
  • Choose “Mark invoice as fully paid (multi deduct)”, and a new +deduction table will appear
  • +
  • Add deduction amount, make sure total deduction amount is equal to the +payment difference
  • +
  • Click validate to finish the payment
  • +
+

Note: this feature only works for 1 invoice payment

+
+
+

Changelog

+
+

13.0.1.0.0 (2020-01-27)

+
    +
  • Migration to version 13
  • +
  • Following how Odoo 13 works with deduction, the multiple deduction +feature only works for one invoice at a time.
  • +
+
+
+

12.0.1.0.0 (2019-05-05)

+
    +
  • Start of the history
  • +
+
+
+
+

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

+
    +
  • Ecosoft
  • +
+
+
+

Contributors

+ +
+
+

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.

+

Current maintainer:

+

kittiu

+

This module is part of the OCA/account-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_multi_deduction/tests/__init__.py b/account_payment_multi_deduction/tests/__init__.py new file mode 100644 index 000000000000..178489c220a3 --- /dev/null +++ b/account_payment_multi_deduction/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import test_payment_multi_deduction diff --git a/account_payment_multi_deduction/tests/test_payment_multi_deduction.py b/account_payment_multi_deduction/tests/test_payment_multi_deduction.py new file mode 100644 index 000000000000..d1acc99fa761 --- /dev/null +++ b/account_payment_multi_deduction/tests/test_payment_multi_deduction.py @@ -0,0 +1,309 @@ +# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import Command, fields +from odoo.exceptions import UserError +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestPaymentMultiDeduction(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.move_line_model = cls.env["account.move.line"] + cls.move_model = cls.env["account.move"] + cls.payment_model = cls.env["account.payment"] + cls.journal_model = cls.env["account.journal"] + cls.currency_model = cls.env["res.currency"] + cls.payment_register_model = cls.env["account.payment.register"] + + cls.register_view_id = "account.view_account_payment_register_form" + cls.partner = cls.env.ref("base.res_partner_12") + cls.product = cls.env.ref("product.product_product_3") + cls.outstanding_receipt = cls.env.ref( + "account.1_account_journal_payment_debit_account_id" + ) + cls.outstanding_payment = cls.env.ref( + "account.1_account_journal_payment_credit_account_id" + ) + cls.account_receivable = cls.partner.property_account_receivable_id + cls.account_revenue = cls.env["account.account"].search( + [ + ("account_type", "=", "income"), + ], + limit=1, + ) + cls.account_expense = cls.env["account.account"].search( + [ + ("account_type", "=", "expense"), + ], + limit=1, + ) + + cls.journal_bank = cls.journal_model.search([("type", "=", "bank")])[0] + + # Add account in payment method line + cls.journal_bank.outbound_payment_method_line_ids.payment_account_id = ( + cls.outstanding_receipt.id + ) + cls.journal_bank.inbound_payment_method_line_ids.payment_account_id = ( + cls.outstanding_payment.id + ) + + cls.cust_invoice = cls.move_model.create( + { + "name": "Test Customer Invoice", + "move_type": "out_invoice", + "journal_id": cls.journal_model.search( + [("type", "=", "sale")], limit=1 + ).id, + "partner_id": cls.partner.id, + "invoice_line_ids": [ + Command.create( + { + "product_id": cls.product.id, + "quantity": 1.0, + "account_id": cls.account_revenue.id, + "name": "[PCSC234] PC Assemble SC234", + "price_unit": 450.00, + "tax_ids": False, + }, + ) + ], + } + ) + + # New currency, 2X lower + cls.company_currency = cls.cust_invoice.currency_id + cls.currency_2x = cls.currency_model.create( + { + "name": "2X", # Foreign currency, 2 time + "symbol": "X", + "rate_ids": [ + Command.create( + { + "name": fields.Date.today(), + "company_rate": cls.company_currency.rate * 2, + } + ) + ], + } + ) + + def test_one_invoice_payment(self): + """Validate 1 invoice and make payment with 2 deduction""" + self.cust_invoice.action_post() # total amount 450.0 + ctx = { + "active_ids": [self.cust_invoice.id], + "active_id": self.cust_invoice.id, + "active_model": "account.move", + } + with self.assertRaises(UserError): # Deduct only 20.0, throw error + with Form( + self.payment_register_model.with_context(**ctx), + view=self.register_view_id, + ) as f: + f.amount = 400.0 + f.payment_difference_handling = "reconcile_multi_deduct" + with f.deduction_ids.new() as f2: + f2.account_id = self.account_expense + f2.name = "Expense 1" + f2.amount = 20.0 + f.save() + with Form( + self.payment_register_model.with_context(**ctx), view=self.register_view_id + ) as f: + f.amount = 400.0 # Reduce to 400.0, and mark fully paid (multi) + f.payment_difference_handling = "reconcile_multi_deduct" + with f.deduction_ids.new() as f2: + f2.account_id = self.account_expense + f2.name = "Expense 1" + f2.amount = 20.0 + with f.deduction_ids.new() as f2: + f2.account_id = self.account_expense + f2.name = "Expense 2" + f2.amount = 30.0 + + payment_register = f.save() + payment_id = payment_register._create_payments() + payment = self.payment_model.browse(payment_id.id) + self.assertEqual(payment.state, "paid") + + move_lines = self.move_line_model.search([("payment_id", "=", payment.id)]) + self.assertEqual(self.cust_invoice.payment_state, "paid") + self.assertRecordValues( + move_lines, + [ + { + "account_id": self.outstanding_payment.id, + "name": "Manual Payment: Test Customer Invoice", + "debit": 400.0, + "credit": 0.0, + }, + { + "account_id": self.account_receivable.id, + "name": "Manual Payment: Test Customer Invoice", + "debit": 0.0, + "credit": 450.0, + }, + { + "account_id": self.account_expense.id, + "name": "Expense 1", + "debit": 20.0, + "credit": 0.0, + }, + { + "account_id": self.account_expense.id, + "name": "Expense 2", + "debit": 30.0, + "credit": 0.0, + }, + ], + ) + + def test_one_invoice_payment_foreign_currency(self): + """Validate 1 invoice and make payment with 2 deduction""" + self.cust_invoice.action_post() # total amount 450.0 + ctx = { + "active_ids": [self.cust_invoice.id], + "active_id": self.cust_invoice.id, + "active_model": "account.move", + } + with Form( + self.payment_register_model.with_context(**ctx), view=self.register_view_id + ) as f: + f.currency_id = self.currency_2x + f.amount = 800.0 # 400 -> 800 as we use currency 2x + f.payment_difference_handling = "reconcile_multi_deduct" + with f.deduction_ids.new() as f2: + f2.account_id = self.account_expense + f2.name = "Expense 1" + f2.amount = 40.0 # 20 -> 40 + with f.deduction_ids.new() as f2: + f2.account_id = self.account_expense + f2.name = "Expense 2" + f2.amount = 60.0 # 60 -> 80 + + payment_register = f.save() + payment_id = payment_register._create_payments() + payment = self.payment_model.browse(payment_id.id) + self.assertEqual(payment.state, "paid") + + move_lines = self.move_line_model.search([("payment_id", "=", payment.id)]) + self.assertEqual(self.cust_invoice.payment_state, "paid") + self.assertRecordValues( + move_lines, + [ + { + "account_id": self.outstanding_payment.id, + "name": "Manual Payment: Test Customer Invoice", + "debit": 400.0, + "credit": 0.0, + "amount_currency": 800.0, + "currency_id": self.currency_2x.id, + }, + { + "account_id": self.account_receivable.id, + "name": "Manual Payment: Test Customer Invoice", + "debit": 0.0, + "credit": 450.0, + "amount_currency": -900.0, + "currency_id": self.currency_2x.id, + }, + { + "account_id": self.account_expense.id, + "name": "Expense 1", + "debit": 20.0, + "credit": 0.0, + "amount_currency": 40.0, + "currency_id": self.currency_2x.id, + }, + { + "account_id": self.account_expense.id, + "name": "Expense 2", + "debit": 30.0, + "credit": 0.0, + "amount_currency": 60.0, + "currency_id": self.currency_2x.id, + }, + ], + ) + + def test_one_invoice_payment_with_keep_open(self): + """Validate 1 invoice and make payment with 2 deduction, + one as normal deduct and another as keep open""" + self.cust_invoice.action_post() # total amount 450.0 + ctx = { + "active_ids": [self.cust_invoice.id], + "active_id": self.cust_invoice.id, + "active_model": "account.move", + } + with Form(self.payment_register_model.with_context(**ctx)) as f: + f.amount = 400.0 # Reduce to 400.0, and mark fully paid (multi) + f.payment_difference_handling = "reconcile_multi_deduct" + with f.deduction_ids.new() as f2: + f2.account_id = self.account_expense + f2.name = "Expense 1" + f2.amount = 20.0 + with f.deduction_ids.new() as f2: # Keep Open + f2.is_open = True + f2.amount = 30.0 + payment_register = f.save() + payment_id = payment_register._create_payments() + payment = self.payment_model.browse(payment_id.id) + self.assertEqual(payment.state, "in_process") + payment.action_validate() + self.assertEqual(payment.state, "paid") + move_lines = self.move_line_model.search([("payment_id", "=", payment.id)]) + self.assertEqual(self.cust_invoice.payment_state, "partial") + self.assertEqual(self.cust_invoice.amount_residual, 30) + + self.assertRecordValues( + move_lines, + [ + { + "account_id": self.outstanding_payment.id, + "name": "Manual Payment: Test Customer Invoice", + "debit": 400.0, + "credit": 0.0, + }, + { + "account_id": self.account_receivable.id, + "credit": 420.0, + "debit": 0.0, + "name": "Manual Payment: Test Customer Invoice", + }, + { + "account_id": 30, + "credit": 0.0, + "debit": 20.0, + "name": "Expense 1", + }, + ], + ) + + def test_invoice_payment_fully_paid(self): + """Validate 1 invoice and make payment with 1 deduction""" + self.cust_invoice.action_post() # total amount 450.0 + + action = self.cust_invoice.action_register_payment() + ctx = action.get("context") + + with Form(self.payment_register_model.with_context(**ctx)) as f: + f.amount = 400.0 # Reduce to 400.0, and mark fully paid (multi) + f.payment_difference_handling = "reconcile" + f.writeoff_account_id = self.account_expense + payment_register = f.save() + payment_id = payment_register._create_payments() + payment = self.payment_model.browse(payment_id.id) + self.assertEqual(payment.state, "paid") + + move_lines = self.move_line_model.search( + [ + ("payment_id", "=", payment.id), + ("account_id", "=", self.account_expense.id), + ] + ) + self.assertEqual(len(move_lines), 1) diff --git a/account_payment_multi_deduction/wizard/__init__.py b/account_payment_multi_deduction/wizard/__init__.py new file mode 100644 index 000000000000..968e95711ac1 --- /dev/null +++ b/account_payment_multi_deduction/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import account_payment_deduction +from . import account_payment_register diff --git a/account_payment_multi_deduction/wizard/account_payment_deduction.py b/account_payment_multi_deduction/wizard/account_payment_deduction.py new file mode 100644 index 000000000000..1e46c5d699a6 --- /dev/null +++ b/account_payment_multi_deduction/wizard/account_payment_deduction.py @@ -0,0 +1,42 @@ +# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import _, api, fields, models + + +class AccountPaymentDeduction(models.TransientModel): + _name = "account.payment.deduction" + _inherit = "analytic.mixin" + _description = "Payment Deduction" + + payment_id = fields.Many2one( + comodel_name="account.payment.register", + readonly=True, + ondelete="cascade", + ) + currency_id = fields.Many2one( + comodel_name="res.currency", + related="payment_id.currency_id", + readonly=True, + ) + account_id = fields.Many2one( + comodel_name="account.account", + domain=[("deprecated", "=", False)], + required=False, + ) + is_open = fields.Boolean(string="Open", help="Keep this line open") + amount = fields.Monetary(string="Deduction Amount", required=True) + name = fields.Char(string="Label", required=True) + + @api.onchange("is_open") + def _onchange_open(self): + if self.is_open: + self.account_id = False + self.name = _("Keep open") + else: + self.name = False + + @api.onchange("account_id") + def _onchange_account_id(self): + if self.account_id: + self.is_open = False diff --git a/account_payment_multi_deduction/wizard/account_payment_register.py b/account_payment_multi_deduction/wizard/account_payment_register.py new file mode 100644 index 000000000000..d52d2b656785 --- /dev/null +++ b/account_payment_multi_deduction/wizard/account_payment_register.py @@ -0,0 +1,137 @@ +# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import _, api, fields, models +from odoo.exceptions import UserError +from odoo.tools import float_compare + + +class AccountPaymentRegister(models.TransientModel): + _name = "account.payment.register" + _inherit = ["account.payment.register", "analytic.mixin"] + + payment_difference_handling = fields.Selection( + selection_add=[ + ("reconcile_multi_deduct", "Mark invoice as fully paid (multi deduct)") + ], + ondelete={"reconcile_multi_deduct": "cascade"}, + ) + deduct_residual = fields.Monetary( + string="Remainings", compute="_compute_deduct_residual" + ) + deduction_ids = fields.One2many( + comodel_name="account.payment.deduction", + inverse_name="payment_id", + string="Deductions", + copy=False, + help="Sum of deduction amount(s) must equal to the payment difference", + ) + deduct_analytic_distribution = fields.Json() + + def _update_vals_deduction(self, move_lines): + """For case `Mark as fully paid`, + Hook this method to update field wizard write-off from move lines""" + analytic = {} + [ + analytic.update(item) + for item in move_lines.mapped("analytic_distribution") + if item + ] + self.analytic_distribution = analytic + + def _update_vals_multi_deduction(self, move_lines): + """For case `Mark invoice as fully paid (multi deduct)`, + Hook this method to update field wizard deduct from move lines""" + analytic = {} + [ + analytic.update(item) + for item in move_lines.mapped("analytic_distribution") + if item + ] + self.deduct_analytic_distribution = analytic + + @api.onchange("payment_difference", "payment_difference_handling") + def _onchange_default_deduction(self): + active_ids = self.env.context.get("active_ids", []) + move_lines = self.env["account.move.line"] + model = self.env.context.get("active_model", False) + if model == "account.move.line": + move_lines = move_lines.browse(active_ids) + elif model == "account.move": + move_lines = self.env["account.move"].browse(active_ids).line_ids + + if self.payment_difference_handling == "reconcile": + self._update_vals_deduction(move_lines) + if self.payment_difference_handling == "reconcile_multi_deduct": + self._update_vals_multi_deduction(move_lines) + + @api.constrains("deduction_ids", "payment_difference_handling") + def _check_deduction_amount(self): + prec_digits = self.env.user.company_id.currency_id.decimal_places + for rec in self: + if rec.payment_difference_handling == "reconcile_multi_deduct": + if ( + float_compare( + rec.payment_difference, + sum(rec.deduction_ids.mapped("amount")), + precision_digits=prec_digits, + ) + != 0 + ): + raise UserError( + _("The total deduction should be %s") % rec.payment_difference + ) + + @api.depends("payment_difference", "deduction_ids") + def _compute_deduct_residual(self): + for rec in self: + rec.deduct_residual = rec.payment_difference - sum( + rec.deduction_ids.mapped("amount") + ) + + def _create_payment_vals_from_wizard(self, batch_result): + payment_vals = super()._create_payment_vals_from_wizard(batch_result) + # payment difference + if ( + not self.currency_id.is_zero(self.payment_difference) + and self.payment_difference_handling == "reconcile" + ): + payment_vals["write_off_line_vals"][0]["analytic_distribution"] = ( + self.analytic_distribution + ) + # multi deduction + elif ( + self.payment_difference + and self.payment_difference_handling == "reconcile_multi_deduct" + ): + payment_vals["write_off_line_vals"] = [ + self._prepare_deduct_move_line(deduct) + for deduct in self.deduction_ids.filtered( + lambda deduct: not deduct.is_open + ) + ] + payment_vals["is_multi_deduction"] = True + return payment_vals + + def _prepare_deduct_move_line(self, deduct): + conversion_rate = self.env["res.currency"]._get_conversion_rate( + self.currency_id, + self.company_id.currency_id, + self.company_id, + self.payment_date, + ) + write_off_amount_currency = ( + deduct.amount if self.payment_type == "inbound" else -deduct.amount + ) + write_off_balance = self.company_id.currency_id.round( + write_off_amount_currency * conversion_rate + ) + return { + "name": deduct.name, + "account_id": deduct.account_id.id, + "partner_id": self.partner_id.id, + "currency_id": self.currency_id.id, + "amount_currency": write_off_amount_currency, + "balance": write_off_balance, + "analytic_distribution": deduct.analytic_distribution, + } diff --git a/account_payment_multi_deduction/wizard/account_payment_register_views.xml b/account_payment_multi_deduction/wizard/account_payment_register_views.xml new file mode 100644 index 000000000000..58d9b368e75c --- /dev/null +++ b/account_payment_multi_deduction/wizard/account_payment_register_views.xml @@ -0,0 +1,67 @@ + + + account.payment.register.form + account.payment.register + + + + +
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+
+