Skip to content

Commit

Permalink
Merge d347aa3 into 348fb04
Browse files Browse the repository at this point in the history
  • Loading branch information
i-vyshnevska committed May 18, 2019
2 parents 348fb04 + d347aa3 commit 7665006
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 160 deletions.
@@ -1,54 +1,57 @@
odoo.define('account_financial_report.account_financial_report_backend', function (require) {
'use strict';
'use strict';

var core = require('web.core');
var Widget = require('web.Widget');
var ControlPanelMixin = require('web.ControlPanelMixin');
var ReportWidget = require('account_financial_report.account_financial_report_widget');
var core = require('web.core');
var Widget = require('web.Widget');
var ControlPanelMixin = require('web.ControlPanelMixin');
var ReportWidget = require(
'account_financial_report.account_financial_report_widget'
);


var report_backend = Widget.extend(ControlPanelMixin, {
// Stores all the parameters of the action.
events: {
'click .o_account_financial_reports_print': 'print',
'click .o_account_financial_reports_export': 'export',
},
init: function(parent, action) {
this.actionManager = parent;
this.given_context = {};
this.odoo_context = action.context;
this.controller_url = action.context.url;
if (action.context.context) {
this.given_context = action.context.context;
}
this.given_context.active_id = action.context.active_id || action.params.active_id;
this.given_context.model = action.context.active_model || false;
this.given_context.ttype = action.context.ttype || false;
return this._super.apply(this, arguments);
},
willStart: function() {
return $.when(this.get_html());
},
set_html: function() {
var self = this;
var def = $.when();
if (!this.report_widget) {
this.report_widget = new ReportWidget(this, this.given_context);
def = this.report_widget.appendTo(this.$el);
}
def.then(function () {
self.report_widget.$el.html(self.html);
});
},
start: function() {
this.set_html();
return this._super();
},
// Fetches the html and is previous report.context if any, else create it
get_html: function() {
var self = this;
var defs = [];
return this._rpc({
var report_backend = Widget.extend(ControlPanelMixin, {
// Stores all the parameters of the action.
events: {
'click .o_account_financial_reports_print': 'print',
'click .o_account_financial_reports_export': 'export',
},
init: function (parent, action) {
this.actionManager = parent;
this.given_context = {};
this.odoo_context = action.context;
this.controller_url = action.context.url;
if (action.context.context) {
this.given_context = action.context.context;
}
this.given_context.active_id = action.context.active_id ||
action.params.active_id;
this.given_context.model = action.context.active_model || false;
this.given_context.ttype = action.context.ttype || false;
return this._super.apply (this, arguments);
},
willStart: function () {
return $.when(this.get_html());
},
set_html: function () {
var self = this;
var def = $.when();
if (!this.report_widget) {
this.report_widget = new ReportWidget(this, this.given_context);
def = this.report_widget.appendTo(this.$el);
}
def.then(function () {
self.report_widget.$el.html(self.html);
});
},
start: function() {
this.set_html();
return this._super();
},
// Fetches the html and is previous report.context if any, else create it
get_html: function() {
var self = this;
var defs = [];
return this._rpc({
model: this.given_context.model,
method: 'get_html',
args: [self.given_context],
Expand All @@ -59,46 +62,50 @@ var report_backend = Widget.extend(ControlPanelMixin, {
defs.push(self.update_cp());
return $.when.apply($, defs);
});
},
// Updates the control panel and render the elements that have yet to be rendered
update_cp: function() {
if (this.$buttons) {
var status = {
breadcrumbs: this.actionManager.get_breadcrumbs(),
cp_content: {$buttons: this.$buttons},
};
return this.update_control_panel(status);
}
},
do_show: function() {
this._super();
this.update_cp();
},
print: function() {
var self = this;
this._rpc({
model: this.given_context.model,
method: 'print_report',
args: [this.given_context.active_id, 'qweb-pdf'],
context: self.odoo_context,
}).then(function(result){
self.do_action(result);
});
},
export: function() {
var self = this;
this._rpc({
model: this.given_context.model,
method: 'print_report',
args: [this.given_context.active_id, 'xlsx'],
context: self.odoo_context,
})
.then(function(result){
self.do_action(result);
});
},
});
},
// Updates the control panel and render the elements that have yet
// to be rendered
update_cp: function () {
if (this.$buttons) {
var status = {
breadcrumbs: this.actionManager.get_breadcrumbs(),
cp_content: {$buttons: this.$buttons},
};
return this.update_control_panel(status);
}
},
do_show: function () {
this._super();
this.update_cp();
},
print: function () {
var self = this;
this._rpc({
model: this.given_context.model,
method: 'print_report',
args: [this.given_context.active_id, 'qweb-pdf'],
context: self.odoo_context,
}).then(function(result){
self.do_action(result);
});
},
export: function () {
var self = this;
this._rpc({
model: this.given_context.model,
method: 'print_report',
args: [this.given_context.active_id, 'xlsx'],
context: self.odoo_context,
})
.then(function(result){
self.do_action(result);
});
},
});

core.action_registry.add("account_financial_report_backend", report_backend);
return report_backend;
core.action_registry.add(
"account_financial_report_backend",
report_backend
);
return report_backend`;
});
@@ -1,69 +1,73 @@
odoo.define('account_financial_report.account_financial_report_widget', function
(require) {
'use strict';
'use strict';

var Widget = require('web.Widget');
var Widget = require('web.Widget');


var accountFinancialReportWidget = Widget.extend({
events: {
'click .o_account_financial_reports_web_action': 'boundLink',
'click .o_account_financial_reports_web_action_multi': 'boundLinkmulti',
'click .o_account_financial_reports_web_action_monetary': 'boundLinkMonetary',
'click .o_account_financial_reports_web_action_monetary_multi': 'boundLinkMonetarymulti',
},
init: function() {
this._super.apply(this, arguments);
},
start: function() {
return this._super.apply(this, arguments);
},
boundLink: function(e) {
var res_model = $(e.target).data('res-model');
var res_id = $(e.target).data('active-id');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
res_id: res_id,
views: [[false, 'form']],
target: 'current'
});
},
boundLinkmulti: function(e) {
var res_model = $(e.target).data('res-model');
var domain = $(e.target).data('domain');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
domain: domain,
views: [[false, "list"], [false, "form"]],
target: 'current'
});
},
boundLinkMonetary: function(e) {
var res_model = $(e.target.parentElement).data('res-model');
var res_id = $(e.target.parentElement).data('active-id');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
res_id: res_id,
views: [[false, 'form']],
target: 'current'
});
},
boundLinkMonetarymulti: function(e) {
var res_model = $(e.target.parentElement).data('res-model');
var domain = $(e.target.parentElement).data('domain');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
domain: domain,
views: [[false, "list"], [false, "form"]],
target: 'current'
});
},
});
var accountFinancialReportWidget = Widget.extend({
events: {
'click .o_account_financial_reports_web_action':
'boundLink',
'click .o_account_financial_reports_web_action_multi':
'boundLinkmulti',
'click .o_account_financial_reports_web_action_monetary':
'boundLinkMonetary',
'click .o_account_financial_reports_web_action_monetary_multi':
'boundLinkMonetarymulti',
},
init: function () {
this._super.apply(this, arguments);
},
start: function () {
return this._super.apply(this, arguments);
},
boundLink: function (e) {
var res_model = $(e.target).data('res-model');
var res_id = $(e.target).data('active-id');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
res_id: res_id,
views: [[false, 'form']],
target: 'current',
});
},
boundLinkmulti: function (e) {
var res_model = $(e.target).data('res-model');
var domain = $(e.target).data('domain');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
domain: domain,
views: [[false, "list"], [false, "form"]],
target: 'current',
});
},
boundLinkMonetary: function (e) {
var res_model = $(e.target.parentElement).data('res-model');
var res_id = $(e.target.parentElement).data('active-id');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
res_id: res_id,
views: [[false, 'form']],
target: 'current',
});
},
boundLinkMonetarymulti: function (e) {
var res_model = $(e.target.parentElement).data('res-model');
var domain = $(e.target.parentElement).data('domain');
return this.do_action({
type: 'ir.actions.act_window',
res_model: res_model,
domain: domain,
views: [[false, "list"], [false, "form"]],
target: 'current',
});
},
});

return accountFinancialReportWidget;
return accountFinancialReportWidget;

});
55 changes: 55 additions & 0 deletions account_financial_report/tests/test_general_ledger.py
Expand Up @@ -4,6 +4,7 @@

import time

from odoo.api import Environment
from odoo.tests import common
from . import abstract_test_foreign_currency as a_t_f_c

Expand Down Expand Up @@ -493,3 +494,57 @@ def test_04_unaffected_account_balance_2_years(self):
self.assertEqual(lines['unaffected'].final_debit, 500)
self.assertEqual(lines['unaffected'].final_credit, 0)
self.assertEqual(lines['unaffected'].final_balance, 500)

def test_partner_filter(self):
partner_1 = self.env.ref('base.res_partner_1')
partner_2 = self.env.ref('base.res_partner_2')
partner_3 = self.env.ref('base.res_partner_3')
partner_4 = self.env.ref('base.res_partner_4')
partner_1.write({'is_company': False,
'parent_id': partner_2.id})
partner_3.write({'is_company': False})

expected_list = [partner_2.id, partner_3.id, partner_4.id]
context = {
'active_ids': [
partner_1.id, partner_2.id, partner_3.id, partner_4.id
],
'active_model': 'res.partner'
}

wizard = self.env["general.ledger.report.wizard"].with_context(context)
self.assertEqual(wizard._default_partners(), expected_list)

def test_validate_date(self):
company_id = self.env.ref('base.main_company')
company_id.write({
'fiscalyear_last_day': 31,
'fiscalyear_last_month': 12,
})
cr = self.registry.cursor()
user = self.env.ref('base.user_root').with_context({
'company_id': company_id.id})
env = Environment(cr, user.id, {})
wizard = env["general.ledger.report.wizard"]
self.assertEqual(wizard._init_date_from(),
time.strftime('%Y') + '-01-01')

def test_validate_date_range(self):
type = self.env['date.range.type'].create({
'name': 'Fiscal year',
'company_id': False,
'allow_overlap': False
})

dr = self.env['date.range'].create({
'name': 'FS2015',
'date_start': '2018-01-01',
'date_end': '2018-12-31',
'type_id': type.id,
})

wizard = self.env["general.ledger.report.wizard"].create({
'date_range_id': dr.id})
wizard.onchange_date_range_id()
self.assertEqual(wizard.date_from, '2018-01-01')
self.assertEqual(wizard.date_to, '2018-12-31')

0 comments on commit 7665006

Please sign in to comment.