-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
====================== | ||
Account Invoice Export | ||
====================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:910d301e4306e622ba05220a032f1103e8793cc9790ea96474821783307a6604 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github | ||
:target: https://github.com/OCA/edi/tree/14.0/account_invoice_export | ||
:alt: OCA/edi | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_export | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
The goal of this module is to allow sending invoices in different format to external systems. | ||
|
||
It extends the module `account_invoice_transmit_method`, adding options to configure an url and credentials (Basic Authentication). | ||
In the UI a new button `Send ebill` send the invoice pdf to the configure url. | ||
|
||
The actual sending of the invoice is manage by queue.job and the standard Odoo chatter on the invoice is used to inform the user on success/failure of the dispatch. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_export%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Camptocamp | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Thierry Ducrest <[email protected]> | ||
* Tam (Nguyen Duc) <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
||
The development of this module has been financially supported by: | ||
|
||
* Camptocamp | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/14.0/account_invoice_export>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
############################################################################## | ||
# | ||
# ______ Releasing children from poverty _ | ||
# / ____/___ ____ ___ ____ ____ ___________(_)___ ____ | ||
# / / / __ \/ __ `__ \/ __ \/ __ `/ ___/ ___/ / __ \/ __ \ | ||
# / /___/ /_/ / / / / / / /_/ / /_/ (__ |__ ) / /_/ / / / / | ||
# \____/\____/_/ /_/ /_/ .___/\__,_/____/____/_/\____/_/ /_/ | ||
# /_/ | ||
# in Jesus' name | ||
# | ||
# Copyright (C) 2015-2019 Compassion CH (http://www.compassion.ch) | ||
# @author: Emanuel Cino <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# pylint: disable=C8101 | ||
{ | ||
"name": "Account Invoice Export Grouped", | ||
"summary": "Extend the Account Invoice Export module with the \"Send eBill as instalment\" feature.", | ||
"version": "14.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Compassion CH", | ||
"website": "https://github.com/CompassionCH/test-repo", | ||
"category": "Accounting", | ||
"depends": [ | ||
"account_invoice_export", # edi/account_invoice_export | ||
], | ||
"external_dependencies": {}, | ||
"data": [ | ||
"views/account_move.xml", | ||
], | ||
"demo": [], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
import requests | ||
|
||
import odoo | ||
from odoo import _, fields, models | ||
from odoo.exceptions import UserError, except_orm | ||
|
||
from odoo.addons.queue_job.job import identity_exact | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
invoice_exported = fields.Boolean(copy=False) | ||
# Usefull when the distant system does not validate the export synchronously | ||
invoice_export_confirmed = fields.Boolean(copy=False) | ||
send_through_http = fields.Boolean(related="transmit_method_id.send_through_http") | ||
|
||
def export_invoice(self): | ||
resend_invoice = self.env.context.get("resend_ebill", False) | ||
for invoice in self: | ||
description = "{} - Export ebill".format(invoice.transmit_method_id.name) | ||
invoice.with_delay( | ||
description=description, identity_key=identity_exact | ||
)._job_export_invoice(resend_invoice) | ||
|
||
def export_invoice_as_instalment(self): | ||
for partner in self.partner_id: | ||
invoices = self.filtered(lambda move : move.partner_id.id == partner.id) | ||
print(invoices) | ||
|
||
def _job_export_invoice(self, resend_invoice=False): | ||
"""Export ebill to external server and update the chatter.""" | ||
self.ensure_one() | ||
if ( | ||
not resend_invoice | ||
and self.invoice_exported | ||
and self.invoice_export_confirmed | ||
): | ||
return _("Nothing done, invoice has already been exported before.") | ||
try: | ||
res = self._export_invoice() | ||
except Exception as e: | ||
values = { | ||
"job_id": self.env.context.get("job_uuid"), | ||
"error_detail": "", | ||
"error_type": type(e).__name__, | ||
"transmit_method_name": self.transmit_method_id.name, | ||
} | ||
if isinstance(e, except_orm): | ||
values["error_detail"] = e.name | ||
with odoo.api.Environment.manage(): | ||
with odoo.registry(self.env.cr.dbname).cursor() as new_cr: | ||
# Create a new environment with new cursor database | ||
new_env = odoo.api.Environment( | ||
new_cr, self.env.uid, self.env.context | ||
) | ||
# The chatter of the invoice need to be updated, when the job fails | ||
self.with_env(new_env).log_error_sending_invoice(values) | ||
raise | ||
self.log_success_sending_invoice() | ||
return res | ||
|
||
def _export_invoice(self): | ||
"""Export electronic invoice to external service.""" | ||
if not self.transmit_method_id.send_through_http: | ||
raise UserError(_("Transmit method is not configured to send through HTTP")) | ||
file_data = self._get_file_for_transmission_method() | ||
headers = self.transmit_method_id.get_transmission_http_header() | ||
url = self.transmit_method_id.get_transmission_url() | ||
res = requests.post(url, headers=headers, files=file_data) | ||
if res.status_code != 200: | ||
raise UserError( | ||
_( | ||
"HTTP error {} sending invoice to {}".format( | ||
res.status_code, self.transmit_method_id.name | ||
) | ||
) | ||
) | ||
self.invoice_exported = self.invoice_export_confirmed = True | ||
return res.text | ||
|
||
def _get_file_for_transmission_method(self): | ||
"""Return the file description to send. | ||
Use the format expected by the request library | ||
By default returns the PDF report. | ||
""" | ||
r = self.env["ir.actions.report"]._get_report_from_name( | ||
"account.report_invoice" | ||
) | ||
pdf, _ = r._render([self.id]) | ||
filename = self._get_report_base_filename().replace("/", "_") + ".pdf" | ||
return {"file": (filename, pdf, "application/pdf")} | ||
|
||
def log_error_sending_invoice(self, values): | ||
"""Log an exception in invoice's chatter when sending fails. | ||
If an exception already exists it is update otherwise a new one | ||
is created. | ||
""" | ||
activity_type = "account_invoice_export.mail_activity_transmit_warning" | ||
activity = self.activity_reschedule( | ||
[activity_type], date_deadline=fields.Date.today() | ||
) | ||
if not activity: | ||
message = self.env.ref( | ||
"account_invoice_export.exception_sending_invoice" | ||
)._render(values=values) | ||
activity = self.activity_schedule( | ||
activity_type, summary="Job error sending invoice", note=message | ||
) | ||
error_log = values.get("error_detail") | ||
if not error_log: | ||
error_log = _("An error of type {} occured.").format( | ||
values.get("error_type") | ||
) | ||
activity.note += "<div class='mt16'><p>{}</p></div>".format(error_log) | ||
|
||
def log_success_sending_invoice(self): | ||
"""Log success sending invoice and clear existing exception, if any.""" | ||
self.activity_feedback( | ||
["account_invoice_export.mail_activity_transmit_warning"], | ||
feedback="It worked on a later try", | ||
) | ||
self.message_post( | ||
body=_("Invoice successfuly sent to {}").format( | ||
self.transmit_method_id.name | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record model="ir.actions.server" id="action_send_ebill_as_instalment"> | ||
<field name="name">Send eBill as instalment</field> | ||
<field name="model_id" ref="account.model_account_move" /> | ||
<field name="binding_model_id" ref="account.model_account_move" /> | ||
<field name="state">code</field> | ||
<field name="code"> | ||
records.export_invoice_as_instalment() | ||
</field> | ||
</record> | ||
</odoo> |