Skip to content

Commit

Permalink
REF invert_receipt_refund_quantity using SQL because using ORM implie…
Browse files Browse the repository at this point in the history
…s dangerous recomputations
  • Loading branch information
eLBati committed Mar 31, 2023
1 parent 92f735b commit 05b1ff0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions account_receipt_sale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ 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),
]
openupgrade.logged_query(
env.cr,
"UPDATE account_move_line l "
"SET quantity = -quantity "
"FROM account_move m "
"WHERE m.id = l.move_id "
"AND m.move_type IN ('out_receipt', 'in_receipt') "
"AND m.amount_total_signed < 0 "
"AND l.exclude_from_invoice_tab = false "
"AND (l.display_type NOT IN ('line_section', 'line_note') "
" OR display_type IS NULL) "
"AND l.quantity > 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):
Expand Down

0 comments on commit 05b1ff0

Please sign in to comment.