diff --git a/sale_order_general_discount/README.rst b/sale_order_general_discount/README.rst index 2456cf24345..05822e9b371 100644 --- a/sale_order_general_discount/README.rst +++ b/sale_order_general_discount/README.rst @@ -28,12 +28,14 @@ Sale Order General Discount |badge1| |badge2| |badge3| |badge4| |badge5| -This module allows to set a general discount in a sales order. This general -discount is set to each line order in the standard `discount` field. +This module allows to set a general discount in a sales order. This +general discount is set to each line order in the standard discount +field. You can configure: - * a default general discount on customers - * On each product define if general discount is applied + +- a default general discount on customers +- On each product define if general discount is applied **Table of contents** @@ -43,19 +45,19 @@ You can configure: Installation ============ -You need to install sale_management module for accessing the needed menus. +You need to install sale_management module for accessing the needed +menus. Usage ===== To use this module, you need to: -#. Create a sale order and set a discount, - this discount will be set in all lines. -#. You can set a discount in a partner. -#. On product you can define if you - apply general discount on sale order line - linked to that product +1. Create a sale order and set a discount, this discount will be set in + all lines. +2. You can set a discount in a partner. +3. On product you can define if you apply general discount on sale order + line linked to that product Bug Tracker =========== @@ -71,23 +73,23 @@ Credits ======= Authors -~~~~~~~ +------- * Tecnativa Contributors -~~~~~~~~~~~~ +------------ -* `Tecnativa `_: +- `Tecnativa `__: - * Sergio Teruel - * Stefan Ungureanu + - Sergio Teruel + - Stefan Ungureanu -* Raf Ven -* Sudhir Arya +- Raf Ven +- Sudhir Arya Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. diff --git a/sale_order_general_discount/readme/CONTRIBUTORS.md b/sale_order_general_discount/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..88f7cbcfcb5 --- /dev/null +++ b/sale_order_general_discount/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel \<\> + - Stefan Ungureanu \<\> +- Raf Ven \<\> +- Sudhir Arya \<\> diff --git a/sale_order_general_discount/readme/CONTRIBUTORS.rst b/sale_order_general_discount/readme/CONTRIBUTORS.rst deleted file mode 100644 index ef09abf24b9..00000000000 --- a/sale_order_general_discount/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1,7 +0,0 @@ -* `Tecnativa `_: - - * Sergio Teruel - * Stefan Ungureanu - -* Raf Ven -* Sudhir Arya diff --git a/sale_order_general_discount/readme/DESCRIPTION.md b/sale_order_general_discount/readme/DESCRIPTION.md new file mode 100644 index 00000000000..f9539cbb76b --- /dev/null +++ b/sale_order_general_discount/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module allows to set a general discount in a sales order. This +general discount is set to each line order in the standard discount +field. + +You can configure: +- a default general discount on customers +- On each product define if general discount is applied diff --git a/sale_order_general_discount/readme/DESCRIPTION.rst b/sale_order_general_discount/readme/DESCRIPTION.rst deleted file mode 100644 index 88bd66fae3e..00000000000 --- a/sale_order_general_discount/readme/DESCRIPTION.rst +++ /dev/null @@ -1,6 +0,0 @@ -This module allows to set a general discount in a sales order. This general -discount is set to each line order in the standard `discount` field. - -You can configure: - * a default general discount on customers - * On each product define if general discount is applied diff --git a/sale_order_general_discount/readme/INSTALL.rst b/sale_order_general_discount/readme/INSTALL.md similarity index 85% rename from sale_order_general_discount/readme/INSTALL.rst rename to sale_order_general_discount/readme/INSTALL.md index 4da360f7c83..5e1d649b89c 100644 --- a/sale_order_general_discount/readme/INSTALL.rst +++ b/sale_order_general_discount/readme/INSTALL.md @@ -1 +1,2 @@ -You need to install sale_management module for accessing the needed menus. +You need to install sale_management module for accessing the needed +menus. diff --git a/sale_order_general_discount/readme/USAGE.md b/sale_order_general_discount/readme/USAGE.md new file mode 100644 index 00000000000..db909f04a1d --- /dev/null +++ b/sale_order_general_discount/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, you need to: + +1. Create a sale order and set a discount, this discount will be set in + all lines. +2. You can set a discount in a partner. +3. On product you can define if you apply general discount on sale + order line linked to that product diff --git a/sale_order_general_discount/readme/USAGE.rst b/sale_order_general_discount/readme/USAGE.rst deleted file mode 100644 index 2c58d327897..00000000000 --- a/sale_order_general_discount/readme/USAGE.rst +++ /dev/null @@ -1,8 +0,0 @@ -To use this module, you need to: - -#. Create a sale order and set a discount, - this discount will be set in all lines. -#. You can set a discount in a partner. -#. On product you can define if you - apply general discount on sale order line - linked to that product diff --git a/sale_order_general_discount/static/description/index.html b/sale_order_general_discount/static/description/index.html index baa03fd4432..d4b6752256b 100644 --- a/sale_order_general_discount/static/description/index.html +++ b/sale_order_general_discount/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -370,16 +369,14 @@

