Browse Source

[FIX] fixed constrains + fixed onchange + other minor fixes

pull/47/head
Andrea 6 years ago
committed by Nikos Tsirintanis
parent
commit
7d93421481
  1. 2
      date_range/README.rst
  2. 2
      date_range/__manifest__.py
  3. 3
      date_range/models/date_range.py
  4. 5
      date_range/models/date_range_type.py
  5. 1
      date_range/readme/CONTRIBUTORS.rst
  6. 2
      date_range/readme/INSTALL.rst
  7. 28
      date_range/static/src/js/date_range.js
  8. 1
      date_range/wizard/date_range_generator.py

2
date_range/README.rst

@ -133,7 +133,7 @@ promote its widespread use.
:target: https://github.com/lmignon :target: https://github.com/lmignon
:alt: lmignon :alt: lmignon
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
Current `maintainer <https://odoo-community.org/page/maintainer-role>`_:
|maintainer-lmignon| |maintainer-lmignon|

2
date_range/__manifest__.py

@ -3,7 +3,7 @@
{ {
"name": "Date Range", "name": "Date Range",
"summary": "Manage all kind of date range", "summary": "Manage all kind of date range",
"version": "11.0.2.0.0",
"version": "11.0.2.0.1",
"category": "Uncategorized", "category": "Uncategorized",
"website": "https://github.com/oca/server-ux", "website": "https://github.com/oca/server-ux",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)", "author": "ACSONE SA/NV, Odoo Community Association (OCA)",

3
date_range/models/date_range.py

@ -8,6 +8,7 @@ from odoo.exceptions import ValidationError
class DateRange(models.Model): class DateRange(models.Model):
_name = "date.range" _name = "date.range"
_description = "Date Range"
_order = "type_name,date_start" _order = "type_name,date_start"
@api.model @api.model
@ -34,7 +35,7 @@ class DateRange(models.Model):
('date_range_uniq', 'unique (name,type_id, company_id)', ('date_range_uniq', 'unique (name,type_id, company_id)',
'A date range must be unique per company !')] 'A date range must be unique per company !')]
@api.onchange('company_id')
@api.onchange('company_id', 'type_id')
def _onchange_company_id(self): def _onchange_company_id(self):
if self.company_id and self.type_id.company_id and \ if self.company_id and self.type_id.company_id and \
self.type_id.company_id != self.company_id: self.type_id.company_id != self.company_id:

5
date_range/models/date_range_type.py

@ -8,6 +8,7 @@ from odoo.exceptions import ValidationError
class DateRangeType(models.Model): class DateRangeType(models.Model):
_name = "date.range.type" _name = "date.range.type"
_description = "Date Range Type"
@api.model @api.model
def _default_company(self): def _default_company(self):
@ -35,10 +36,10 @@ class DateRangeType(models.Model):
for rec in self.sudo(): for rec in self.sudo():
if not rec.company_id: if not rec.company_id:
continue continue
if bool(self.date_range_ids.filtered(
if bool(rec.date_range_ids.filtered(
lambda r: r.company_id and lambda r: r.company_id and
r.company_id != rec.company_id)): r.company_id != rec.company_id)):
raise ValidationError( raise ValidationError(
_('You cannot change the company, as this ' _('You cannot change the company, as this '
'Date Range Type is assigned to Date Range ' 'Date Range Type is assigned to Date Range '
'(%s).') % (self.date_range_ids.name_get()[0][1]))
'(%s).') % (rec.date_range_ids.name_get()[0][1]))

1
date_range/readme/CONTRIBUTORS.rst

@ -1,3 +1,4 @@
* Laurent Mignon <laurent.mignon@acsone.eu> * Laurent Mignon <laurent.mignon@acsone.eu>
* Alexis de Lattre <alexis.delattre@akretion.com> * Alexis de Lattre <alexis.delattre@akretion.com>
* Miquel Raïch <miquel.raich@eficent.com> * Miquel Raïch <miquel.raich@eficent.com>
* Andrea Stirpe <a.stirpe@onestein.nl>

2
date_range/readme/INSTALL.rst

@ -1,3 +1 @@
The addon use the daterange method from postgres. This method is supported as of postgresql 9.2 The addon use the daterange method from postgres. This method is supported as of postgresql 9.2

28
date_range/static/src/js/date_range.js

