diff --git a/account_receipt_sale/__init__.py b/account_receipt_sale/__init__.py index 6ea70b9312f..12330845cf7 100644 --- a/account_receipt_sale/__init__.py +++ b/account_receipt_sale/__init__.py @@ -1,5 +1,6 @@ from . import models from . import wizard +from odoo import api, SUPERUSER_ID from openupgradelib import openupgrade @@ -48,6 +49,20 @@ def rename_old_italian_module(cr): ) +def invert_receipt_refund_quantity(env): + """Receipt Refunds are the same as normal Receipts + but with inverted Quantities.""" + refund_receipts = env["account.move"].search( + [ + ("move_type", "in", ["out_receipt", "in_receipt"]), + ("amount_total_signed", "<", 0), + ] + ) + refund_receipts_lines = refund_receipts.mapped("invoice_line_ids") + for refund_receipts_line in refund_receipts_lines: + refund_receipts_line.quantity = -refund_receipts_line.quantity + + def migrate_corrispettivi_data(cr, registry): """ Populate the new columns with data from corrispettivi modules. @@ -73,3 +88,7 @@ def migrate_corrispettivi_data(cr, registry): "SET use_receipts = true " "WHERE use_corrispettivi = true", ) + + with api.Environment.manage(): + env = api.Environment(cr, SUPERUSER_ID, {}) + invert_receipt_refund_quantity(env) diff --git a/account_receipt_sale/__manifest__.py b/account_receipt_sale/__manifest__.py index 8584641f57c..f4604a908dd 100644 --- a/account_receipt_sale/__manifest__.py +++ b/account_receipt_sale/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Receipts from sales", "summary": "Generate receipts from sale orders", - "version": "14.0.1.0.0", + "version": "14.0.1.0.1", "development_status": "Beta", "category": "Sales/Sales", "website": "https://github.com/OCA/account-invoicing", diff --git a/account_receipt_sale/migrations/14.0.1.0.1/post-migrate.py b/account_receipt_sale/migrations/14.0.1.0.1/post-migrate.py new file mode 100644 index 00000000000..46ddf848562 --- /dev/null +++ b/account_receipt_sale/migrations/14.0.1.0.1/post-migrate.py @@ -0,0 +1,11 @@ +# Copyright 2023 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + +from odoo.addons.account_receipt_sale import invert_receipt_refund_quantity + + +@openupgrade.migrate() +def migrate(env, version): + invert_receipt_refund_quantity(env)