odoo/odoo#209394

Created by fw-bot
Merged at 0b4da70f684194d6c19b4fbea4ea993e8e78dd92

Statuses:

label
odoo-dev:saas-18.3-16.0-l10n_sa_edi-fix-zatca-posting-with-reversed-downpayment-loug-435155-fw
head
01b55b0bd728398f69c0bea735a807dfd903cc93
merged
1 month ago by Training, Louis Gobert (loug)
odoo/odoo
16.0 #201322
17.0 #208069
saas-17.4 #208259
18.0 #208325
saas-18.1 #208333
saas-18.2 #209391
saas-18.3 #209394
master #209398

[FW][FIX] l10n_sa_edi: fix ZATCA posting with reversed downpayment

An error occurs when trying to send a reversed invoice to ZATCA if it included a downpayment that was also reversed.

Steps to reproduce:
- Install "Sales" and "Saudi Arabia - E-invoicing" apps.
- Create a quotation and confirm it.
- Create a downpayment and post it to ZATCA.
- Create an invoice A including the downpayment and post it.
- Reverse the downpayment and post it to ZATCA.
- Reverse invoice A and try posting it to ZATCA.

An error will occur:

File ".../l10n_sa_edi/models/account_edi_xml_ubl_21_zatca.py", line 356, in _l10n_sa_get_line_prepayment_vals
    'prepayment_id': prepayment_move_id.name,
                     ^^^^^^^^^^^^^^^^^^^^^^^
File ".../odoo/fields.py", line 1154, in __get__
    record.ensure_one()
File ".../odoo/models.py", line 5204, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: account.move(190098, 190096)

This fix ensures that only the actual downpayment move is used by filtering on the move type.

opw-4567756

Forward-Port-Of: #208259
Forward-Port-Of: #201322