Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions account_invoice_transmit_peppol/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
class AccountMove(models.Model):
_inherit = "account.move"

def _is_transmissible_by_peppol(self):
"""Check if the invoice can be sent by peppol"""
self.ensure_one()
if self.transmit_method_code != "peppol":
return False
if self.invoice_exported and not self.invoice_export_confirmed:
# Already sent but confirmation not yet synced
return False
return not self.invoice_export_confirmed

def _batch_transmit_invoice_by_peppol(self):
"""Mass sending by peppol

Expand All @@ -18,20 +28,27 @@ def _batch_transmit_invoice_by_peppol(self):
"""
result = []
for invoice in self:
description = _(
"Generating invoice for peppol sending: %(name)s",
name=invoice.display_name,
)
invoice.with_delay(
description=description,
identity_key=identity_exact,
priority=40,
channel="root.invoice_transmit.peppol",
)._transmit_invoice_by_peppol()
if not invoice._is_transmissible_by_peppol():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe generate a first job calling


to update invoice_export_confirmed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a delayable method on the invoice itself to check its status...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds a good idea if invoice_export is True. That would be a limited number of case

description = _(
"Invoice already sent to peppol: %(name)s",
name=invoice.name,
)
else:
description = _(
"Generating invoice for peppol sending: %(name)s",
name=invoice.name,
)
invoice.with_delay(
description=description,
identity_key=identity_exact,
priority=40,
channel="root.invoice_transmit.peppol",
)._transmit_invoice_by_peppol()
result.append(description)
return "\n".join(result)
Comment on lines 21 to 48

@lmignon lmignon May 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pattern I like and implement now in my code is to create a method returning a delayable receiving job_options as arguments and call delay on the delayable returned by the method. In this way, it can be extended to change or fine tune the job_options according to a specific project need...

Suggested change
def _batch_transmit_invoice_by_peppol(self):
"""Mass sending by peppol
"""
for invoice in self:
if not invoice._is_transmissible_by_peppol():
description = _(
"Invoice already sent to peppol: %(name)s",
name=invoice.name,
)
else:
description = _(
"Generating invoice for peppol sending: %(name)s",
name=invoice.name,
)
invoice._enqueue_transmit_invoice_by_peppol(description=description).delay()
result.append(description)
return "\n".join(result)
def _enqueue_transmit_invoice_by_peppol(self, **job_options):
self.ensure_one()
job_options = job_options.copy()
job_options.setdefault("identity_key", identity_exact")
job_options.setdefault("priority", 40)
job_options.setdefault("channel", "root.invoice_transmit.peppol")
delayable = self.delayable(**job_options)
return delayable._transmit_invoice_by_peppol()
``


def _transmit_invoice_by_peppol(self):
"""Sending by peppol"""
invoices = self._transmit_invoice("peppol")
invoices = self.filtered(lambda p: p._is_transmissible_by_peppol())
invoices = invoices._transmit_invoice("peppol")
return invoices.peppol_export_invoice()