-
Notifications
You must be signed in to change notification settings - Fork 3
[16.0] account_invoice_transmit_peppol: Speedup and indepotent #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 _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() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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
peppol/account_invoice_export_ubl/models/peppol_server.py
Line 65 in 4d2f18d
to update invoice_export_confirmed
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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_exportis True. That would be a limited number of case