Commit Graph

38 Commits

Author SHA1 Message Date
qsm-odoo b2d66d0c14 [FIX] web: properly combine domains with "OR" in CompoundDomain
The CompoundDomain class allows to regroup several domains with an
implicit "AND"; these domains can be either a string, an array or
another CompoundDomain. A CompoundDomain can then be converted to
an array thanks to pyeval.js.
For example, if a CompoundDomain is initialized with `[A, B]` and
`[C]`, the array conversion gave `[A, B, C]` (which is expected).

However, a hackish method was used with CompoundDomain. If one of the
domain of a CompoundDomain is equal to `["|"]` (an array with the
OR operator in it), the two next subdomains were supposed to be joined
by a OR operator. Indeed, for the case of a CompoundDomain initialized
with `["|"]`, `[A]` and `[B]`, the array conversion gave `["|", A, B]`
(which is expected). However, if initialized with `["|"]`, `[A, B]` and
`[C]`, the array conversion gave `["|", A, B, C]` which is very wrong
as what was expected is `["|", "&", A, B, C]`. The problem is that the
given `[A, B]` contains implicit "&" operators.

This commit fixes the problem by normalizing only if the CompoundDomain
starts with a ["|"] or ["!"] array which is the standard odoo case.
This allows to limit breaking custom code (e.g we want a simple "AND"
of `[A]` and `[B]` to stay `[A, B]`, not become `["&", A, B]`).

The commit also modifies a test so that it checks that the problem is
properly solved.
2017-03-24 15:03:54 +01:00
Xavier Morel fb2b1d7568 [IMP] py.js relativedelta
Rewrite relativedelta.__add__ based on dateutil 2.4.0

* completely remove any hint of supporting time deltas (could be
  implemented in the future, but not currently asked for and lots of
  code to implement)
* implement weekday support (ordinal only)
* probably better leapyear support
* remove relativedelta.__sub__ (only works between relativedeltas)
* add relativedelta.__neg__

fixes #5089
2015-03-03 12:00:12 +01:00
Géry Debongnie af8c2e4db6 [IMP] pyeval: implement weekday function
courtesy of mva.  This adds the weekday function to date objects in
pyeval.  This will be useful for adding better filters (such as this
week) in the searchview.
2015-01-19 14:08:09 +01:00
Mario Arias Badila bd2633753d [ADD] pyeval: date.replace method
Needed to create filters like "previous month"

It was just defined for "datetime", but is also needed for "date"

closes #2915
2014-12-02 16:59:24 +01:00
Géry Debongnie 22b1f5ce0c [FIX] web: fixes issues with custom filters and search view
The problem was that when the user manipulates the graph view (in pivot
table mode), the graph view resetted the group by facet in the search
view.  It was not a problem unless a custom filter with a groupby was
already there, in which case, the group bys were duplicated.

The search view is now smarter, it only resets the additional groupbys
(and col_groupbys).   Also, to prevent usability problems, the graph
view disable the '+/-' groupbys added by a custom filters.

