Merge pull request #110 from luc-demeyer/8.0-aml_search_extension-update

V8 port account_move_line_search_extension
This commit is contained in:
Pedro M. Baeza
2015-06-19 09:31:59 +02:00
12 changed files with 457 additions and 0 deletions

View File

@@ -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 <info@noviat.com>
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.

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import account
from . import res_partner
from . import ir_actions

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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',
],
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)

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, 'analytic_journal_id': 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,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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -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;
}

View File

@@ -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);
},
});
};

View File

@@ -0,0 +1,31 @@
<?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"/>
</div>
<t t-if="group_analytic">
<div class="oe_form_char_section">
<h4>Analytic Account :</h4>
<input type="text" class="oe_account_select_analytic_account"/>
</div>
</t>
<div class="oe_form_char_section">
<h4>Partner :</h4>
<input type="text" class="oe_account_select_partner"/>
</div>
<div class="oe_form_dropdown_section">
<h4>Journal :</h4>
<select class="oe_account_select_journal"/>
</div>
<div class="oe_form_char_section">
<h4>Period :</h4>
<input type="text" class="oe_account_select_period"/>
</div>
</div>
</t>
</templates>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/account_move_line_search_extension/static/src/css/account_move_line_search_extension.css"/>
<script type="text/javascript" src="/account_move_line_search_extension/static/src/js/account_move_line_search_extension.js"></script>
</xpath>
</template>
</data>
</openerp>