Skip to content

Commit

Permalink
Fix date range type unlink.
Browse files Browse the repository at this point in the history
Fix date range type unlink.

Update version.
  • Loading branch information
Fekete Mihai committed Mar 17, 2018
1 parent da7cfdc commit aa2df69
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 29 deletions.
1 change: 0 additions & 1 deletion date_range/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
3 changes: 1 addition & 2 deletions date_range/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Date Range",
"summary": "Manage all kind of date range",
"version": "11.0.1.0.0",
"version": "11.0.1.0.1",
"category": "Uncategorized",
"website": "https://github.com/oca/server-ux",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
Expand Down
1 change: 0 additions & 1 deletion date_range/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
1 change: 0 additions & 1 deletion date_range/models/date_range.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
12 changes: 10 additions & 2 deletions date_range/models/date_range_type.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import api, fields, models, _
from odoo.exceptions import UserError


class DateRangeType(models.Model):
Expand All @@ -26,3 +26,11 @@ def _default_company(self):
_sql_constraints = [
('date_range_type_uniq', 'unique (name,company_id)',
'A date range type must be unique per company !')]

@api.multi
def unlink(self):
if self.env['date.range'].search(
[('type_id', 'in', self.ids)], limit=1):
raise UserError(
_('You cannot date range types linked with date range.'))
return super(DateRangeType, self).unlink()
31 changes: 15 additions & 16 deletions date_range/static/src/js/date_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
odoo.define('date_range.search_filters', function (require) {
"use strict";

var core = require('web.core');
var core = require('web.core');
var data = require('web.data');
var filters = require('web.search_filters');
var rpc = require('web.rpc');
var framework = require('web.framework');

var _t = core._t;
var _lt = core._lt;
filters.ExtendedSearchProposition.include({
select_field: function(field) {
this._super.apply(this, arguments);
this.is_date_range_selected = false;
this.is_date = field.type == 'date' || field.type == 'datetime';
this.is_date = field.type === 'date' || field.type === 'datetime';
this.$value = this.$el.find('.searchview_extended_prop_value, .o_searchview_extended_prop_value');
if (this.is_date){
var ds = new data.DataSetSearch(this, 'date.range.type', this.context, [[1, '=', 1]]);
ds.read_slice(['name'], {}).done(this.proxy('add_date_range_types_operator'));
}
},

add_date_range_types_operator: function(date_range_types){
var self = this;
_.each(date_range_types, function(drt) {
Expand All @@ -31,10 +30,10 @@ filters.ExtendedSearchProposition.include({
.appendTo(self.$el.find('.searchview_extended_prop_op, .o_searchview_extended_prop_op'));
});
},

operator_changed: function (e) {
var val = $(e.target).val();
this.is_date_range_selected = val.startsWith('drt_');
this.is_date_range_selected = val.startsWith('drt_');
if (this.is_date_range_selected){
var type_id = val.replace('drt_', '');
this.date_range_type_operator_selected(type_id);
Expand All @@ -47,18 +46,18 @@ filters.ExtendedSearchProposition.include({
this.$value.empty().show();
var ds = new data.DataSetSearch(this, 'date.range', this.context, [['type_id', '=', parseInt(type_id)]]);
ds.read_slice(['name','date_start', 'date_end'], {}).done(this.proxy('on_range_type_selected'));

},

on_range_type_selected: function(date_range_values){
this.value = new filters.ExtendedSearchProposition.DateRange(this, this.value.field, date_range_values);
this.value.appendTo(this.$value);
if (!this.$el.hasClass('o_filter_condition')){
this.$value.find('.date-range-select').addClass('form-control');
this.$value.find('.date-range-select').addClass('form-control');
}
this.value.on_range_selected();
},

get_filter: function () {
var res = this._super.apply(this, arguments);
if (this.is_date_range_selected){
Expand All @@ -68,7 +67,7 @@ filters.ExtendedSearchProposition.include({
}
return res;
},

});

/**
Expand All @@ -83,7 +82,7 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('
events: {
'change': 'on_range_selected',
},

init: function (parent, field, date_range_values) {
this._super(parent, field);
this.date_range_values = date_range_values;
Expand All @@ -94,11 +93,11 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('
var option = select.options[select.selectedIndex];
return option.label || option.text;
},

get_value: function() {
return parseInt(this.$el.val());
},

on_range_selected: function(e){
var self = this;
self.domain = '';
Expand All @@ -116,11 +115,11 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('
self.domain = domain;
});
},

get_domain: function (field, operator) {
return this.domain;
},

});

});
});
1 change: 0 additions & 1 deletion date_range/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
1 change: 0 additions & 1 deletion date_range/tests/test_date_range.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

Expand Down
1 change: 0 additions & 1 deletion date_range/tests/test_date_range_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)nses/agpl).

Expand Down
16 changes: 15 additions & 1 deletion date_range/tests/test_date_range_type.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError


class DateRangeTypeTest(TransactionCase):
Expand All @@ -18,3 +18,17 @@ def test_default_company(self):
'company_id': False,
'allow_overlap': False})
self.assertFalse(drt.company_id)

def test_unlink(self):
date_range = self.env['date.range']
drt = self.env['date.range.type'].create(
{'name': 'Fiscal year',
'allow_overlap': False})
date_range.create({
'name': 'FS2016',
'date_start': '2015-01-01',
'date_end': '2016-12-31',
'type_id': drt.id,
})
with self.assertRaises(UserError):
drt.unlink()
1 change: 0 additions & 1 deletion date_range/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
1 change: 0 additions & 1 deletion date_range/wizard/date_range_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down

0 comments on commit aa2df69

Please sign in to comment.