[OU-FIX] account_payment_partner: Fill payment mode on lines for draft/cancel invoices

If you have some draft or cancel invoices on v12, the account process
generates journal items for them, and no payment_mode is populated on
them, so we run an SQL for filling it when such incoherence is found.

It also serves for other missing payment mode filling (if any) according
to the compute method, trasposed to SQL.

TT34717
This commit is contained in:
Pedro M. Baeza
2022-02-21 21:39:04 +01:00
parent 4347c9f785
commit e950bdf0ce

View File

@@ -14,3 +14,16 @@ def migrate(env, version):
FROM account_invoice ai
WHERE ai.id = am.old_invoice_id""",
)
# Fill new move lines created from draft/cancel invoices in account module with the
# proper payment mode following the logic in the compute method
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move_line aml
SET payment_mode_id = am.payment_mode_id
FROM account_move am
WHERE am.id = aml.move_id
AND am.type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund')
AND aml.account_internal_type in ('receivable', 'payable')
AND aml.payment_mode_id IS NULL AND am.payment_mode_id IS NOT NULL""",
)