diff --git a/aeat.py b/aeat.py index b81fcb5..57940b5 100644 --- a/aeat.py +++ b/aeat.py @@ -437,6 +437,8 @@ class SIIReport(Workflow, ModelSQL, ModelView): ReportLine = pool.get('aeat.sii.report.lines') for report in reports: + if report.lines: + continue domain = [ ('sii_book_key', '=', report.book), ('move.period', '=', report.period.id), @@ -444,10 +446,11 @@ class SIIReport(Workflow, ModelSQL, ModelView): ] if report.operation_type == 'A0': - domain.append(('sii_state', '=', None)) + domain.append(('sii_state', 'in', [None, 'Incorrecto'])) + elif report.operation_type in ('A1', 'A4'): domain.append(('sii_state', 'in', [ - 'ACEPTADOCONERRORES', 'INCORRECTO'])) + 'AceptadoConErrores', 'AceptadaConErrores'])) _logger.debug('Searching invoices for SII report: %s', domain) invoices = Invoice.search(domain) diff --git a/invoice.py b/invoice.py index 1d8741a..df340db 100644 --- a/invoice.py +++ b/invoice.py @@ -83,14 +83,26 @@ class Invoice: invoices.append(invoice) lines.append(id_) - if clause[-1] == None: - return [('id', 'not in', invoices)] + is_none = False + c = clause[-1] + if isinstance(clause[-1], list): + if None in clause[-1]: + is_none = True + c.remove(None) + + c0 = [] + if clause[-1] == None or is_none: + c0 = [('id', 'not in', invoices)] clause2 = [tuple(('state',)) + tuple(clause[1:])] + \ - [('id', 'in', lines)] + [('id', 'in', lines)] res_lines = SIILines.search(clause2) - return [('id', 'in', [x.invoice.id for x in res_lines])] + + if is_none: + return ['OR', c0, [('id', 'in', [x.invoice.id for x in res_lines])]] + else: + return [('id', 'in', [x.invoice.id for x in res_lines])] @classmethod def get_sii_state(cls, invoices, names):