summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-06-02 15:03:52 +0000
committerJulien Mougenot <jum@odoo.com>2020-07-14 09:10:32 +0000
commit669c2ebaec701055a15dc56ea90bf2d64bc38154 (patch)
tree6711c374432f030d3c375825b65943cdc0186bdc /addons/web/static/src
parentb9ad60d5ebe73ee47eba64145ebe27d483a7f33a (diff)
[IMP] web: improve eval context dates
This commit handles 2 things: 1) the merging of the `py_utils.context()` into the evaluation context returned by `BasicModel._getEvalContext` to access the same time-related keys, 2) the addition of 2 new keys into the `py_utils.context` (thus transmitted to the basic model): `today` (an alias for the already present `current_date`) and `now` which represents the current date and time value. Task 2269697
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/core/py_utils.js29
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js31
2 files changed, 42 insertions, 18 deletions
diff --git a/addons/web/static/src/js/core/py_utils.js b/addons/web/static/src/js/core/py_utils.js
index 590d5e62fc6..1cf1150ab76 100644
--- a/addons/web/static/src/js/core/py_utils.js
+++ b/addons/web/static/src/js/core/py_utils.js
@@ -254,14 +254,29 @@ function tz_offset() {
function pycontext() {
+ const d = new Date();
+ const today = `${
+ String(d.getFullYear()).padStart(4, "0")}-${
+ String(d.getMonth() + 1).padStart(2, "0")}-${
+ String(d.getDate()).padStart(2, "0")}`;
+ const now = `${
+ String(d.getUTCFullYear()).padStart(4, "0")}-${
+ String(d.getUTCMonth() + 1).padStart(2, "0")}-${
+ String(d.getUTCDate()).padStart(2, "0")} ${
+ String(d.getUTCHours()).padStart(2, "0")}:${
+ String(d.getUTCMinutes()).padStart(2, "0")}:${
+ String(d.getUTCSeconds()).padStart(2, "0")}`;
+
+ const { datetime, relativedelta, time } = py.extras;
return {
- datetime: py.extras.datetime,
- context_today: context_today,
- time: py.extras.time,
- relativedelta: py.extras.relativedelta,
- current_date: py.PY_call(
- py.extras.time.strftime, [py.str.fromJSON('%Y-%m-%d')]),
- tz_offset: tz_offset,
+ current_date: today,
+ datetime,
+ time,
+ now,
+ today,
+ relativedelta,
+ context_today,
+ tz_offset,
};
}
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index adefa997e99..8878de55a3e 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -88,6 +88,7 @@ var concurrency = require('web.concurrency');
var Context = require('web.Context');
var core = require('web.core');
var Domain = require('web.Domain');
+const pyUtils = require('web.py_utils');
var session = require('web.session');
var utils = require('web.utils');
var viewUtils = require('web.viewUtils');
@@ -3696,19 +3697,27 @@ var BasicModel = AbstractModel.extend({
}
// Uses "current_company_id" because "company_id" would conflict with all the company_id fields
// in general, the actual "company_id" field of the form should be used for m2o domains, not this fallback
+ let current_company_id;
if (session.user_context.allowed_company_ids) {
- var current_company = session.user_context.allowed_company_ids[0];
+ current_company_id = session.user_context.allowed_company_ids[0];
} else {
- var current_company = session.user_companies ? session.user_companies.current_company[0] : false;
- }
- return _.extend({
- active_id: evalContext.id || false,
- active_ids: evalContext.id ? [evalContext.id] : [],
- active_model: element.model,
- current_date: moment().format('YYYY-MM-DD'),
- id: evalContext.id || false,
- current_company_id: current_company,
- }, session.user_context, element.context, evalContext);
+ current_company_id = session.user_companies ?
+ session.user_companies.current_company[0] :
+ false;
+ }
+ return Object.assign(
+ {
+ active_id: evalContext.id || false,
+ active_ids: evalContext.id ? [evalContext.id] : [],
+ active_model: element.model,
+ current_company_id,
+ id: evalContext.id || false,
+ },
+ pyUtils.context(),
+ session.user_context,
+ element.context,
+ evalContext,
+ );
},
/**
* Returns the list of field names of the given element according to its