-
-
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
4b3934f
commit c81b304
Showing
21 changed files
with
820 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 @@ | ||
<to update> |
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.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,26 @@ | ||
<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')}</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" | ||
><![CDATA[ | ||
<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 : ${ctx['sales_call_count']}</p> | ||
<p style="font-family: arial, sans-serif; font-size: 12.8px;">Invoice Transactions : ${ctx['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;">Sodexis 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,21 @@ | ||
# 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 fields, 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, | ||
"create_date_time": fields.Datetime.now(), | ||
"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() | ||
create_date_time = fields.Datetime("Create Date & Time") | ||
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 | ||
if not self.avatax_request: | ||
logs = self.search([]).filtered( | ||
lambda p: p.create_date_time.date() | ||
== fields.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,21 @@ | ||
# 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 fields | ||
|
||
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, | ||
"create_date_time": fields.Datetime.now(), | ||
"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.