-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OCA#150 from TelmoSenseFly/BSSFL-169
[BSSFL-169] Add module rma webhook
- Loading branch information
Showing
14 changed files
with
150 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 @@ | ||
Creates a HTTP callback when the rma is repaired. |
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,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of sensefly. | ||
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of senseFly. | ||
|
||
{ | ||
'name': 'RMA Web Hook', | ||
'version': '1.0', | ||
'author': 'Telmo Santos', | ||
'category': 'SenseFly', | ||
'depends': ['sf_rma', 'sf_rma_sale_order'], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/rma_config_settings.xml', | ||
'data/base_url_data.xml' | ||
], | ||
'demo': [], | ||
'images': ['static/description/icon.png'], | ||
'installable': True, | ||
'auto_install': False, | ||
} |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="rma_web_hook_base_url" model="rma.config.settings"> | ||
<field name="web_hook_base_url">http://translator.sensefly.com</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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of sensefly. | ||
from . import mrp_repair | ||
from . import rma_callback | ||
from . import res_company | ||
from . import rma_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,14 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of sensefly. | ||
|
||
from odoo import models, api | ||
|
||
|
||
class MRPRepair(models.Model): | ||
_inherit = "mrp.repair" | ||
|
||
@api.multi | ||
def action_repair_done(self): | ||
rma_ids = super(MRPRepair, self).action_repair_done() | ||
self.env['rma.callback'].call('odoo_rma_repaired', rma_ids) | ||
return rma_ids |
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,14 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class ResCompany(models.Model): | ||
|
||
_inherit = 'res.company' | ||
|
||
web_hook_base_url = fields.Char( | ||
string='Web Hook Base Url' | ||
) |
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,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of sensefly. | ||
|
||
from odoo import fields, models, api, _ | ||
from odoo.exceptions import MissingError | ||
from urlparse import urljoin | ||
import requests | ||
import logging | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class RmaCallBack(models.Model): | ||
_name = "rma.callback" | ||
|
||
@api.model | ||
def call(self, url_suffix, rma_ids): | ||
base_url = self.env['rma.config.settings'].default_web_hook_base_url() | ||
if not base_url: | ||
raise MissingError(_("Rma web hook base url not configured!")) | ||
|
||
for rma in self.env['mrp.repair'].browse(rma_ids): | ||
url = urljoin(base_url, url_suffix + '/' + rma.name) | ||
|
||
rma_call = self.search([('url', '=', url)], limit=1) | ||
|
||
if rma_call: | ||
# We do not make the call twice but we want to log it | ||
rma_call.count += 1 | ||
else: | ||
r = requests.get(url) | ||
self.env['rma.callback'].create( | ||
{ | ||
'url': url, | ||
'status_code': r.status_code, | ||
'count': 1 | ||
} | ||
) | ||
|
||
log_msg = "Called %s. Status code %s." % (url, r.status_code, ) | ||
if r.status_code == 200: | ||
_logger.info(log_msg) | ||
else: | ||
_logger.warning(log_msg) | ||
|
||
url = fields.Char(required=True) | ||
status_code = fields.Integer(required=True) | ||
count = fields.Integer(default=1) |
16 changes: 16 additions & 0 deletions
16
odoo/local-src/sf_rma_webhook/models/rma_config_settings.py
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class RMASettings(models.TransientModel): | ||
|
||
_inherit = 'rma.config.settings' | ||
|
||
web_hook_base_url = fields.Char( | ||
string='Base Url', required=True, | ||
related='company_id.web_hook_base_url', | ||
help="Base url to be called when rma is confirmed or repaired.", | ||
) |
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,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_rma_callback_user,access_rma_callback_user,model_rma_callback,sf_rma.group_rma_user,1,0,0,0 | ||
access_rma_callback_manager,access_rma_callback_manager,model_rma_callback,sf_rma.group_rma_manager,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.
17 changes: 17 additions & 0 deletions
17
odoo/local-src/sf_rma_webhook/views/rma_config_settings.xml
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_rma_config_settings_inherit" model="ir.ui.view"> | ||
<field name="name">rma settings inherit</field> | ||
<field name="model">rma.config.settings</field> | ||
<field name="inherit_id" ref="sf_rma.view_rma_config_settings" /> | ||
<field name="arch" type="xml"> | ||
<div id="main" position="inside"> | ||
<group string="Web Hook"> | ||
<field name="web_hook_base_url"/> | ||
</group> | ||
</div> | ||
</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