add account_move_line_search_extension

This commit is contained in:
Luc De Meyer
2014-03-20 15:54:42 +01:00
parent 206fae752d
commit 317f0e468f
7 changed files with 225 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
#
# Copyright (c) 2013 Noviat nv/sa (www.noviat.com). All rights reserved.
#
# 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/>.
#
##############################################################################

View File

@@ -0,0 +1,54 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
#
# Copyright (c) 2013 Noviat nv/sa (www.noviat.com). All rights reserved.
#
# 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': 'Journal Items Search Extension',
'version': '0.1',
'license': 'AGPL-3',
'author': 'Noviat',
'category' : 'Generic Modules',
'description': """
Journal Items Search Extension
==============================
This module adds the 'Journal Items Search All' menu entry.
This menu entry adds a number of search fields on top of the List View rows.
These fields can be used in combination with the Search window.
""",
'depends': ['account'],
'data' : [
'account_view.xml',
],
'js': [
'static/src/js/account_move_line_search_extension.js',
],
'qweb' : [
'static/src/xml/account_move_line_search_extension.xml',
],
'css':[
'static/src/css/account_move_line_search_extension.css',
],
'installable': True,
'auto_install': False,
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="action_account_move_line_search_extension" model="ir.actions.act_window">
<field name="context">{'account_move_line_search_extension':1}</field>
<field name="name">Journal Items Search All</field>
<field name="res_model">account.move.line</field>
<field name="view_id" ref="account.view_move_line_tree"/>
<field name="view_mode">account_move_line_search_extension,form</field>
</record>
<menuitem
action="action_account_move_line_search_extension"
icon="STOCK_JUSTIFY_FILL"
id="menu_account_move_line_search_extension"
parent="account.menu_finance_entries"
sequence="1"
groups="account.group_account_user"
/>
</data>
</openerp>

View File

@@ -0,0 +1,5 @@
.openerp .oe_form_char_section {
position: relative;
display: inline-block;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1,93 @@
openerp.account_move_line_search_extension = function (instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
instance.account_move_line_search_extension = {};
instance.web.views.add('account_move_line_search_extension', 'instance.account_move_line_search_extension.ListSearchView');
instance.account_move_line_search_extension.ListSearchView = instance.web.ListView.extend({
init: function() {
this._super.apply(this, arguments);
this.journals = [];
this.current_account = null;
this.current_partner = null;
this.current_journal = null;
this.current_period = null;
},
start:function(){
var tmp = this._super.apply(this, arguments);
var self = this;
this.$el.parent().prepend(QWeb.render('AccountMoveLineSearchExtension', {widget: this}));
this.$el.parent().find('.oe_account_select_account').change(function() {
self.current_account = this.value === '' ? null : this.value;
self.do_search(self.last_domain, self.last_context, self.last_group_by);
});
this.$el.parent().find('.oe_account_select_partner').change(function() {
self.current_partner = this.value === '' ? null : this.value;
self.do_search(self.last_domain, self.last_context, self.last_group_by);
});
this.$el.parent().find('.oe_account_select_journal').change(function() {
self.current_journal = this.value === '' ? null : parseInt(this.value);
//console.log('start, oasj, self.current_journal=', self.current_journal, 'self.last_domain=', self.last_domain, 'self.last_context=', self.last_context, 'self.last_group_by=', self.last_group_by);
self.do_search(self.last_domain, self.last_context, self.last_group_by);
});
this.$el.parent().find('.oe_account_select_period').change(function() {
self.current_period = this.value === '' ? null : this.value;
self.do_search(self.last_domain, self.last_context, self.last_group_by);
});
this.on('edit:after', this, function () {
self.$el.parent().find('.oe_account_select_account').attr('disabled', 'disabled');
self.$el.parent().find('.oe_account_select_partner').attr('disabled', 'disabled');
self.$el.parent().find('.oe_account_select_journal').attr('disabled', 'disabled');
self.$el.parent().find('.oe_account_select_period').attr('disabled', 'disabled');
});
this.on('save:after cancel:after', this, function () {
self.$el.parent().find('.oe_account_select_account').removeAttr('disabled');
self.$el.parent().find('.oe_account_select_partner').removeAttr('disabled');
self.$el.parent().find('.oe_account_select_journal').removeAttr('disabled');
self.$el.parent().find('.oe_account_select_period').removeAttr('disabled');
});
return tmp;
},
do_search: function(domain, context, group_by) {
var self = this;
this.last_domain = domain;
this.last_context = context;
this.last_group_by = group_by;
this.old_search = _.bind(this._super, this);
var aj_mod = new instance.web.Model('account.journal');
return $.when(aj_mod.query(['name']).all().then(function(result) {
self.journals = result;
})).then(function () {
var o;
self.$el.parent().find('.oe_account_select_journal').children().remove().end();
self.$el.parent().find('.oe_account_select_journal').append(new Option('', ''));
for (var i = 0;i < self.journals.length;i++){
o = new Option(self.journals[i].name, self.journals[i].id);
if (self.journals[i].id === self.current_journal){
$(o).attr('selected',true);
}
self.$el.parent().find('.oe_account_select_journal').append(o);
}
return self.search_by_selection();
});
},
search_by_selection: function() {
var self = this;
var domain = [];
if (self.current_account) domain.push(['account_id.code', 'ilike', self.current_account]);
if (self.current_partner) domain.push(['partner_id.name', 'ilike', self.current_partner],'|',['partner_id.parent_id','=',false],['partner_id.is_company','=',true]);
if (self.current_journal) domain.push(['journal_id', '=', self.current_journal]);
if (self.current_period) domain.push('|',['period_id.code', 'ilike', self.current_period],['period_id.name', 'ilike', self.current_period]);
//_.each(domain, function(x) {console.log('search_by_journal_period, domain_part = ', x)});
return self.old_search(new instance.web.CompoundDomain(self.last_domain, domain), self.last_context, self.last_group_by);
},
});
};

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="AccountMoveLineSearchExtension">
<div class="ui-toolbar" style="margin-bottom:0px;">
<div class="oe_form_char_section">
<h4>Account :</h4>
<input type="text" class="oe_account_select_account">
</input>
</div>
<div class="oe_form_char_section">
<h4>Partner :</h4>
<input type="text" class="oe_account_select_partner">
</input>
</div>
<div class="oe_form_dropdown_section">
<h4>Journal :</h4>
<select class="oe_account_select_journal">
</select>
</div>
<div class="oe_form_char_section">
<h4>Period :</h4>
<input type="text" class="oe_account_select_period">
</input>
</div>
</div>
</t>
</templates>