add analytic + fix tree/form view switch

This commit is contained in:
luc-demeyer
2015-03-09 10:14:26 +01:00
parent 1674f95e5a
commit 532c3167a7
9 changed files with 148 additions and 22 deletions

View File

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

View File

@@ -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',

View File

@@ -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)

View File

@@ -18,5 +18,16 @@
groups="account.group_account_user"
/>
<record id="amlse_view_move_line_tree" model="ir.ui.view">
<field name="name">amlse.view.move.line.tree</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree"/>
<field name="arch" type="xml">
<field name="analytic_account_id" position="attributes">
<attribute name="invisible">False</attribute>
</field>
</field>
</record>
</data>
</openerp>

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
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

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

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

View File

@@ -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]);

View File

@@ -1,27 +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>
<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">
</input>
<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">
</select>
<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">
</input>
<h4>Period :</h4>
<input type="text" class="oe_account_select_period"/>
</div>
</div>
</t>