diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/utm/models/ir_http.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/utm/models/ir_http.py')
| -rw-r--r-- | addons/utm/models/ir_http.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/addons/utm/models/ir_http.py b/addons/utm/models/ir_http.py new file mode 100644 index 00000000..7de6922c --- /dev/null +++ b/addons/utm/models/ir_http.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from odoo.http import request +from odoo import models + + +class IrHttp(models.AbstractModel): + _inherit = 'ir.http' + + @classmethod + def get_utm_domain_cookies(cls): + return request.httprequest.host + + @classmethod + def _set_utm(cls, response): + if isinstance(response, Exception): + return response + # the parent dispatch might destroy the session + if not request.db: + return response + + domain = cls.get_utm_domain_cookies() + for var, dummy, cook in request.env['utm.mixin'].tracking_fields(): + if var in request.params and request.httprequest.cookies.get(var) != request.params[var]: + response.set_cookie(cook, request.params[var], domain=domain) + return response + + @classmethod + def _dispatch(cls): + response = super(IrHttp, cls)._dispatch() + return cls._set_utm(response) + + @classmethod + def _handle_exception(cls, exc): + response = super(IrHttp, cls)._handle_exception(exc) + return cls._set_utm(response) |
