This question has been flagged
1 Reply
4104 Views

I am trying to add extra filter to show Not Reconcile only Aged Payable report.

Here is my phyton code:

class ReportAgedPartnerBalance(models.AbstractModel):
_inherit = 'report.account.report_agedpartnerbalance'

def _get_partner_move_lines(self, account_type, date_from, target_move, period_length):
if self._context.get('reconcile_filter') == 'not_reconcile':
raise UserError(_("not_reconcile!"))
class ReportAccountAgedPayable(models.AbstractModel):
_inherit = "account.aged.payable"

@api.model
def get_lines(self, context_id, line_id=None):
if type(context_id) == int:
context_id = self.env['account.context.aged.payable'].search([['id', '=', context_id]])
new_context = dict(self.env.context)
new_context.update({
'date_to': context_id.date_to,
'aged_balance': True,
'context_id': context_id,
'company_ids': context_id.company_ids.ids,
'account_type': 'payable',
'reconcile_filter': context_id.reconcile_filter
})
return self.with_context(new_context)._lines(context_id, line_id)


class AccountReportContextCommon(models.TransientModel):
_inherit = "account.report.context.common"

reconcile_filter = fields.Char('Reconcile Option')

@api.model
def create(self, vals):
res = super(AccountReportContextCommon, self).create(vals)
report_type = res.get_report_obj().get_report_type()
if not report_type.date_range:
res.update({'reconcile_filter': 'all'})
return res

I add the XML in account_report_backend

<?xml version="1.0" encoding="utf-8"?>
<templates>
<t t-extend="accountReports.searchView" name="account_filter.searchView_inherit">
<t t-jquery=".o_account_reports_date-filter" t-operation="prepend">
<div class="btn-group o_dropdown o_account_reports_filter-reconcile_filter" t-if="!report_type.date_range">
<a type="button" class="dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-filter"/> Reconcile:
<t t-if="context.reconcile_filter == 'all'">All</t>
<t t-if="context.reconcile_filter == 'not_reconcile'">Not Reconciled</t>
<span class="caret"/>
</a>
<ul class="dropdown-menu o_filters_menu" role="menu">
<li title="All" data-value="all"
t-att-class="'o_account_reports_one-reconcile_filter ' + (context.reconcile_filter == 'all' and 'selected' or '')">
<a>Reconcile: All</a>
</li>
<li title="Not Reconciled" data-value="not_reconcile"
t-att-class="'o_account_reports_one-reconcile_filter ' + (context.reconcile_filter == 'not_reconcile' and 'selected' or '')">
<a>Reconcile: Not Reconciled</a>
</li>
</ul>
</div>
</t>
</t>
</templates>

And Here are the JS code

    var QWeb = core.qweb;

var account_reports_filters = Widget.extend(ControlPanelMixin,{

render_searchview_buttons: function() {
var self = this;

this.$searchview_buttons = $(QWeb.render("accountReports.searchView", {report_type: this.report_type, context: this.report_context}));
this.$searchview_buttons.find('.o_account_reports_one-reconcile_filter').bind('click', function (event)
{
var report_context = {};
var reconcile_filter = $(event.target).parents('li').data('value');
report_context.reconcile_filter = reconcile_filter;
self.restart(report_context);
});

return this.$searchview_buttons;
},

get_html : function() {
var result = this._super();
if (result.report_context) {
result.report_context.reconcile_filter = result.reconcile_filter;
}
return result;
},

});

core.action_registry.add("account_reports_filters", account_reports_filters);
return account_reports_filters;

}

The button shows but I can't click it and I don't think that button is register in correct manner. 

Please help, I have been stuck with this for awhile. Thank you.

Avatar
Discard

Hello there, did you find any solution?