Skip to content

Commit

Permalink
[FIX] account_receipt_sale: Receipt refunds have negative quantities
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTakobi committed Mar 28, 2023
1 parent 8a53cf7 commit 456f257
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions account_receipt_sale/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import models
from . import wizard
from odoo import api, SUPERUSER_ID
from openupgradelib import openupgrade


Expand Down Expand Up @@ -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.
Expand All @@ -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)
2 changes: 1 addition & 1 deletion account_receipt_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions account_receipt_sale/migrations/14.0.1.0.1/post-migrate.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 456f257

Please sign in to comment.