[IMP] delivery: mechanism to log XML requests

This will help future debugging of integrated shipping providers by
enabling the logging of XML requests in ir.logging table.
This commit is contained in:
Richard Mathot
2017-07-25 10:42:27 +02:00
parent 67e2372d61
commit 4c6c16a382
2 changed files with 38 additions and 1 deletions
+30 -1
View File
@@ -2,8 +2,9 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import psycopg2
from odoo import api, fields, models, _
from odoo import api, fields, models, registry, SUPERUSER_ID, _
_logger = logging.getLogger(__name__)
@@ -39,6 +40,7 @@ class DeliveryCarrier(models.Model):
delivery_type = fields.Selection([('fixed', 'Fixed Price')], string='Provider', default='fixed', required=True)
integration_level = fields.Selection([('rate', 'Get Rate'), ('rate_and_ship', 'Get Rate and Create Shipment')], string="Integration Level", default='rate_and_ship', help="Action while validating Delivery Orders")
prod_environment = fields.Boolean("Environment", help="Set to True if your credentials are certified for production.")
debug_logging = fields.Boolean('Debug logging', help="Log requests in order to ease debugging")
company_id = fields.Many2one('res.company', string='Company', related='product_id.company_id', store=True)
product_id = fields.Many2one('product.product', string='Delivery Product', required=True, ondelete='restrict')
@@ -59,6 +61,10 @@ class DeliveryCarrier(models.Model):
for c in self:
c.prod_environment = not c.prod_environment
def toggle_debug(self):
for c in self:
c.debug_logging = not c.debug_logging
@api.multi
def install_more_provider(self):
return {
@@ -154,6 +160,29 @@ class DeliveryCarrier(models.Model):
if hasattr(self, '%s_cancel_shipment' % self.delivery_type):
return getattr(self, '%s_cancel_shipment' % self.delivery_type)(pickings)
def log_xml(self, xml_string, func):
self.ensure_one()
if self.debug_logging:
db_name = self._cr.dbname
# Use a new cursor to avoid rollback that could be caused by an upper method
try:
db_registry = registry(db_name)
with db_registry.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
IrLogging = env['ir.logging']
IrLogging.sudo().create({'name': 'delivery.carrier',
'type': 'server',
'dbname': db_name,
'level': 'DEBUG',
'message': xml_string,
'path': self.delivery_type,
'func': func,
'line': 1})
except psycopg2.Error:
pass
# ------------------------------------------------ #
# Fixed price shipping, aka a very simple provider #
# ------------------------------------------------ #
+8
View File
@@ -59,6 +59,14 @@
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button" options='{"terminology": "active"}'/>
</button>
<button name="toggle_debug" type="object" class="oe_stat_button" icon="fa-code" groups="base.group_no_one" attrs="{'invisible': ['|', ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule')]}">
<field name="debug_logging" widget="boolean_button" options='{"terminology": {
"string_true": "Debug requests",
"hover_true": "Disable debug",
"string_false": "No debug",
"hover_false": "Enable debug"
}}'/>
</button>
</div>
<div class="oe_title" name="title">
<label for="name" string="Name" class="oe_edit_only"/>