Sale Order General Discount

!! source digest: sha256:a4eeadfa3e2fc4ad9f54244dc002a32d12938c91207c4f729001730ca727a156 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Production/Stable License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

-

This module allows to set a general discount in a sales order. This general -discount is set to each line order in the standard discount field.

-
-
You can configure:
-
    +

    This module allows to set a general discount in a sales order. This +general discount is set to each line order in the standard discount +field.

    +

    You can configure:

    +
    • a default general discount on customers
    • On each product define if general discount is applied
    -
-

Table of contents

    @@ -396,18 +393,18 @@

    Sale Order General Discount

Installation

-

You need to install sale_management module for accessing the needed menus.

+

You need to install sale_management module for accessing the needed +menus.

Usage

To use this module, you need to:

    -
  1. Create a sale order and set a discount, -this discount will be set in all lines.
  2. +
  3. Create a sale order and set a discount, this discount will be set in +all lines.
  4. You can set a discount in a partner.
  5. -
  6. On product you can define if you -apply general discount on sale order line -linked to that product
  7. +
  8. On product you can define if you apply general discount on sale order +line linked to that product
@@ -441,9 +438,7 @@

Contributors

Maintainers

This module is maintained by the OCA.

- -Odoo Community Association - +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.

diff --git a/sale_order_invoice_amount/README.rst b/sale_order_invoice_amount/README.rst new file mode 100644 index 00000000000..67cb66756f8 --- /dev/null +++ b/sale_order_invoice_amount/README.rst @@ -0,0 +1,81 @@ +========================= +Sale Order Invoice Amount +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:adda86ddd28b95f77e0604ae2d8fcc9e48351fb5567a49001111cf3c6edd5488 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/17.0/sale_order_invoice_amount + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_order_invoice_amount + :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/sale-workflow&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +The purpose of this module is to add two fields in the sale order model: + +- invoiced_amount: total invoiced amount. +- uninvoiced_amount: total uninvoiced amount. + +**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 +------- + +* ForgeFlow + +Contributors +------------ + +- Mateu Griful +- Lois Rilo +- Meritxell Abellan + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_invoice_amount/__init__.py b/sale_order_invoice_amount/__init__.py new file mode 100644 index 00000000000..6d58305f5dd --- /dev/null +++ b/sale_order_invoice_amount/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import pre_init_hook diff --git a/sale_order_invoice_amount/__manifest__.py b/sale_order_invoice_amount/__manifest__.py new file mode 100644 index 00000000000..1aa1623f1ee --- /dev/null +++ b/sale_order_invoice_amount/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright (C) 2021 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +{ + "name": "Sale Order Invoice Amount", + "version": "17.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "category": "Sales", + "license": "LGPL-3", + "summary": "Display the invoiced and uninvoiced total in the sale order", + "depends": [ + "sale", + "account", + ], + "data": [ + "views/sale_order_view.xml", + "views/sale_order_config_settings.xml", + ], + "installable": True, + "pre_init_hook": "pre_init_hook", + "assets": { + "web.assets_backend": [ + "sale_order_invoice_amount/static/src/xml/*", + ], + }, +} diff --git a/sale_order_invoice_amount/hooks.py b/sale_order_invoice_amount/hooks.py new file mode 100644 index 00000000000..399ed541451 --- /dev/null +++ b/sale_order_invoice_amount/hooks.py @@ -0,0 +1,92 @@ +def _add_new_columns(cr): + cr.execute( + """ +ALTER TABLE + sale_order +ADD COLUMN IF NOT EXISTS + invoiced_amount numeric, +ADD COLUMN IF NOT EXISTS + uninvoiced_amount numeric + """ + ) + + +def _update_amounts_for_cancel_invoices(cr): + cr.execute( + """ +UPDATE + sale_order +SET + invoiced_amount = 0.0, + uninvoiced_amount = sale_order.amount_total +WHERE + sale_order.state = 'cancel' + """ + ) + + +def _update_amounts_for_non_cancel_invoices(cr): + cr.execute( + """ +WITH amt AS( + SELECT + sale_order_id, + COALESCE(SUM(amount_total_in_currency_signed), 0) AS invoiced_amount, + CASE + WHEN SUM(amount_total_in_currency_signed) IS NULL + THEN amount_total + WHEN amount_total - SUM( + amount_total_in_currency_signed + ) > 0.0 THEN amount_total - SUM( + amount_total_in_currency_signed) + ELSE 0.0 + END AS uninvoiced_amount + FROM ( + SELECT DISTINCT + sale_order.id AS sale_order_id, + sale_order.amount_total AS amount_total, + account_move.id AS account_move_id, + account_move.amount_total_in_currency_signed + as amount_total_in_currency_signed + FROM + sale_order + LEFT JOIN sale_order_line + ON sale_order_line.order_id = sale_order.id + LEFT JOIN sale_order_line_invoice_rel + ON sale_order_line_invoice_rel.order_line_id = sale_order_line.id + LEFT JOIN account_move_line + ON sale_order_line_invoice_rel.invoice_line_id = account_move_line.id + LEFT JOIN account_move + ON account_move_line.move_id = account_move.id + WHERE + sale_order.state != 'cancel' + AND ( + account_move IS NULL + OR ( + account_move.move_type IN ('out_invoice', 'out_refund') + AND account_move.state != 'cancel' + ) + ) + ) AS distinct_account_move + GROUP BY sale_order_id, amount_total +) +UPDATE sale_order + SET invoiced_amount = amt.invoiced_amount, + uninvoiced_amount = amt.uninvoiced_amount +FROM amt +WHERE sale_order.id = amt.sale_order_id + """ + ) + + +def _update_amounts(cr): + _update_amounts_for_cancel_invoices(cr) + _update_amounts_for_non_cancel_invoices(cr) + + +def pre_init_hook(env): + """ + Add columns to avoid Memory error on an existing Odoo instance with lots of data + """ + _add_new_columns(env.cr) + _update_amounts(env.cr) diff --git a/sale_order_invoice_amount/i18n/es.po b/sale_order_invoice_amount/i18n/es.po new file mode 100644 index 00000000000..3558c1f4522 --- /dev/null +++ b/sale_order_invoice_amount/i18n/es.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_invoice_amount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__invoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Invoiced Amount" +msgstr "Importe facturado" + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__invoiced_amount +msgid "Order amount already invoiced." +msgstr "Importe del pedido ya facturado." + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +msgid "Order amount to be invoiced" +msgstr "Importe del pedido pendiente de facturar" + +#. module: sale_order_invoice_amount +#: model:ir.model,name:sale_order_invoice_amount.model_sale_order +msgid "Sales Order" +msgstr "Pedidos de venta" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Uninvoiced Amount" +msgstr "Importe no facturado" diff --git a/sale_order_invoice_amount/i18n/fr.po b/sale_order_invoice_amount/i18n/fr.po new file mode 100644 index 00000000000..a6a4af8753a --- /dev/null +++ b/sale_order_invoice_amount/i18n/fr.po @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_invoice_amount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-28 13:16+0000\n" +"Last-Translator: Nicolas JEUDY \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" +"X-Generator: Weblate 4.17\n" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__invoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Invoiced Amount" +msgstr "Montant facturé" + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__invoiced_amount +msgid "Order amount already invoiced." +msgstr "Montant de commande déjà facturé." + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +msgid "Order amount to be invoiced" +msgstr "Montant de commande à facturer" + +#. module: sale_order_invoice_amount +#: model:ir.model,name:sale_order_invoice_amount.model_sale_order +msgid "Sales Order" +msgstr "Bon de commande" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Uninvoiced Amount" +msgstr "Montant à facturer" diff --git a/sale_order_invoice_amount/i18n/it.po b/sale_order_invoice_amount/i18n/it.po new file mode 100644 index 00000000000..75ee2256b79 --- /dev/null +++ b/sale_order_invoice_amount/i18n/it.po @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_invoice_amount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-04 09:34+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 4.17\n" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__invoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Invoiced Amount" +msgstr "Importo fatturato" + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__invoiced_amount +msgid "Order amount already invoiced." +msgstr "Importo ordine già fatturato." + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +msgid "Order amount to be invoiced" +msgstr "Importo ordine da fatturare" + +#. module: sale_order_invoice_amount +#: model:ir.model,name:sale_order_invoice_amount.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Uninvoiced Amount" +msgstr "Importo non fatturato" diff --git a/sale_order_invoice_amount/i18n/sale_order_invoice_amount.pot b/sale_order_invoice_amount/i18n/sale_order_invoice_amount.pot new file mode 100644 index 00000000000..b97f75a6e4f --- /dev/null +++ b/sale_order_invoice_amount/i18n/sale_order_invoice_amount.pot @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_invoice_amount +# +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: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__invoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Invoiced Amount" +msgstr "" + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__invoiced_amount +msgid "Order amount already invoiced." +msgstr "" + +#. module: sale_order_invoice_amount +#: model:ir.model.fields,help:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +msgid "Order amount to be invoiced" +msgstr "" + +#. module: sale_order_invoice_amount +#: model:ir.model,name:sale_order_invoice_amount.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_order_invoice_amount +#. odoo-javascript +#: code:addons/sale_order_invoice_amount/static/src/xml/tax_totals.xml:0 +#: model:ir.model.fields,field_description:sale_order_invoice_amount.field_sale_order__uninvoiced_amount +#: model_terms:ir.ui.view,arch_db:sale_order_invoice_amount.view_order_tree_invoiced_amount +#, python-format +msgid "Uninvoiced Amount" +msgstr "" diff --git a/sale_order_invoice_amount/models/__init__.py b/sale_order_invoice_amount/models/__init__.py new file mode 100644 index 00000000000..89c66973653 --- /dev/null +++ b/sale_order_invoice_amount/models/__init__.py @@ -0,0 +1,3 @@ +from . import sale_order +from . import sale_order_config_settings +from . import res_company diff --git a/sale_order_invoice_amount/models/res_company.py b/sale_order_invoice_amount/models/res_company.py new file mode 100644 index 00000000000..b81fd2b9969 --- /dev/null +++ b/sale_order_invoice_amount/models/res_company.py @@ -0,0 +1,14 @@ +# Copyright 2025 ForgeFlow S.L. (http://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + enable_amount_invoiced_based_on_quantity = fields.Boolean( + string="Enable computing amount invoiced based on quantity", + implied_group="sale_order.enable_amount_invoiced_based_on_quantity", + default=False, + ) diff --git a/sale_order_invoice_amount/models/sale_order.py b/sale_order_invoice_amount/models/sale_order.py new file mode 100644 index 00000000000..d9dd04ea4a4 --- /dev/null +++ b/sale_order_invoice_amount/models/sale_order.py @@ -0,0 +1,104 @@ +# Copyright (C) 2021 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from odoo import api, fields, models +from odoo.tools.misc import formatLang + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + amount_invoiced = fields.Monetary( + compute="_compute_amount_invoiced", + store=True, + help="Order amount already invoiced.", + ) + + amount_to_invoice = fields.Monetary( + compute="_compute_amount_to_invoice", + store=True, + help="Order amount to be invoiced", + ) + + @api.depends( + "state", + "invoice_ids", + "invoice_ids.amount_total_in_currency_signed", + "amount_total", + "invoice_ids.state", + ) + def _compute_amount_invoiced(self): + if not self.env.company.enable_amount_invoiced_based_on_quantity: + return super()._compute_amount_invoiced() + else: + for rec in self: + if rec.state != "cancel" and rec.invoice_ids: + rec.amount_invoiced = 0.0 + for invoice in rec.invoice_ids: + if invoice.state != "cancel": + invoices = rec.invoice_ids.filtered( + lambda x: x.state == "posted" + ) + if ( + invoice.currency_id != rec.currency_id + and rec.currency_id != invoice.company_currency_id + ): + rec.amount_invoiced += ( + invoices._get_sale_order_invoiced_amount(rec) + ) + else: + rec.amount_invoiced += invoice.amount_total_signed + else: + rec.amount_invoiced = 0.0 + + # Amount to invoice could not be equal to total - amount invoiced. + # For example if the amount invoiced does not match with the price unit. + @api.depends("invoice_ids.state") + def _compute_amount_to_invoice(self): + if not self.env.company.enable_amount_invoiced_based_on_quantity: + return super()._compute_amount_to_invoice() + else: + for rec in self: + if rec.state in ["draft", "sent", "cancel"]: + rec.amount_to_invoice = 0.0 + else: + rec.amount_to_invoice = max( + 0, + sum( + (line.product_uom_qty - line.qty_invoiced) + * (line.price_total / line.product_uom_qty) + for line in rec.order_line.filtered( + lambda sl: sl.product_uom_qty > 0 + ) + ), + ) + + @api.depends( + "order_line.tax_id", + "order_line.price_unit", + "amount_total", + "amount_untaxed", + "state", + "invoice_ids", + "invoice_ids.amount_total_in_currency_signed", + "amount_total", + "invoice_ids.state", + ) + def _compute_tax_totals(self): + res = super()._compute_tax_totals() + for order in self: + lang_env = order.with_context(lang=order.partner_id.lang).env + order.tax_totals.update( + { + "amount_invoiced": order.amount_invoiced, + "formatted_amount_invoiced": formatLang( + lang_env, order.amount_invoiced, currency_obj=order.currency_id + ), + "amount_to_invoice": order.amount_to_invoice, + "formatted_amount_to_invoice": formatLang( + lang_env, + order.amount_to_invoice, + currency_obj=order.currency_id, + ), + } + ) + return res diff --git a/sale_order_invoice_amount/models/sale_order_config_settings.py b/sale_order_invoice_amount/models/sale_order_config_settings.py new file mode 100644 index 00000000000..1915df0bf86 --- /dev/null +++ b/sale_order_invoice_amount/models/sale_order_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2025 ForgeFlow S.L. (http://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import fields, models + + +class SaleConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + enable_amount_invoiced_based_on_quantity = fields.Boolean( + related="company_id.enable_amount_invoiced_based_on_quantity", + readonly=False, + ) diff --git a/sale_order_invoice_amount/pyproject.toml b/sale_order_invoice_amount/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_order_invoice_amount/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_order_invoice_amount/readme/CONTRIBUTORS.md b/sale_order_invoice_amount/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..ec3dfeec24a --- /dev/null +++ b/sale_order_invoice_amount/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Mateu Griful \<\> +- Lois Rilo \<\> diff --git a/sale_order_invoice_amount/readme/DESCRIPTION.md b/sale_order_invoice_amount/readme/DESCRIPTION.md new file mode 100644 index 00000000000..944ec1733d1 --- /dev/null +++ b/sale_order_invoice_amount/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +The purpose of this module is to add two fields in the sale order model: + +- invoiced_amount: total invoiced amount. +- uninvoiced_amount: total uninvoiced amount. diff --git a/sale_order_invoice_amount/static/description/icon.png b/sale_order_invoice_amount/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_order_invoice_amount/static/description/icon.png differ diff --git a/sale_order_invoice_amount/static/description/index.html b/sale_order_invoice_amount/static/description/index.html new file mode 100644 index 00000000000..8b6869d90ab --- /dev/null +++ b/sale_order_invoice_amount/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +Sale Order Invoice Amount + + + +
+

Sale Order Invoice Amount

+ + +

Beta License: LGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

The purpose of this module is to add two fields in the sale order model:

+
    +
  • invoiced_amount: total invoiced amount.
  • +
  • uninvoiced_amount: total uninvoiced amount.
  • +
+

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

+
    +
  • ForgeFlow
  • +
+
+ +
+

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/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_order_invoice_amount/static/src/xml/tax_totals.xml b/sale_order_invoice_amount/static/src/xml/tax_totals.xml new file mode 100644 index 00000000000..ed40a34d20b --- /dev/null +++ b/sale_order_invoice_amount/static/src/xml/tax_totals.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sale_order_invoice_amount/tests/__init__.py b/sale_order_invoice_amount/tests/__init__.py new file mode 100644 index 00000000000..15963146727 --- /dev/null +++ b/sale_order_invoice_amount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order_invoice_amount diff --git a/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py b/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py new file mode 100644 index 00000000000..51d1f42293f --- /dev/null +++ b/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py @@ -0,0 +1,513 @@ +# Copyright (C) 2021 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import fields +from odoo.tests import common, tagged + + +@tagged("post_install", "-at_install") +class TestSaleOrderInvoiceAmount(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + # Partners + partner_model = cls.env["res.partner"] + cls.res_partner_1 = partner_model.create({"name": "Wood Corner"}) + cls.env.company.write( + { + "enable_amount_invoiced_based_on_quantity": True, + } + ) + cls.res_partner_address_1 = partner_model.create( + {"name": "Willie Burke", "parent_id": cls.res_partner_1.id} + ) + cls.res_partner_2 = partner_model.create({"name": "Partner 12"}) + # Products + product_model = cls.env["product.product"] + cls.product_1 = product_model.create( + {"name": "Desk Combination", "type": "consu"} + ) + cls.product_2 = product_model.create( + {"name": "Conference Chair", "type": "consu"} + ) + cls.product_3 = product_model.create( + {"name": "Repair Services", "type": "service"} + ) + cls.currency_eur = cls.env.ref("base.EUR") + cls.currency_eur.active = True + cls.currency_cad = cls.env.ref("base.CAD") + cls.currency_cad.active = True + cls.env["res.currency.rate"].search( + [("currency_id", "in", [cls.currency_eur.id, cls.currency_cad.id])] + ).unlink() + cls.env["res.currency.rate"].create( + [ + { + "name": fields.Date.from_string("2024-01-01"), + "rate": 1.500000, # Fixing the rate for test support. + "currency_id": cls.currency_eur.id, + }, + { + "name": fields.Date.from_string("2024-01-01"), + "rate": 2.00000, # Fixing the rate for test support. + "currency_id": cls.currency_cad.id, + }, + ] + ) + cls.res_partner_2 = cls.env["res.partner"].create({"name": "Partner 12"}) + # Sale Order + cls.tax = cls.env["account.tax"].create( + {"name": "Tax 15", "type_tax_use": "sale", "amount": 21} + ) + cls.sale_order_1 = cls.env["sale.order"].create( + {"partner_id": cls.res_partner_1.id} + ) + sale_order_line_model = cls.env["sale.order.line"] + cls.order_line_1 = sale_order_line_model.create( + { + "order_id": cls.sale_order_1.id, + "product_id": cls.product_1.id, + "product_uom": cls.product_1.uom_id.id, + "product_uom_qty": 10.0, + "price_unit": 10.0, + "tax_id": cls.tax, + } + ) + cls.order_line_2 = sale_order_line_model.create( + { + "order_id": cls.sale_order_1.id, + "product_id": cls.product_2.id, + "product_uom": cls.product_2.uom_id.id, + "product_uom_qty": 25.0, + "price_unit": 4.0, + "tax_id": cls.tax, + } + ) + cls.order_line_3 = sale_order_line_model.create( + { + "order_id": cls.sale_order_1.id, + "product_id": cls.product_3.id, + "product_uom": cls.product_3.uom_id.id, + "product_uom_qty": 20.0, + "price_unit": 5.0, + "tax_id": cls.tax, + } + ) + + def test_01_sale_order_invoiced_amount(self): + self.assertEqual( + self.sale_order_1.amount_invoiced, + 0.0, + "Invoiced Amount should be 0.0", + ) + + self.sale_order_1.action_confirm() + aml1 = self.order_line_1._prepare_invoice_line() + aml2 = self.order_line_2._prepare_invoice_line() + test_invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ], + } + ) + test_invoice.action_post() + self.assertEqual( + self.sale_order_1.amount_invoiced, + 242.0, + "Invoiced Amount should be 211.75", + ) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 121.0, + "Uninvoiced Amount should be 181.5, as the lines keep uninvoiced.", + ) + test_invoice.button_cancel() + self.sale_order_1._create_invoices(final=True) + self.assertEqual( + self.sale_order_1.amount_invoiced, + 363.0, + "Invoiced Amount should be calculated.", + ) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 0.00, + "Uninvoiced Amount should be calculated.", + ) + tax_totals = self.sale_order_1.tax_totals + self.assertEqual( + tax_totals["amount_invoiced"], + 363.0, + ) + self.assertEqual( + tax_totals["amount_to_invoice"], + 0.00, + ) + self.assertEqual( + tax_totals["formatted_amount_invoiced"], + "$\xa0363.00", + ) + self.assertEqual( + tax_totals["formatted_amount_to_invoice"], + "$\xa00.00", + ) + + def test_02_sale_order_invoiced_amount_different_currencies_invoice(self): + self.assertEqual( + self.sale_order_1.amount_invoiced, + 0.0, + "Invoiced Amount should be 0.0", + ) + self.sale_order_1.action_confirm() + + price_foreign_currency_1 = self.sale_order_1.currency_id._convert( + 10.0, + self.currency_eur, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + price_foreign_currency_2 = self.sale_order_1.currency_id._convert( + 4.0, + self.currency_eur, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + aml1 = self.order_line_1._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_1, + "currency_id": self.currency_eur.id, + } + ) + aml2 = self.order_line_2._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_2, + "currency_id": self.currency_eur.id, + } + ) + test_invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ], + "currency_id": self.currency_eur.id, + } + ) + test_invoice.action_post() + self.assertAlmostEqual( + self.sale_order_1.amount_invoiced, + 242.0, + delta=1, + ) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 121.0, + "Uninvoiced Amount should be 121, as the lines keep uninvoiced.", + ) + test_invoice.button_cancel() + self.sale_order_1._create_invoices(final=True) + self.assertEqual( + self.sale_order_1.amount_invoiced, + 363.0, + "Invoiced Amount should be calculated.", + ) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 0.0, + "Uninvoiced Amount should be calculated.", + ) + + def test_03_sale_order_invoiced_amount_different_currencies_sale(self): + self.currency_cad.active = True + self.sale_order_1 = self.env["sale.order"].create( + {"partner_id": self.res_partner_1.id, "currency_id": self.currency_eur.id} + ) + self.order_line_1 = self.env["sale.order.line"].create( + { + "order_id": self.sale_order_1.id, + "product_id": self.product_1.id, + "product_uom": self.product_1.uom_id.id, + "product_uom_qty": 10.0, + "price_unit": 10.0, + "tax_id": self.tax, + "currency_id": self.currency_eur.id, + } + ) + self.order_line_2 = self.env["sale.order.line"].create( + { + "order_id": self.sale_order_1.id, + "product_id": self.product_2.id, + "product_uom": self.product_2.uom_id.id, + "product_uom_qty": 25.0, + "price_unit": 4.0, + "tax_id": self.tax, + "currency_id": self.currency_eur.id, + } + ) + self.order_line_3 = self.env["sale.order.line"].create( + { + "order_id": self.sale_order_1.id, + "product_id": self.product_3.id, + "product_uom": self.product_3.uom_id.id, + "product_uom_qty": 20.0, + "price_unit": 5.0, + "tax_id": self.tax, + "currency_id": self.currency_eur.id, + } + ) + + self.assertEqual( + self.sale_order_1.amount_invoiced, + 0.0, + "Invoiced Amount should be 0.0", + ) + self.sale_order_1.action_confirm() + self.sale_order_1.currency_id = self.currency_eur + price_foreign_currency_1 = self.sale_order_1.currency_id._convert( + 10.0, + self.currency_cad, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + price_foreign_currency_2 = self.sale_order_1.currency_id._convert( + 4.0, + self.currency_cad, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + aml1 = self.order_line_1._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_1, + "currency_id": self.currency_cad.id, + } + ) + aml2 = self.order_line_2._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_2, + "currency_id": self.currency_cad.id, + } + ) + test_invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ], + "currency_id": self.currency_cad.id, + } + ) + test_invoice.action_post() + self.assertAlmostEqual(self.sale_order_1.amount_invoiced, 242.0, delta=0.2) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 121.0, + "Uninvoiced Amount should be 121, as the lines keep uninvoiced.", + ) + test_invoice.button_cancel() + price_foreign_currency_1 = self.sale_order_1.currency_id._convert( + 10.0, + self.currency_cad, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + price_foreign_currency_2 = self.sale_order_1.currency_id._convert( + 4.0, + self.currency_cad, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + price_foreign_currency_3 = self.sale_order_1.currency_id._convert( + 5.0, + self.currency_cad, + self.sale_order_1.company_id, + fields.Date.from_string("2024-01-01"), + ) + aml1 = self.order_line_1._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_1, + "currency_id": self.currency_cad.id, + } + ) + aml2 = self.order_line_2._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_2, + "currency_id": self.currency_cad.id, + } + ) + aml3 = self.order_line_3._prepare_invoice_line( + **{ + "price_unit": price_foreign_currency_3, + "currency_id": self.currency_cad.id, + } + ) + test_invoice = self.env["account.move"].create( + [ + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ( + 0, + 0, + aml3, + ), + ], + "currency_id": self.currency_cad.id, + } + ] + ) + test_invoice.action_post() + self.assertAlmostEqual(self.sale_order_1.amount_invoiced, 363.0, delta=0.2) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 0.0, + "Uninvoiced Amount should be calculated.", + ) + + def test_04_sale_order_invoiced_amount_different_price_deactivated(self): + self.env.company.write( + { + "enable_amount_invoiced_based_on_quantity": False, + } + ) + self.assertEqual( + self.sale_order_1.amount_invoiced, + 0.0, + "Invoiced Amount should be 0.0", + ) + + self.sale_order_1.action_confirm() + aml1 = self.order_line_1._prepare_invoice_line() + aml1["price_unit"] = 15.0 + aml1["quantity"] = 5.0 + aml2 = self.order_line_2._prepare_invoice_line() + test_invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ], + } + ) + test_invoice.action_post() + self.assertEqual( + self.sale_order_1.amount_invoiced, + 211.75, + "Invoiced Amount should be 211.75", + ) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 151.25, + "Uninvoiced Amount should be 121, as the lines keep uninvoiced.", + ) + + def test_05_sale_order_invoiced_amount_different_price_activated(self): + self.env.company.write( + { + "enable_amount_invoiced_based_on_quantity": True, + } + ) + self.assertEqual( + self.sale_order_1.amount_invoiced, + 0.0, + "Invoiced Amount should be 0.0", + ) + + self.sale_order_1.action_confirm() + aml1 = self.order_line_1._prepare_invoice_line() + aml1["price_unit"] = 15.0 + aml1["quantity"] = 5.0 + aml2 = self.order_line_2._prepare_invoice_line() + test_invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ], + } + ) + test_invoice.action_post() + self.assertEqual( + self.sale_order_1.amount_invoiced, + 211.75, + "Invoiced Amount should be 211.75", + ) + self.assertEqual( + self.sale_order_1.amount_to_invoice, + 181.5, + "Uninvoiced Amount should be 181.5, as the lines keep uninvoiced.", + ) diff --git a/sale_order_invoice_amount/views/sale_order_config_settings.xml b/sale_order_invoice_amount/views/sale_order_config_settings.xml new file mode 100644 index 00000000000..dc3140fdaff --- /dev/null +++ b/sale_order_invoice_amount/views/sale_order_config_settings.xml @@ -0,0 +1,22 @@ + + + + + res.config.settings.form - sale_order_invoice_amount + res.config.settings + + + + + + + + + + diff --git a/sale_order_invoice_amount/views/sale_order_view.xml b/sale_order_invoice_amount/views/sale_order_view.xml new file mode 100644 index 00000000000..ae869262b00 --- /dev/null +++ b/sale_order_invoice_amount/views/sale_order_view.xml @@ -0,0 +1,24 @@ + + + + sale.order.form.invoiced.amount + sale.order + + + + + + + + + + sale.order.tree.amount_invoiced + sale.order + + + + + + + +