Note that this fix is only temporary: a revamp of custom filters, facets,
search view is coming in the next months. (at least, that's the idea). Right
now, too much 'search logic' is in the graph view.

Another note: this fix is somewhat fragile: it makes some assumptions
about the search query (mainly that the custom filter is the first facet,
also, that no other filters add groupbys/col_groupbys)
2014-09-15 09:52:34 +02:00
Martin Trigaux 802d64ca92 [MERGE] [ADD] ways to correctly handle local datetimes in e.g. domains
* Alter datetime.now(), generate a local datetime (add utcnow() which generates a UTC datetime)
* Implement datetime.replace() to manipulate local datetimes
* Implement date.today(), generates a local date
* Implement datetime.toJSON(), returns a javascript Date (assumes datetime attributes are local)
* Add conversion hook in JSON and JSONP handlers, automatically converts a Date object to a UTC datetime formatted according to server formats

Should allow the generation of correctly working (from the end-user's POV) [Today] filters, amongst other things.
Eg: a local expression in a domain for 'Today 00:00:00' would now be expressed as 'datetime.datetime.now().replace(hour=0, minute=0, second=0)' (no .strftime) and will be converted to UTC when sent to the server

bzr revid: mat@openerp.com-20140128133706-4yp610pp5w06tcia
2014-01-28 14:37:06 +01:00
Xavier Morel 5b7ade9db1 [ADD] ways to correctly handle local datetimes in e.g. domains
* change datetime.now() to generate user-local naive datetimes
* add datetime.utcnow() behaving as the old now()
* add date.today() generating a user-local date (for the current day)
* add datetime.replace() to replace any specific attribute of the
  datetime object (except tzinfo, for now)
* datetime.toJSON() now returns the equivalent javascript Date object
  (warning: uses the datetime attributes directly, since datetimes are
  naive if they were created with utcnow() the Date result is going to
  be complete nonsense). With the previous commit datetime.now()
  generates a user-local now() which is converted to the correct UTC
  datetime when sent to the server.

This means it becomes possible to generate datetime bounds for the
user's local today with either

    datetime.datetime.now().replace(hour=0, minute=0, second=0)

or

    datetime.datetime.combine(
        datetime.date.today(),
        datetime.time())

and once send over JSON-RPC the server will get the local datetime
in UTC to the server's format.

nb: user-local means "in the timezone of the user's browser" in this
context.

bzr revid: xmo@openerp.com-20140122151911-akn1nr6e739eg92s
2014-01-22 16:19:11 +01:00
Gery Debongnie 30e6eadf42 [FIX] fixes a problem in pyeval catching all exceptions silently
bzr revid: ged@openerp.com-20131113102204-m0gox7odwgkmon4o
2013-11-13 11:22:04 +01:00
niv-openerp baef37aec6 [IMP] Removed old JavaScript module loading system in the 'web' addons. Still has some retro-compatibility for other addons.
bzr revid: nicolas.vanhoren@openerp.com-20130806125022-bzjbtn0nqk40ak4g
2013-08-06 14:50:22 +02:00
niv-openerp c767a0d34c Added semicolons
bzr revid: nicolas.vanhoren@openerp.com-20130725103301-65nld10p1if7k0zt
2013-07-25 12:33:01 +02:00
niv-openerp 42e493e73e Added Gruntfile with jshint and corrected most js errors
bzr revid: nicolas.vanhoren@openerp.com-20130725100749-0i82gf3k3nvt4r44
2013-07-25 12:07:49 +02:00
Martin Trigaux 7e4776f2f2 [FIX] pyeval: be more fault tolerant to avoid wrap null values
bzr revid: mat@openerp.com-20130702141600-4s7oan9yidjrlmcc
2013-07-02 16:16:00 +02:00
Xavier Morel 11a0ece543 [FIX] evaluation context structures not being round-tripped through eval
JS objects are converted to py.object when passed in through the
evaluation context. py.object are not serializable by default (because
that doesn't really make sense), which breaks when the input is
intended as a dict and returned (e.g. o2m values, which are triples of
(int, int?, dict?)).

Intuitively, JS objects passed as part of the context should be mostly
JSON-ish and thus dicts, but that turns out not work work as some
addons use attribute accesses within contexts (e.g. parent.access in
account/account_invoice_view.xml)

=> Temporarily solve by converting raw js objects to an "attributed
dict" which acts as both a dict and an object and can be converted to
JSON.

Ideally, py.js should provide for a pluggable conversion, or should
use an attributed mapping internally. See issues 21 and 23.

lp bug: https://launchpad.net/bugs/1182101 fixed

bzr revid: xmo@openerp.com-20130624055929-3rtkgqrp4o87pvau
2013-06-24 07:59:29 +02:00
niv-openerp c55de6996f [FIX] small problem with m2o, does not uses context when opening them in read-only mode
bzr revid: nicolas.vanhoren@openerp.com-20130319102719-0gdwvmix4d3x8th5
2013-03-19 11:27:19 +01:00
Xavier Morel ac5008abc9 [FIX] pyeval: argspec of relativedelta
bzr revid: xmo@openerp.com-20130318105244-qkgvi69do0219lkk
2013-03-18 11:52:44 +01:00
Xavier Morel b87102f22e [FIX] Inject user context in all domain and context evaluation
Custom keys from user context may be used in action contexts (not just
e.g. searchview filters). For instance, have a custom key
context_salesteam (in the user model) and an action defining some
search default as a function of the salesteam.

In that case, the action's context evaluation (view.js:~275) will blow
up.

Ensure that does not happen.

Note: eval_contexts already injects user_context in the reduction of
contexts to evaluate. It should be possible to alter the reduction
function to avoid having to inject instance.session.user_context
through pyeval.context(), maybe by _.extend-ing ``result_context``
into ``evaluation_context`` at the *top* of the reduction function
rather than at its bottom?

bzr revid: xmo@openerp.com-20130128130640-ksyvxvx6rlc4820n
2013-01-28 14:06:40 +01:00
Xavier Morel 5d313f1754 [FIX] styllistic fixes
bzr revid: xmo@openerp.com-20121130103638-8r77jpmb3hhmo8dt
2012-11-30 11:36:38 +01:00
niv-openerp 94dca54e38 [IMP] removed date.today() in pyeval
bzr revid: nicolas.vanhoren@openerp.com-20121130095228-mffq2407lq7tf8jj
2012-11-30 10:52:28 +01:00
niv-openerp f9b9e7c4cb [IMP] added context_today()
bzr revid: nicolas.vanhoren@openerp.com-20121129160746-c3c691zk5fxhzse0
2012-11-29 17:07:46 +01:00
niv-openerp cc6f0aa20a [FIX] potential problem with pyeval datetime/date today()/now() methods. Now only returns the same timezone than server (UTC).
bzr revid: nicolas.vanhoren@openerp.com-20121129153601-vtpnvkc0vylo9hux
2012-11-29 16:36:01 +01:00
Xavier Morel 89d9cd5910 [FIX] use py.js 0.7 API
bzr revid: xmo@openerp.com-20121128110542-nplg9o3e5jpxmqic
2012-11-28 12:05:42 +01:00
Xavier Morel 929a656619 [IMP] allow eval'ing a single context or domain
bzr revid: xmo@openerp.com-20121126084229-wgpjszmquhibbrpf
2012-11-26 09:42:29 +01:00
Xavier Morel 6b2b2d889c [IMP] move nonliteral domains and contexts to JS test case
bzr revid: xmo@openerp.com-20121123114923-t4047w6jztria91x
2012-11-23 12:49:23 +01:00
Xavier Morel 709f2506ff [REM] server-side eval_domain_and_context
bzr revid: xmo@openerp.com-20121123113932-siz0u2vp2u7z6wk2
2012-11-23 12:39:32 +01:00
Xavier Morel 49bd834725 [IMP] deferred init style
bzr revid: xmo@openerp.com-20121123101822-inox7gkxvd0gtqbp
2012-11-23 11:18:22 +01:00
Xavier Morel 7c09e23de7 [ADD] todo notes
bzr revid: xmo@openerp.com-20121123101658-xoynynruwnuzyrv3
2012-11-23 11:16:58 +01:00
Xavier Morel 242a5da5a9 [REM] stray logging
bzr revid: xmo@openerp.com-20121123095824-xg6afc1l01t3y48y
2012-11-23 10:58:24 +01:00
Xavier Morel 328537a7ba [ADD] arithmetics between date and timedelta
bzr revid: xmo@openerp.com-20121123095206-dtvoiignb7xnzsl0
2012-11-23 10:52:06 +01:00
Xavier Morel 815b908759 [ADD] partial but sufficient (I think) implementation of datetime.timedelta
bzr revid: xmo@openerp.com-20121123075938-oazwt4bn2l639r3a
2012-11-23 08:59:38 +01:00
Xavier Morel 9105afcd68 [FIX] put evaluation context in evaluation context
so you can access the context while you're accessing the context

bzr revid: xmo@openerp.com-20121122124130-t8j6sggtnl4f0b8r
2012-11-22 13:41:30 +01:00
Xavier Morel e6b77eb820 [IMP] shortcut call to eval_domain_and_context to be evaluated on the JS side, also add some offline-evaluation of contexts and domains in rpc call methods
bzr revid: xmo@openerp.com-20121011100532-5ihje0maslp37zpf
2012-10-11 12:05:32 +02:00
Xavier Morel b94e9c30a7 [FIX] after discussions with odo, date/datetime/time for locally-evaluated contexts and domains should be local, not UTC
bzr revid: xmo@openerp.com-20121011075759-qfwkfws5tu9yidab
2012-10-11 09:57:59 +02:00
Xavier Morel 1fa00288b2 [FIX] add 'context' free variable in evaluation contexts for domains and contexts
bzr revid: xmo@openerp.com-20121010145945-16shdry3udum0mn1
2012-10-10 16:59:45 +02:00
Xavier Morel 894bd34e62 [REM] timedelta, because pain
bzr revid: xmo@openerp.com-20121008125523-ed1g42vjxbcfo62r
2012-10-08 14:55:23 +02:00
Xavier Morel 7bcbadb099 [FIX] update py.js to 0.6, port existin classes to it, attempt to implement timedelta
bzr revid: xmo@openerp.com-20121008120619-lhmexjnujjrigjn9
2012-10-08 14:06:19 +02:00
Xavier Morel 10bc6ddfe4 [ADD] groupby eval tests
bzr revid: xmo@openerp.com-20121005142808-yx6o8nfnn0o4ms56
2012-10-05 16:28:08 +02:00
Xavier Morel 0e101c63a3 [FIX] evaluator: connection -> session
bzr revid: xmo@openerp.com-20121005131205-ffk746ac5xrua62j
2012-10-05 15:12:05 +02:00
Xavier Morel 6f4abdfbd5 [IMP] move eval functions for domains, groupbys and contexts outside of corelib, as well as the standard evaluation context building (and related objects)
bzr revid: xmo@openerp.com-20120806094627-8c9lwtfkbfws2bmj
2012-08-06 11:46:27 +02:00