changeset 0a742f78ab11 in modules/account_es:default details: https://hg.tryton.org/modules/account_es?cmd=changeset&node=0a742f78ab11 description: Do not ignore invoice cancelled by a credit note
issue10030 review348231002 diffstat: reporting_tax.py | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diffs (57 lines): diff -r 5d09b0c25145 -r 0a742f78ab11 reporting_tax.py --- a/reporting_tax.py Mon Apr 19 16:39:09 2021 +0200 +++ b/reporting_tax.py Thu Apr 29 11:20:15 2021 +0200 @@ -433,6 +433,7 @@ invoice = Invoice.__table__() cancel_invoice = Invoice.__table__() move = Move.__table__() + cancel_move = Move.__table__() line = Line.__table__() tax_line = TaxLine.__table__() tax = Tax.__table__() @@ -451,16 +452,18 @@ where=tax_code.aeat_report.in_(cls.excluded_tax_codes()))) where = ((invoice.company == context.get('company')) - & (invoice.state.in_(['posted', 'paid'])) & (tax.es_vat_list_code != Null) & (Extract('year', invoice.invoice_date) == context.get('date', Date.today()).year) # Exclude base amount for es_reported_with taxes because it is # already included in the base of main tax & ((tax.es_reported_with == Null) | (tax_line.type == 'tax')) - & ~Exists(cancel_invoice.select( - cancel_invoice.cancel_move, distinct=True, - where=(cancel_invoice.cancel_move == invoice.move))) + & ~Exists(cancel_invoice + .join(cancel_move, + condition=cancel_invoice.cancel_move == cancel_move.id) + .select(cancel_invoice.id, distinct=True, + where=((cancel_invoice.id == invoice.id) + & (~cancel_move.origin.like('account.invoice,%'))))) # Use exists to exclude the full invoice when it has multiple taxes & ~Exists(exclude_invoice_tax.select( exclude_invoice_tax.invoice, @@ -815,7 +818,9 @@ context = Transaction().context company = Company.__table__() invoice = Invoice.__table__() + cancel_invoice = Invoice.__table__() move = Move.__table__() + cancel_move = Move.__table__() line = Line.__table__() tax_line = TaxLine.__table__() period = Period.__table__() @@ -824,6 +829,12 @@ where = ((invoice.company == context.get('company')) & (period.fiscalyear == context.get('fiscalyear')) & ~tax.es_exclude_from_vat_book) + where &= ~Exists(cancel_invoice + .join(cancel_move, + condition=cancel_invoice.cancel_move == cancel_move.id) + .select(cancel_invoice.id, distinct=True, + where=((cancel_invoice.id == invoice.id) + & (~cancel_move.origin.like('account.invoice,%'))))) groups = cls.included_tax_groups() if groups: where &= tax.group.in_(groups)