-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
1 parent
c816411
commit d401cf2
Showing
21 changed files
with
854 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
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,90 @@ | ||
====================== | ||
Account Avatax OCA Log | ||
====================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:f2ef9f0fced1ab2776c5c31c6e4595b45327f1f7b09c60843ff0ca2b58542d23 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |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%2Faccount--fiscal--rule-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-fiscal-rule/tree/16.0/account_avatax_oca_log | ||
:alt: OCA/account-fiscal-rule | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-fiscal-rule-16-0/account-fiscal-rule-16-0-account_avatax_oca_log | ||
: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/account-fiscal-rule&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to log the API calls to Avatax. | ||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
All the calls to Avatax are logged in Odoo. You can access to the logs in the menu Avatax log. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-fiscal-rule/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/account-fiscal-rule/issues/new?body=module:%20account_avatax_oca_log%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* Open Source Integrators | ||
* ForgeFlow | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Open Source Integrators (https://opensourceintegrators.com) | ||
* ForgeFlow (https://www.forgeflow.com) | ||
|
||
* Jordi Ballester Alomar <[email protected]> | ||
|
||
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/account-fiscal-rule <https://github.com/OCA/account-fiscal-rule/tree/16.0/account_avatax_oca_log>`_ 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,19 @@ | ||
{ | ||
"name": "Account Avatax OCA Log", | ||
"version": "16.0.1.0.0", | ||
"author": "Open Source Integrators, ForgeFlow, Odoo Community Association (OCA)", | ||
"summary": "Add Logs to Avatax calls", | ||
"license": "AGPL-3", | ||
"category": "Accounting", | ||
"website": "https://github.com/OCA/account-fiscal-rule", | ||
"depends": ["account_avatax_oca"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"data/cron.xml", | ||
"data/emails.xml", | ||
"views/res_config_settings_views.xml", | ||
"views/avatax_log_views.xml", | ||
], | ||
"auto_install": False, | ||
"development_status": "Alpha", | ||
} |
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 @@ | ||
<odoo noupdate="1"> | ||
<record id="ir_cron_avatax_api_call_counter" model="ir.cron"> | ||
<field name="name">Avatax API Call Counter</field> | ||
<field name="model_id" ref="account_avatax_oca_log.model_avatax_log" /> | ||
<field name="state">code</field> | ||
<field name="code">model.avatax_api_call_counter()</field> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field name="active" eval="False" /> | ||
</record> | ||
</odoo> |
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,33 @@ | ||
<odoo noupdate="1"> | ||
<record id="reaching_limit_avatax_api_call_email" model="mail.template"> | ||
<field name="name">Avatax API Call Reaching Limit</field> | ||
<field name="model_id" ref="base.model_res_company" /> | ||
<field name="email_to">{{ ctx.get('email_to', False) }}</field> | ||
<field name="subject">Avatax API Call Reaching Limit</field> | ||
<field name="auto_delete" eval="True" /> | ||
<field name="lang">{{ object.partner_id.lang }}</field> | ||
<field name="body_html" type="html"> | ||
<p>Hello.</p> | ||
<br /> | ||
<p> | ||
The number of Avatax API calls was over the limit yesterday. | ||
</p> | ||
<p | ||
style="font-family: arial, sans-serif; font-size: 12.8px;" | ||
>Sale Transactions : <t t-out="ctx.get('sales_call_count')" /></p> | ||
<p | ||
style="font-family: arial, sans-serif; font-size: 12.8px;" | ||
>Invoice Transactions : <t t-out="ctx.get('invoices_call_count')" /></p> | ||
<br /> | ||
<p | ||
style="font-family: arial, sans-serif; font-size: 12.8px;" | ||
>Thank you for your cooperation.</p> | ||
<p | ||
style="font-family: arial, sans-serif; font-size: 12.8px;" | ||
>Kind regards,</p> | ||
<p | ||
style="font-family: arial, sans-serif; font-size: 12.8px;" | ||
>Support Team.</p> | ||
</field> | ||
</record> | ||
</odoo> |
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,4 @@ | ||
from . import avalara_salestax | ||
from . import avatax_log | ||
from . import avatax_rest_api | ||
from . import res_config_settings |
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,20 @@ | ||
# Copyright (C) 2020 Open Source Integrators | ||
# Copyright (C) 2023 ForgeFlow, S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import models | ||
|
||
|
||
class AvalaraSalestax(models.Model): | ||
_inherit = "avalara.salestax" | ||
|
||
def void_transaction(self, doc_code, doc_type): | ||
result = super().void_transaction(doc_code, doc_type) | ||
if not self.disable_tax_reporting: | ||
self.env["avatax.log"].sudo().create( | ||
{ | ||
"avatax_request": result.get("id"), | ||
"avatax_response": result, | ||
"avatax_type": "cancel", | ||
} | ||
) | ||
return result | ||
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,73 @@ | ||
# Copyright (C) 2020 Open Source Integrators | ||
# Copyright (C) 2023 ForgeFlow, S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from ast import literal_eval | ||
|
||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class AvataxLog(models.Model): | ||
_name = "avatax.log" | ||
_description = "Avatax API call counter" | ||
|
||
avatax_request = fields.Text() | ||
avatax_response = fields.Text() | ||
avatax_type = fields.Selection( | ||
[ | ||
("SalesOrder", "Sale Transaction"), | ||
("SalesInvoice", "Invoice Transaction"), | ||
("cancel", "Cancel / Void"), | ||
("others", "Others"), | ||
] | ||
) | ||
|
||
def name_get(self): | ||
result = [] | ||
for log in self: | ||
name = "Avatax Log" + " " + str(log.id) | ||
result.append((log.id, name)) | ||
return result | ||
|
||
def avatax_api_call_counter(self): | ||
call_counter_config_values = ( | ||
self.env["ir.config_parameter"] | ||
.sudo() | ||
.get_param("account_avatax_oca.call_counter_limit") | ||
) | ||
logs = self.env["avatax.log"] | ||
sales_call_count = 0 | ||
invoices_call_count = 0 | ||
today = fields.Date.today() | ||
yesterday = today - relativedelta(days=1) | ||
logs = self.search( | ||
[ | ||
("create_date", ">=", yesterday), | ||
("create_date", "<", today + relativedelta(days=1)), | ||
] | ||
) | ||
sales_call_count = len(logs.filtered(lambda p: p.avatax_type == "SalesOrder")) | ||
invoices_call_count = len( | ||
logs.filtered(lambda p: p.avatax_type == "SalesInvoice") | ||
) | ||
if len(logs) > int(call_counter_config_values): | ||
avatax_api_call_notification = ( | ||
self.env["ir.config_parameter"] | ||
.sudo() | ||
.get_param( | ||
"account_avatax_oca.avatax_api_call_notification_ids", default="[]" | ||
) | ||
) | ||
user_ids = literal_eval(avatax_api_call_notification) | ||
user_email = self.env["res.users"].browse(user_ids).mapped("login") | ||
email = ",".join(user_email) | ||
self.env.ref( | ||
"account_avatax_oca.reaching_limit_avatax_api_call_email" | ||
).with_context( | ||
sales_call_count=sales_call_count, | ||
invoices_call_count=invoices_call_count, | ||
email=email, | ||
).send_mail( | ||
self.env.company.id, force_send=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,19 @@ | ||
# Copyright (C) 2020 Open Source Integrators | ||
# Copyright (C) 2023 ForgeFlow, S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.addons.account_avatax_oca.models.avatax_rest_api import AvaTaxRESTService | ||
|
||
|
||
class AvaTaxRESTServiceExtended(AvaTaxRESTService): | ||
def _get_tax_post_process(self, data, result, doc_type): | ||
self.config.env["avatax.log"].sudo().create( | ||
{ | ||
"avatax_request": data, | ||
"avatax_response": result, | ||
"avatax_type": "SalesOrder" | ||
if doc_type in ["SalesOrder", "ReturnOrder"] | ||
else "SalesInvoice", | ||
} | ||
) | ||
return 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,39 @@ | ||
# Copyright (C) 2020 Open Source Integrators | ||
# Copyright (C) 2023 ForgeFlow, S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from ast import literal_eval | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class Settings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
avatax_api_call_notification_ids = fields.Many2many( | ||
"res.users", | ||
readonly=False, | ||
) | ||
call_counter_limit = fields.Integer( | ||
config_parameter="account_avatax_oca.call_counter_limit", | ||
default=100, | ||
) | ||
|
||
@api.model | ||
def get_values(self): | ||
res = super(Settings, self).get_values() | ||
ICPSudo = self.env["ir.config_parameter"].sudo() | ||
get_param = "account_avatax_oca.avatax_api_call_notification_ids" | ||
calls = ICPSudo.get_param(get_param) | ||
res.update( | ||
avatax_api_call_notification_ids=[(6, 0, literal_eval(calls))] | ||
if calls | ||
else False, | ||
) | ||
return res | ||
|
||
def set_values(self): | ||
res = super(Settings, self).set_values() | ||
ICPSudo = self.env["ir.config_parameter"].sudo() | ||
set_param = "account_avatax_oca.avatax_api_call_notification_ids" | ||
ICPSudo.set_param(set_param, self.avatax_api_call_notification_ids.ids) | ||
return res | ||
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,4 @@ | ||
* Open Source Integrators (https://opensourceintegrators.com) | ||
* ForgeFlow (https://www.forgeflow.com) | ||
|
||
* Jordi Ballester Alomar <[email protected]> |
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 @@ | ||
This module allows to log the API calls to Avatax. |
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 @@ | ||
All the calls to Avatax are logged in Odoo. You can access to the logs in the menu Avatax log. |
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,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_avatax_log,avatax_log,model_avatax_log,base.group_user,1,1,1,1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.