openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #06394
[Merge] lp:~therp-nl/web-addons/7.0-web_relativedelta into lp:web-addons
Holger Brunn (Therp) has proposed merging lp:~therp-nl/web-addons/7.0-web_relativedelta into lp:web-addons with lp:~therp-nl/web-addons/7.0-web_relativedelta_momentjs as a prerequisite.
Requested reviews:
Web-Addons Core Editors (webaddons-core-editors)
For more details, see:
https://code.launchpad.net/~therp-nl/web-addons/7.0-web_relativedelta/+merge/217653
Reimplementation of relativedelta for use in client side domains in the hope that it sucks less than the one provided in upstream.
This uses http://momentjs.com which was committed separately to simplify the review.
--
https://code.launchpad.net/~therp-nl/web-addons/7.0-web_relativedelta/+merge/217653
Your team Web-Addons Core Editors is requested to review the proposed merge of lp:~therp-nl/web-addons/7.0-web_relativedelta into lp:web-addons.
=== added file 'web_relativedelta/__init__.py'
--- web_relativedelta/__init__.py 1970-01-01 00:00:00 +0000
+++ web_relativedelta/__init__.py 2014-04-29 17:50:23 +0000
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
=== added file 'web_relativedelta/__openerp__.py'
--- web_relativedelta/__openerp__.py 1970-01-01 00:00:00 +0000
+++ web_relativedelta/__openerp__.py 2014-04-29 17:50:23 +0000
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+ "name": "More pythonic relativedelta",
+ "version": "1.0",
+ "author": "Therp BV",
+ "license": "AGPL-3",
+ "complexity": "normal",
+ "description": """
+Introduction
+============
+
+This addon provides a reimplementation of OpenERP's pyjs relativedelta class
+using Moment.js (http://momentjs.com).
+
+On top of what you can do with the original, you can use
+
+- datetime objects
+- relativedelta(hour=0-23, hours=0-23)
+- relativedelta(minute=0-59, minutes=0-59)
+- relativedelta(seconds=0-59, seconds=0-59)
+- relativedelta(weekday=0) [MO] ... weekday=6 [SU]
+
+ - there's no MO(+n) syntax, but that can be simulated by
+ relativedelta(weeks=+n, weekday=0)
+
+- all of them together in a predictable manner as detailed in https://labix.org/python-dateutil#head-72c4689ec5608067d118b9143cef6bdffb6dad4e
+
+Usage
+=====
+
+Simply depend on web_relativedelta and enjoy most of python's relativedelta
+functionality
+ """,
+ "category": "Dependency",
+ "depends": [
+ 'web',
+ ],
+ "data": [
+ ],
+ "js": [
+ 'static/lib/moment.js',
+ 'static/src/js/web_relativedelta.js'
+ ],
+ "css": [
+ ],
+ "qweb": [
+ ],
+ "auto_install": False,
+ "installable": True,
+ "application": False,
+ "external_dependencies": {
+ 'python': [],
+ },
+}
=== added directory 'web_relativedelta/static/src'
=== added directory 'web_relativedelta/static/src/img'
=== added file 'web_relativedelta/static/src/img/icon.png'
Binary files web_relativedelta/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and web_relativedelta/static/src/img/icon.png 2014-04-29 17:50:23 +0000 differ
=== added directory 'web_relativedelta/static/src/js'
=== added file 'web_relativedelta/static/src/js/web_relativedelta.js'
--- web_relativedelta/static/src/js/web_relativedelta.js 1970-01-01 00:00:00 +0000
+++ web_relativedelta/static/src/js/web_relativedelta.js 2014-04-29 17:50:23 +0000
@@ -0,0 +1,171 @@
+//-*- coding: utf-8 -*-
+//############################################################################
+//
+// OpenERP, Open Source Management Solution
+// This module copyright (C) 2014 Therp BV (<http://therp.nl>).
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//############################################################################
+
+openerp.web_relativedelta = function(openerp)
+{
+ var relativedelta = py.type('relativedelta', null,
+ {
+ __init__: function()
+ {
+ this.ops = py.PY_parseArgs(
+ arguments,
+ [
+ ['year', null],
+ ['years', null],
+ ['month', null],
+ ['months', null],
+ ['day', null],
+ ['days', null],
+ ['hour', null],
+ ['hours', null],
+ ['minute', null],
+ ['minutes', null],
+ ['second', null],
+ ['seconds', null],
+ ['weeks', null],
+ ['weekday', null],
+ ]);
+ },
+ __add__: function(other)
+ {
+ if(other.__name__ != 'date' && other.__name__ != 'datetime')
+ {
+ return py.NotImplemented;
+ }
+
+ var result = moment({
+ year: other.year,
+ //january==0 in moment.js
+ month: other.month - 1,
+ day: other.day,
+ hour: other.hour,
+ minute: other.minute,
+ second: other.second});
+
+ if(this.ops.year)
+ {
+ result.year(this.ops.year._value);
+ }
+ if(this.ops.years)
+ {
+ result.add('years', this.ops.years._value);
+ }
+ if(this.ops.month)
+ {
+ //january==0 in moment.js
+ result.month(this.ops.month._value - 1);
+ }
+ if(this.ops.months)
+ {
+ result.add('months', this.ops.months._value);
+ }
+ if(this.ops.day)
+ {
+ result.date(this.ops.day._value);
+ }
+ if(this.ops.days)
+ {
+ result.add('days', this.ops.days._value)
+ }
+ if(this.ops.weeks)
+ {
+ result.add('days', this.ops.weeks._value * 7);
+ }
+ if(this.ops.hour)
+ {
+ result.hour(this.ops.hour._value);
+ }
+ if(this.ops.hours)
+ {
+ result.add('hours', this.ops.hours._value);
+ }
+ if(this.ops.minute)
+ {
+ result.minute(this.ops.minute._value);
+ }
+ if(this.ops.minutes)
+ {
+ result.add('minutes', this.ops.minutes._value);
+ }
+ if(this.ops.second)
+ {
+ result.second(this.ops.second._value);
+ }
+ if(this.ops.seconds)
+ {
+ result.add('seconds', this.ops.seconds._value);
+ }
+ if(this.ops.weekday)
+ {
+ //in relativedelta, 0=MO, but in iso, 1=MO
+ result.isoWeekday(
+ Math.abs(this.ops.weekday._value || 1) /
+ (this.ops.weekday._value || 1) *
+ (Math.abs(this.ops.weekday._value) + 1));
+ }
+
+ var args = [
+ result.year(),
+ //january==0 in moment.js
+ result.month() + 1,
+ result.date(),
+ ];
+ if(other.__name__ == 'datetime')
+ {
+ args.push(result.hour());
+ args.push(result.minute());
+ args.push(result.second());
+ }
+
+ return py.PY_call(Object.getPrototypeOf(other), args);
+ },
+ __radd__: function(other)
+ {
+ return this.__add__(other);
+ },
+ __sub__: function(other)
+ {
+ _.each(this.ops, function(op, name)
+ {
+ if(!op)
+ {
+ return;
+ }
+ op._value = -op._value;
+ });
+ return this.__add__(other);
+ },
+ __rsub__: function(other)
+ {
+ return this.__sub__(other);
+ },
+ });
+ var original_pyeval_context = openerp.web.pyeval.context;
+ openerp.web.pyeval.context = function ()
+ {
+ var ctx = original_pyeval_context();
+ return _.extend(
+ ctx,
+ {
+ relativedelta: relativedelta,
+ });
+ }
+}
Follow ups