Skip to content
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

[18.0][MIG] account_avatax_oca_log: Migration to 18.0 #460

Open
wants to merge 3 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
95 changes: 95 additions & 0 deletions account_avatax_oca_log/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
======================
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/18.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-18-0/account-fiscal-rule-18-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=18.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:%2018.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]>

- Kencove (https://www.kencove.com)

- Mohamed Alkobrosli <[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/18.0/account_avatax_oca_log>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_avatax_oca_log/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions account_avatax_oca_log/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Account Avatax OCA Log",
"version": "18.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",
}
11 changes: 11 additions & 0 deletions account_avatax_oca_log/data/cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<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="active" eval="False" />
</record>
</odoo>
33 changes: 33 additions & 0 deletions account_avatax_oca_log/data/emails.xml
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>
4 changes: 4 additions & 0 deletions account_avatax_oca_log/models/__init__.py
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
20 changes: 20 additions & 0 deletions account_avatax_oca_log/models/avalara_salestax.py
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
71 changes: 71 additions & 0 deletions account_avatax_oca_log/models/avatax_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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)
19 changes: 19 additions & 0 deletions account_avatax_oca_log/models/avatax_rest_api.py
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
39 changes: 39 additions & 0 deletions account_avatax_oca_log/models/res_config_settings.py
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().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().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
3 changes: 3 additions & 0 deletions account_avatax_oca_log/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions account_avatax_oca_log/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Open Source Integrators (<https://opensourceintegrators.com>)
- ForgeFlow (<https://www.forgeflow.com>)
- Jordi Ballester Alomar \<<[email protected]>\>
- Kencove (<https://www.kencove.com>)
- Mohamed Alkobrosli \<<[email protected]>\>
1 change: 1 addition & 0 deletions account_avatax_oca_log/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to log the API calls to Avatax.
2 changes: 2 additions & 0 deletions account_avatax_oca_log/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
All the calls to Avatax are logged in Odoo. You can access to the logs
in the menu Avatax log.
2 changes: 2 additions & 0 deletions account_avatax_oca_log/security/ir.model.access.csv
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.
Loading
Loading