如何停止Qweb调用odoo9中计算字段的计算方法以生成结果?

时间:2018-08-16 10:31:47

标签: odoo odoo-9

我正在使用odoo9,我有一个具有计算字段的模型,这些字段也是可编辑的,因此用户可以更改值。但是,当生成此模型的PDF时,Qweb会调用计算方法并重新计算字段,因此它没有显示修改后的值。我不要这样的行为

1 个答案:

答案 0 :(得分:0)

要停止对计算字段的Qweb调用Compute方法,请像这样从db获取存储的值:

<openerp>
<data>
    <template id="payslip">
        <t t-call="report.html_container">
            <t t-foreach="docs" t-as="doc">
                <t t-foreach="doc.get_info(doc.id)" t-as="res">
                  <t t-set="name" t-value="res['name']"/>
                  <t t-set="designation" t-value="res['designation']"/>
                  <t t-set="required_hours" t-value="res['required_hours']"/>
                  <t t-set="regular_worked_hour" t-value="res['regular_worked_hour']"/>
                  <t t-set="vacation_credited" t-value="res['vacation_credited']"/>
                  <t t-set="vacation_encash" t-value="res['vacation_encash']"/>
                  <t t-set="overtime_hours" t-value="res['overtime_hours']"/>
                  <t t-set="work_from_home_hrs" t-value="res['work_from_home_hrs']"/>
                  <t t-set="total_plus_manual" t-value="res['total_plus_manual']"/>
                  <t t-set="total_this_period" t-value="res['total_this_period']"/>
                  <t t-set="mobile_allowance" t-value="res['mobile_allowance']"/>
                  <t t-set="internet_allowance" t-value="res['internet_allowance']"/>
                  <t t-set="bonus_amount" t-value="res['bonus_amount']"/>
                  <t t-set="net_salary" t-value="res['net_salary']"/>
                  <t t-set="salary_tax" t-value="res['salary_tax']"/>
                  <t t-set="vacation_opening_bal" t-value="res['vacation_opening_bal']"/>
                  <t t-set="advance_salary" t-value="res['advance_salary']"/>
                  <t t-set="vacation_earned" t-value="res['vacation_earned']"/>
                  <t t-set="loan_amount" t-value="res['loan_amount']"/>
                  <t t-set="vacation_taken" t-value="res['vacation_taken']"/>
                  <t t-set="salary_brought_forward" t-value="res['salary_brought_forward']"/>
                  <t t-set="vacation_encash" t-value="res['vacation_encash']"/>
                  <t t-set="salary_payable" t-value="res['salary_payable']"/>
                  <t t-set="vacation_closing_bal" t-value="res['vacation_closing_bal']"/>
                  <t t-set="join_date" t-value="res['join_date']"/>
                  <t t-set="month_name" t-value="res['month_name']"/>
                  <t t-set="pay_period" t-value="res['pay_period']"/>
                  <t t-set="stand_salary" t-value="res['stand_salary']"/>
                  <t t-set="monthly_rate" t-value="res['monthly_rate']"/>
                  <t t-set="hourly_rate" t-value="res['hourly_rate']"/>
                  <t t-set="stand_salary" t-value="res['stand_salary']"/>


                <div class="header">
                        <span>
                            <div class="row">
                            <div class="col-xs-3">
                                <strong>Name:</strong>
                            </div>

                            <div class="col-xs-3">
                                <span t-esc="name"/>
                            </div>
                            </div>

                        </span>


                        <span style="margin-top:-2px !important;">
                            <div class="row">
                            <div class="col-xs-3">
                                <strong>Designation:</strong>
                            </div>

                            <div class="col-xs-5">
                                <span t-esc="designation"/>
                            </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                            <div class="col-xs-3">
                                <strong>Appointment Date:</strong>
                            </div>

                            <div class="col-xs-3">
                                <span t-esc="join_date"/>
                            </div>
                            </div>
                        </span>

                        <span style="margin-top:0px;">
                            <div class="row">
                            <div class="col-xs-3">
                                <strong>Salary Type:</strong>
                            </div>

                            <div class="col-xs-5">
                                <span>Monthly/
                                    <span t-esc="month_name"/>
                                </span>
                            </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">

                            <div class="col-xs-3">
                                <strong>Pay Date:</strong>
                            </div>

                            <div class="col-xs-5">

                                <span t-esc="time.strftime('%B %d %Y')"/>
                            </div>

                            </div>
                        </span>

                        <span style="margin-top:0px;">
                            <div class="row">
                            <div class="col-xs-3">
                                <strong>Pay Period:</strong>
                            </div>

                            <div class="col-xs-5">
                                <span t-esc="pay_period"/>
                            </div>
                            </div>
                        </span>
                </div>

                    <div class="page" >

                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <strong>Standard Salary:</strong>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="stand_salary"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Current Monthly Basic Rate:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="monthly_rate"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Current Hourly Rate:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="hourly_rate"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Total Hours This Period:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="required_hours"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Regular Hours Worked This Period:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="regular_worked_hour"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Vacations Credited:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="vacation_credited"/>
                                </div>
                            </div>
                        </span>





                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Vacations Encash:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="vacation_encash"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Over Time Hours:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="overtime_hours"/>
                                </div>
                            </div>
                        </span>


                         <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Work from Home Hours:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="work_from_home_hrs"/>
                                </div>
                            </div>
                        </span>




                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Total Hours Payable:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="total_plus_manual"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Total For This Period:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="total_this_period"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Add: Mobile Allowance:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="mobile_allowance"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Add: Internet Allowance:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="internet_allowance"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Bonus:</span>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="bonus_amount"/>
                                </div>
                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">

                                <div class="col-xs-6">
                                    <strong>Net Salary (Round to Next 100):</strong>
                                </div>

                                <div class="col-xs-5">
                                    <span t-esc="net_salary"></span>
                                </div>


                            </div>


                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Less: Withholding Tax On Salary:</span>
                                </div>

                                <div class="col-xs-2">
                                    <span t-esc="salary_tax"></span>
                                </div>

                                <div class="col-xs-3">
                                    <span>Vacation Opening Bal</span>
                                </div>

                                <div class="col-xs-1">
                                    <span t-esc="vacation_opening_bal"></span>
                                </div>
                            </div>

                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Less: Advance Salary:</span>
                                </div>

                                <div class="col-xs-2">
                                    <span t-esc="advance_salary"></span>
                                </div>

                                <div class="col-xs-3">
                                    <span>Vacation Earned (+)</span>
                                </div>

                                <div class="col-xs-1">
                                    <span t-esc="vacation_earned"></span>
                                </div>


                            </div>
                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">

                                <div class="col-xs-6">
                                    <span>Less Loan:</span>
                                </div>

                                <div class="col-xs-2">
                                    <span t-esc="loan_amount"></span>
                                </div>


                                <div class="col-xs-3">
                                    <span>Vacation Taken (-)</span>
                                </div>

                                <div class="col-xs-1">
                                    <span t-esc="vacation_taken"></span>
                                </div>

                            </div>


                        </span>


                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <span>Carried Over to Next Month [Short (+) Excessive (-)]:</span>
                                </div>

                                <div class="col-xs-2">
                                    <span t-esc="salary_brought_forward"></span>
                                </div>
                                <div class="col-xs-3">
                                    <span>Vacation Encash (-)</span>
                                </div>

                                <div class="col-xs-1">
                                    <span t-esc="vacation_encash"></span>
                                </div>


                            </div>
                        </span>

                        <span style="margin-top:0px;">
                            <div class="row">
                                <div class="col-xs-6">
                                    <Strong>Salary Amount Payable:</Strong>
                                </div>

                                <div class="col-xs-2">
                                    <span t-esc="salary_payable"></span>
                                </div>

                                <div class="col-xs-3">
                                    <strong>Vacation Closing Bal</strong>
                                </div>

                                <div class="col-xs-1">

                                    <strong t-esc="vacation_closing_bal"></strong>
                                </div>

                            </div>
                        </span>


                    </div>


                </t>
            </t>
        </t>
    </template>

