diff --git a/account_move_line_search_extension/__init__.py b/account_move_line_search_extension/__init__.py index 87623927b..d8798c3a5 100644 --- a/account_move_line_search_extension/__init__.py +++ b/account_move_line_search_extension/__init__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # -# Copyright (c) 2013-14 Noviat nv/sa (www.noviat.com). All rights reserved. +# 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 @@ -21,3 +21,4 @@ ############################################################################## from . import account +from . import ir_actions diff --git a/account_move_line_search_extension/__openerp__.py b/account_move_line_search_extension/__openerp__.py index 51a4f13dc..e09f0896b 100644 --- a/account_move_line_search_extension/__openerp__.py +++ b/account_move_line_search_extension/__openerp__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # -# Copyright (c) 2013-14 Noviat nv/sa (www.noviat.com). All rights reserved. +# 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 @@ -22,7 +22,7 @@ { 'name': 'Journal Items Search Extension', - 'version': '0.2', + 'version': '0.4', 'license': 'AGPL-3', 'author': 'Noviat', 'category': 'Accounting & Finance', diff --git a/account_move_line_search_extension/account.py b/account_move_line_search_extension/account.py index 85d8f0d59..58a638d72 100644 --- a/account_move_line_search_extension/account.py +++ b/account_move_line_search_extension/account.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # -# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. +# 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 @@ -22,6 +22,8 @@ from openerp.osv import orm from lxml import etree +import logging +_logger = logging.getLogger(__name__) class account_move_line(orm.Model): @@ -41,3 +43,22 @@ class account_move_line(orm.Model): 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 index 5318aa7dd..560a6e814 100644 --- a/account_move_line_search_extension/account_view.xml +++ b/account_move_line_search_extension/account_view.xml @@ -18,5 +18,16 @@ groups="account.group_account_user" /> + + amlse.view.move.line.tree + account.move.line + + + + False + + + + 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..1fd5246cd --- /dev/null +++ b/account_move_line_search_extension/ir_actions.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 +import logging +_logger = logging.getLogger(__name__) + + +class ir_actions_act_window(models.Model): + _inherit = 'ir.actions.act_window' + + def __init__(self, pool, 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() + self._amlse_act_id = res[0] + 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 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/static/src/img/icon.png b/account_move_line_search_extension/static/description/icon.png similarity index 100% rename from account_move_line_search_extension/static/src/img/icon.png rename to account_move_line_search_extension/static/description/icon.png 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 index 812421790..9945b1fce 100644 --- 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 @@ -1,3 +1,8 @@ +.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 index 8f5b2f80a..1e450c4c0 100644 --- 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 @@ -1,6 +1,4 @@ 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 = {}; @@ -9,24 +7,31 @@ openerp.account_move_line_search_extension = function (instance) { 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(){ + start: function(){ var tmp = this._super.apply(this, arguments); var self = this; - this.$el.parent().prepend(QWeb.render('AccountMoveLineSearchExtension', {widget: this})); + this.$el.parent().prepend(QWeb.render('AccountMoveLineSearchExtension', self.groups_dict)); 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); @@ -42,12 +47,14 @@ openerp.account_move_line_search_extension = function (instance) { }); this.on('edit:after', this, function () { self.$el.parent().find('.oe_account_select_account').attr('disabled', 'disabled'); + self.$el.parent().find('.oe_account_select_analytic_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_analytic_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'); @@ -55,6 +62,22 @@ openerp.account_move_line_search_extension = function (instance) { return tmp; }, + set_user_groups: function() { + var self = this; + var result = {}; + var action_context = this.dataset.get_context().__contexts[1]; + _.each(action_context, function(v,k) { + //console.log('init, k=', k, 'v=', v); + 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; @@ -83,6 +106,7 @@ openerp.account_move_line_search_extension = function (instance) { 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],'|',['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]); 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 index a22e1c7a8..09ce57a6c 100644 --- 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 @@ -1,27 +1,29 @@ - +
-

Account :

- - -
+

Account :

+ +
+ +
+

Analytic Account :

+ +
+
-

Partner :

- - +

Partner :

+
-

Journal :

- +

Journal :

+ - +

Period :

+