单击按钮时展开组

时间:2017-10-17 06:05:57

标签: javascript xml python-2.7 odoo-10

我正在使用会员 - >关于企业的总帐管理系统,其中名称下有组列表。我正在做的是我在那里制作了按钮,并希望该按钮在单击时展开所有名称列表。目前,当我点击它显示"未命名"我无法确定其原因:

请看图片:

enter image description here

按钮的xml文件:

<?xml version="1.0" encoding="UTF-8"?>



<templates>

    <t t-extend="accountReports.buttons">

        <t t-jquery="[t-if*='xml_export']" t-operation="before">

            <button t-if="report_name == 'account.context.general.ledger'" type="button" class='btn btn-primary btn-sm o_account-widget-expand'>Expand Lines</button>

        </t>

    </t>



</templates>

javascript文件

this.$buttons.siblings('.o_account-widget-expand').bind('click', function () {

            //session.user_context.expand_all = true;

            var expand = false;

            if (self.given_context.expand_all) {

                expand=false;

            }

            else

            {

                expand=true;

            }

            self.do_action({

                type: 'ir.actions.client',

                tag: 'account_report_generic',

                context: {'url': '/account_reports/output_format/general_ledger/1', 'model': 'account.general.ledger','context':{'from_button':true,'expand_all':expand}},

                });

            });

        return this.$buttons;

python :

class account_context_general_ledger(models.TransientModel):

    _inherit= "account.context.general.ledger"



    @api.multi

    def get_html_and_data(self, given_context=None):

        if given_context is None:

            given_context = {}

        result = {}

        if given_context:

            if 'force_account' in given_context and (not self.date_from or self.date_from == self.date_to):

                self.date_from = self.env.user.company_id.compute_fiscalyear_dates(datetime.strptime(self.date_to, "%Y-%m-%d"))['date_from']

                self.date_filter = 'custom'

        lines = self.get_report_obj().get_lines(self)





        ctx = self._context.copy()

        if given_context.get('from_button'):

            ctx.update({'expand_all':given_context.get('expand_all')})

            self = self.with_context(ctx)



        rcontext = {

            'res_company': self.env['res.users'].browse(self.env.uid).company_id,

            'context': self.with_context(**given_context), # context? rcontext with_context! Haaa... given_context!

            'report': self.get_report_obj(),

            'lines': lines,

            'footnotes': self.get_footnotes_from_lines(lines),

            'mode': 'display',

        }

        result['html'] = self.env['ir.model.data'].xmlid_to_object(self.get_report_obj().get_template()).render(rcontext)

        result['report_type'] = self.get_report_obj().get_report_type().read(['date_range', 'comparison', 'cash_basis', 'analytic', 'extra_options'])[0]

        select = ['id', 'date_filter', 'date_filter_cmp', 'date_from', 'date_to', 'periods_number', 'date_from_cmp', 'date_to_cmp', 'cash_basis', 'all_entries', 'company_ids', 'multi_company', 'hierarchy_3', 'analytic']

        if self.get_report_obj().get_name() == 'general_ledger':

            select += ['journal_ids']

            result['available_journals'] = self.get_available_journal_ids_names_and_codes()

        if self.get_report_obj().get_name() == 'partner_ledger':

            select += ['account_type']

        result['report_context'] = self.read(select)[0]

        result['report_context'].update(self._context_add())

        result['report_context'].update({'report_name':self._name})

        if result['report_type']['analytic']:

            result['report_context']['analytic_account_ids'] = [(t.id, t.name) for t in self.analytic_account_ids]

            result['report_context']['analytic_tag_ids'] = [(t.id, t.name) for t in self.analytic_tag_ids]

            result['report_context']['available_analytic_account_ids'] = self.analytic_manager_id.get_available_analytic_account_ids_and_names()

            result['report_context']['available_analytic_tag_ids'] = self.analytic_manager_id.get_available_analytic_tag_ids_and_names()

        result['xml_export'] = self.env['account.financial.html.report.xml.export'].is_xml_export_available(self.get_report_obj())

        result['fy'] = {

            'fiscalyear_last_day': self.env.user.company_id.fiscalyear_last_day,

            'fiscalyear_last_month': self.env.user.company_id.fiscalyear_last_month,

        }

        result['available_companies'] = self.multicompany_manager_id.get_available_company_ids_and_names()

        return result

0 个答案:

没有答案