Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0] [MIG] sale_order_invoice_amount: Migration to 17.0 #3332

Open
wants to merge 18 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added pandoc-3.4-1-amd64.deb
Binary file not shown.
80 changes: 80 additions & 0 deletions sale_order_invoice_amount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
=========================
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 <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_invoice_amount%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* ForgeFlow

Contributors
------------

- Mateu Griful <[email protected]>
- Lois Rilo <[email protected]>

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 <https://github.com/OCA/sale-workflow/tree/17.0/sale_order_invoice_amount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions sale_order_invoice_amount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
26 changes: 26 additions & 0 deletions sale_order_invoice_amount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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",
],
"installable": True,
"pre_init_hook": "pre_init_hook",
"assets": {
"web.assets_backend": [
"sale_order_invoice_amount/static/src/xml/*",
],
},
}
92 changes: 92 additions & 0 deletions sale_order_invoice_amount/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
def _add_new_columns(env):
env.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(env):
env.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(env):
env.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(env):
_update_amounts_for_cancel_invoices(env)
_update_amounts_for_non_cancel_invoices(env)


def pre_init_hook(env):
"""
Add columns to avoid Memory error on an existing Odoo instance with lots of data
"""
_add_new_columns(env)
_update_amounts(env)
48 changes: 48 additions & 0 deletions sale_order_invoice_amount/i18n/es.po
Original file line number Diff line number Diff line change
@@ -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"
50 changes: 50 additions & 0 deletions sale_order_invoice_amount/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>\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"
50 changes: 50 additions & 0 deletions sale_order_invoice_amount/i18n/it.po
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>\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"
Loading
Loading