Skip to content

Commit

Permalink
Merge pull request OCA#150 from TelmoSenseFly/BSSFL-169
Browse files Browse the repository at this point in the history
[BSSFL-169] Add module rma webhook
  • Loading branch information
yvaucher committed Oct 23, 2017
2 parents 275d44b + 0c8f714 commit a012721
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ latest (unreleased)

**Features and Improvements**

* Add module rma webhook
* Add section on quotation and invoice reports
* Install module sale_validity
* Labeling analytic account/tags columns as Project/Team
Expand Down
1 change: 1 addition & 0 deletions odoo/local-src/sf_rma_webhook/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Creates a HTTP callback when the rma is repaired.
3 changes: 3 additions & 0 deletions odoo/local-src/sf_rma_webhook/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# Part of sensefly.
import models
19 changes: 19 additions & 0 deletions odoo/local-src/sf_rma_webhook/__manifest__.py
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,
}
6 changes: 6 additions & 0 deletions odoo/local-src/sf_rma_webhook/data/base_url_data.xml
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>
6 changes: 6 additions & 0 deletions odoo/local-src/sf_rma_webhook/models/__init__.py
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
14 changes: 14 additions & 0 deletions odoo/local-src/sf_rma_webhook/models/mrp_repair.py
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
14 changes: 14 additions & 0 deletions odoo/local-src/sf_rma_webhook/models/res_company.py
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'
)
48 changes: 48 additions & 0 deletions odoo/local-src/sf_rma_webhook/models/rma_callback.py
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 odoo/local-src/sf_rma_webhook/models/rma_config_settings.py
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.",
)
3 changes: 3 additions & 0 deletions odoo/local-src/sf_rma_webhook/security/ir.model.access.csv
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 odoo/local-src/sf_rma_webhook/views/rma_config_settings.xml
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>
2 changes: 2 additions & 0 deletions odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ migration:
- mrp_team
- sf_sale_invoicing
- sale_partner_incoterm
- sf_sale_invoice_fiscal_position
- sf_rma_webhook
- version: 10.1.0
- version: 10.2.0
- version: 10.3.0
Expand Down

0 comments on commit a012721

Please sign in to comment.