콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
7425 화면

Dear all,

I am using Odoo 12.

How can I have the "Print" menu option to call a function instead of directly call the qweb template.

For instance:

In core Odoo we have:

1. Report (creates the Print menu option and calls the qweb template)

    <report
          id="account_invoices" 
          model="account.invoice"
          string="Invoices"
          report_type="qweb-pdf"
          name="account.report_invoice_with_payments"
          file="account.report_invoice_with_payments"
          attachment="(object.state in ('open','in_payment','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
          print_report_name="(object._get_report_base_filename())"
          groups="account.group_account_invoice"
    />

2. Function inside Python module:

    @api.multi
    def invoice_print(self):
        self.filtered(lambda inv: not inv.sent).write({'sent': True})
        if self.user_has_groups('account.group_account_invoice'):
            return self.env.ref('account.account_invoices').report_action(self)
        else:
            return self.env.ref('account.account_invoices_without_payment').report_action(self)

The above function is called by a button on the invoice form and I want to have the print menu option to call this function too instead of directly call the qweb template shown on point 1?

Thank you all in advance

Best regards

PM



아바타
취소
베스트 답변

you have to create server action for it like
https://github.com/odoo/odoo/blob/12.0/addons/mrp_bom_cost/views/product_views.xml#L57

I think server action couldn't return action implicitly like button type object. so you have to assign an action to action variable and odoo server action code executer/sandbox will return it internally/explicitly 

like
action = self.env.ref('account.account_invoices').report_action(self)​

아바타
취소
작성자

Thank you @Ravi

Can you please help me with a sample code?

You refer I have to create a server action but I do not know where to apply this action to.

Thank you in advance

Best regards

PM

you don't need to apply this action it will automatically register and show in action menu of the top bar

https://ibb.co/KFQbhFd

베스트 답변

Hi,

you can use t-set to call function

<t t-set="result_function" t-value="request.env['model.name'].function()"/>

<t t-esc="result_function"/>

i hope yhis will helpful for you.


아바타
취소
관련 게시물 답글 화면 활동
1
1월 20
4309
2
11월 19
4628
2
12월 19
4942
1
2월 19
9769
1
5월 23
2198