</data>

这个python代码:

    def get_info(self, id):

    data = self.env['payslip.deta'].search([("id", "=", id)])
    dict =  {'name': data.employee_id.name_related, 'designation':data.employee_id.job_id.name,\
             'required_hours': data.required_hours ,'regular_worked_hour':data.regular_worked_hour, \
             'vacation_credited':data.vacation_credited, 'vacation_encash':data.vacation_encash,\
             'overtime_hours':data.overtime_hours, 'work_from_home_hrs':data.work_from_home_hrs,\
             'total_plus_manual':data.total_plus_manual, 'total_this_period': data.total_this_period,\
             'mobile_allowance':data.mobile_allowance,'internet_allowance':data.internet_allowance,\
             'bonus_amount': data.bonus_amount, 'net_salary': data.net_salary, 'salary_tax':data.salary_tax,\
             'vacation_opening_bal':data.vacation_opening_bal, 'advance_salary':data.advance_salary,\
             'vacation_earned':data.vacation_earned, 'loan_amount': data.loan_amount,\
             'vacation_taken':data.vacation_credited,'salary_brought_forward':data.salary_brought_forward,\
             'vacation_encash':data.vacation_encash, 'vacation_closing_bal': data.vacation_closing_bal,\
             'salary_payable':data.get_net_salary_in_slip(),'join_date':data.get_emp_join_date(data.employee_id.join_date),\
             'month_name':data.get_month_name(data.month),'pay_period':data.get_pay_period_in_slip(data.year,data.month),
             'stand_salary':data.get_emp_stand_salary_in_slip(data.employee_id), 'monthly_rate':data.get_monthly_basic_rate_in_slip(),\
             'hourly_rate':data.get_hourly_rate_in_slip()

            }
    return [dict]