@ -1,4 +1,4 @@
/* © 2016 ACSONE SA/NV (<http://acsone.eu>)
/* Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define('date_range.search_filters', function (require) { odoo.define('date_range.search_filters', function (require) {
"use strict"; "use strict";
@ -11,7 +11,7 @@ var framework = require('web.framework');
var _t = core._t; var _t = core._t;
filters.ExtendedSearchProposition.include({ filters.ExtendedSearchProposition.include({
select_field: function(field) {
select_field: function (field) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.is_date_range_selected = false; this.is_date_range_selected = false;
this.is_date = field.type === 'date' || field.type === 'datetime'; this.is_date = field.type === 'date' || field.type === 'datetime';
@ -22,9 +22,9 @@ filters.ExtendedSearchProposition.include({
} }
}, },
add_date_range_types_operator: function(date_range_types){
add_date_range_types_operator: function (date_range_types){
var self = this; var self = this;
_.each(date_range_types, function(drt) {
_.each(date_range_types, function (drt) {
$('<option>', {value: 'drt_' + drt.id}) $('<option>', {value: 'drt_' + drt.id})
.text(_('in ') + drt.name) .text(_('in ') + drt.name)
.appendTo(self.$el.find('.searchview_extended_prop_op, .o_searchview_extended_prop_op')); .appendTo(self.$el.find('.searchview_extended_prop_op, .o_searchview_extended_prop_op'));
@ -42,14 +42,14 @@ filters.ExtendedSearchProposition.include({
this._super.apply(this, arguments); this._super.apply(this, arguments);
}, },
date_range_type_operator_selected: function(type_id){
date_range_type_operator_selected: function (type_id){
this.$value.empty().show(); this.$value.empty().show();
var ds = new data.DataSetSearch(this, 'date.range', this.context, [['type_id', '=', parseInt(type_id)]]);
var ds = new data.DataSetSearch(this, 'date.range', this.context, [['type_id', '=', parseInt(type_id, 10)]]);
ds.read_slice(['name','date_start', 'date_end'], {}).done(this.proxy('on_range_type_selected')); ds.read_slice(['name','date_start', 'date_end'], {}).done(this.proxy('on_range_type_selected'));
}, },
on_range_type_selected: function(date_range_values){
on_range_type_selected: function (date_range_values){
this.value = new filters.ExtendedSearchProposition.DateRange(this, this.value.field, date_range_values); this.value = new filters.ExtendedSearchProposition.DateRange(this, this.value.field, date_range_values);
this.value.appendTo(this.$value); this.value.appendTo(this.$value);
if (!this.$el.hasClass('o_filter_condition')){ if (!this.$el.hasClass('o_filter_condition')){
@ -66,7 +66,7 @@ filters.ExtendedSearchProposition.include({
res.attrs.domain = this.value.domain; res.attrs.domain = this.value.domain;
} }
return res; return res;
},
}
}); });
@ -80,7 +80,7 @@ class
filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('id').extend({ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('id').extend({
template: 'SearchView.extended_search.dateRange.selection', template: 'SearchView.extended_search.dateRange.selection',
events: { events: {
'change': 'on_range_selected',
'change': 'on_range_selected'
}, },
init: function (parent, field, date_range_values) { init: function (parent, field, date_range_values) {
@ -94,11 +94,11 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('
return option.label || option.text; return option.label || option.text;
}, },
get_value: function() {
return parseInt(this.$el.val());
get_value: function () {
return parseInt(this.$el.val(), 10);
}, },
on_range_selected: function(e){
on_range_selected: function (e){
var self = this; var self = this;
self.domain = ''; self.domain = '';
framework.blockUI(); framework.blockUI();
@ -108,7 +108,7 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('
field_name: this.field.name field_name: this.field.name
}, },
model: 'date.range', model: 'date.range',
method: 'get_domain',
method: 'get_domain'
}) })
.then(function (domain) { .then(function (domain) {
framework.unblockUI(); framework.unblockUI();
@ -118,7 +118,7 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('
get_domain: function (field, operator) { get_domain: function (field, operator) {
return this.domain; return this.domain;
},
}
}); });

1
date_range/wizard/date_range_generator.py

@ -14,6 +14,7 @@ from dateutil.relativedelta import relativedelta
class DateRangeGenerator(models.TransientModel): class DateRangeGenerator(models.TransientModel):
_name = 'date.range.generator' _name = 'date.range.generator'
_description = 'Date Range Generator'
@api.model @api.model
def _default_company(self): def _default_company(self):

Loading…
Cancel
Save