diff --git a/account_move_line_search_extension/README.rst b/account_move_line_search_extension/README.rst new file mode 100644 index 000000000..de57bebfd --- /dev/null +++ b/account_move_line_search_extension/README.rst @@ -0,0 +1,39 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +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. + +The purpose of this view is to offer a fast drill down capability +when searching through large number of accounting entries. + +The drill down is facilitated further by opening the Form View when clicking on +the sought-after entry. +This allows an intuitive click-through to the related accounting documents +such as the originating Bank Statement, Invoice, Asset, ... + +Credits +======= + +Author +------ +* Luc De Meyer, Noviat + +Maintainer +---------- +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/account_move_line_search_extension/__init__.py b/account_move_line_search_extension/__init__.py new file mode 100644 index 000000000..edb26d42a --- /dev/null +++ b/account_move_line_search_extension/__init__.py @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2013-2015 Noviat nv/sa (www.noviat.com). +# +# 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 . +# +############################################################################## + +from . import account +from . import res_partner +from . import ir_actions diff --git a/account_move_line_search_extension/__openerp__.py b/account_move_line_search_extension/__openerp__.py new file mode 100644 index 000000000..5b9e98e12 --- /dev/null +++ b/account_move_line_search_extension/__openerp__.py @@ -0,0 +1,37 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2013-2015 Noviat nv/sa (www.noviat.com). +# +# 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 . +# +############################################################################## + +{ + 'name': 'Journal Items Search Extension', + 'version': '0.6', + 'license': 'AGPL-3', + 'author': 'Noviat, Odoo Community Association (OCA)', + 'category': 'Accounting & Finance', + 'depends': ['account'], + 'data': [ + 'account_view.xml', + 'views/account.xml', + ], + 'qweb': [ + 'static/src/xml/account_move_line_search_extension.xml', + ], +} diff --git a/account_move_line_search_extension/account.py b/account_move_line_search_extension/account.py new file mode 100644 index 000000000..a21db3b7e --- /dev/null +++ b/account_move_line_search_extension/account.py @@ -0,0 +1,62 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2013-2015 Noviat nv/sa (www.noviat.com). +# +# 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 . +# +############################################################################## + +from openerp import models +from lxml import etree + + +class account_move_line(models.Model): + _inherit = 'account.move.line' + + def fields_view_get(self, cr, uid, view_id=None, view_type='form', + context=None, toolbar=False, submenu=False): + res = super(account_move_line, self).fields_view_get( + cr, uid, view_id=view_id, view_type=view_type, + context=context, toolbar=toolbar, submenu=False) + if context and 'account_move_line_search_extension' in context \ + and view_type == 'tree': + doc = etree.XML(res['arch']) + nodes = doc.xpath("/tree") + for node in nodes: + if 'editable' in node.attrib: + del node.attrib['editable'] + res['arch'] = etree.tostring(doc) + return res + + def search(self, cr, uid, args, offset=0, limit=None, order=None, + context=None, count=False): + if context and 'account_move_line_search_extension' in context: + ana_obj = self.pool['account.analytic.account'] + for arg in args: + if arg[0] == 'analytic_account_id': + ana_dom = ['|', + ('name', 'ilike', arg[2]), + ('code', 'ilike', arg[2])] + ana_ids = ana_obj.search( + cr, uid, ana_dom, context=context) + ana_ids = ana_obj.search( + cr, uid, [('id', 'child_of', ana_ids)]) + arg[2] = ana_ids + break + return super(account_move_line, self).search( + cr, uid, args, offset=offset, limit=limit, order=order, + context=context, count=count) diff --git a/account_move_line_search_extension/account_view.xml b/account_move_line_search_extension/account_view.xml new file mode 100644 index 000000000..a375d5bdb --- /dev/null +++ b/account_move_line_search_extension/account_view.xml @@ -0,0 +1,22 @@ + + + + + + {'account_move_line_search_extension': 1, 'analytic_journal_id': 1} + Journal Items Search All + account.move.line + + account_move_line_search_extension,form + + + + + diff --git a/account_move_line_search_extension/ir_actions.py b/account_move_line_search_extension/ir_actions.py new file mode 100644 index 000000000..ef3a30fdd --- /dev/null +++ b/account_move_line_search_extension/ir_actions.py @@ -0,0 +1,65 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2013-2015 Noviat nv/sa (www.noviat.com). +# +# 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 . +# +############################################################################## + +from openerp import models + + +class ir_actions_act_window(models.Model): + _inherit = 'ir.actions.act_window' + + def _get_amlse_act_id(self, cr): + module = 'account_move_line_search_extension' + xml_id = 'action_account_move_line_search_extension' + cr.execute( + "SELECT res_id from ir_model_data " + "WHERE model = 'ir.actions.act_window' " + "AND module = %s AND name = %s ", + (module, xml_id)) + res = cr.fetchone() + return res and res[0] + + def __init__(self, pool, cr): + self._amlse_act_id = self._get_amlse_act_id(cr) + super(ir_actions_act_window, self).__init__(pool, cr) + + def _amlse_add_groups(self, cr, uid, context): + groups = {} + if self.pool['res.users'].has_group( + cr, uid, 'analytic.group_analytic_accounting'): + groups['group_analytic'] = 1 + return groups + + def read(self, cr, uid, ids, fields=None, + context=None, load='_classic_read'): + if not context: + context = {} + res = super(ir_actions_act_window, self).read( + cr, uid, ids, fields=fields, context=context, load=load) + if not self._amlse_act_id: + self._amlse_act_id = self._get_amlse_act_id(cr) + if ids == [self._amlse_act_id]: + amlse_act = res[0] + if amlse_act.get('context'): + act_ctx = eval(amlse_act['context']) + act_ctx.update(self._amlse_add_groups(cr, uid, context)) + amlse_act['context'] = str(act_ctx) + return res diff --git a/account_move_line_search_extension/res_partner.py b/account_move_line_search_extension/res_partner.py new file mode 100644 index 000000000..1746d2a4d --- /dev/null +++ b/account_move_line_search_extension/res_partner.py @@ -0,0 +1,41 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2015 Noviat nv/sa (www.noviat.com). +# +# 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 . +# +############################################################################## + +from openerp import models + + +class res_partner(models.Model): + _inherit = 'res.partner' + + def search(self, cr, uid, args, + offset=0, limit=None, order=None, context=None, count=False): + if context and 'account_move_line_search_extension' in context: + args.extend( + ['|', + ('parent_id', '=', False), + ('is_company', '=', True), + '|', + ('active', '=', False), + ('active', '=', True)]) + return super(res_partner, self).search( + cr, uid, args, offset=offset, limit=limit, order=order, + context=context, count=count) diff --git a/account_move_line_search_extension/static/description/icon.png b/account_move_line_search_extension/static/description/icon.png new file mode 100644 index 000000000..214166a26 Binary files /dev/null and b/account_move_line_search_extension/static/description/icon.png differ diff --git a/account_move_line_search_extension/static/src/css/account_move_line_search_extension.css b/account_move_line_search_extension/static/src/css/account_move_line_search_extension.css new file mode 100644 index 000000000..9945b1fce --- /dev/null +++ b/account_move_line_search_extension/static/src/css/account_move_line_search_extension.css @@ -0,0 +1,10 @@ +.openerp .oe_vm_switch_account_move_line_search_extension:after { + padding: 2px; + content: "i"; +} + +.openerp .oe_form_char_section { + position: relative; + display: inline-block; +} + diff --git a/account_move_line_search_extension/static/src/js/account_move_line_search_extension.js b/account_move_line_search_extension/static/src/js/account_move_line_search_extension.js new file mode 100644 index 000000000..effa8b0ec --- /dev/null +++ b/account_move_line_search_extension/static/src/js/account_move_line_search_extension.js @@ -0,0 +1,112 @@ +openerp.account_move_line_search_extension = function (instance) { + 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() { + var self = this; + this._super.apply(this, arguments); + this.journals = []; + this.current_account = null; + this.current_analytic_account = null; + this.current_partner = null; + this.current_journal = null; + this.current_period = null; + this.options.addable = false; + this.set_user_groups(); + }, + + start: function(){ + var tmp = this._super.apply(this, arguments); + var self = this; + this.$el.parent().prepend(QWeb.render('AccountMoveLineSearchExtension', self.groups_dict)); + self.set_change_events(); + return tmp; + }, + + set_change_events: function() { + var self = 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_analytic_account').change(function() { + self.current_analytic_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); + 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); + }); + }, + + set_user_groups: function() { + var self = this; + var result = {}; + var action_context = this.dataset.get_context().__contexts[1]; + _.each(action_context, function(v,k) { + if (k[v] && (k.slice(0, 6) === "group_")) { + result[k] = true; + } + else { + result[k] = false; + }; + }); + self.groups_dict = result; + }, + + 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(); + }); + }, + + aml_search_domain: function() { + var self = this; + var domain = []; + if (self.current_account) domain.push(['account_id.code', 'ilike', self.current_account]); + if (self.current_analytic_account) domain.push(['analytic_account_id', 'in', self.current_analytic_account]); //cf. def search + if (self.current_partner) domain.push(['partner_id.name', 'ilike', self.current_partner]); + 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('amlse, aml_search_domain, domain_part = ', x)}); + return domain; + }, + + search_by_selection: function() { + var self = this; + var domain = self.aml_search_domain(); + return self.old_search(new instance.web.CompoundDomain(self.last_domain, domain), self.last_context, self.last_group_by); + }, + + }); +}; diff --git a/account_move_line_search_extension/static/src/xml/account_move_line_search_extension.xml b/account_move_line_search_extension/static/src/xml/account_move_line_search_extension.xml new file mode 100644 index 000000000..09ce57a6c --- /dev/null +++ b/account_move_line_search_extension/static/src/xml/account_move_line_search_extension.xml @@ -0,0 +1,31 @@ + + + + +
+
+

Account :

+ +
+ +
+

Analytic Account :

+ +
+
+
+

Partner :

+ +
+
+

Journal :

+ +
+
+
+ +
diff --git a/account_move_line_search_extension/views/account.xml b/account_move_line_search_extension/views/account.xml new file mode 100644 index 000000000..8d53d60f0 --- /dev/null +++ b/account_move_line_search_extension/views/account.xml @@ -0,0 +1,13 @@ + + + + + + + +