我有一行求和上面所有的值,但我想不接受值与'cancel'状态
这是我的python代码,用于定义我的状态
sale_order_draft_ids = self.sale_order_draft_ids.ids
sale_order_draft_ids = list(set(sale_order_draft_ids))
sale_draft_ids = self.env['sale.order'].sudo().browse(sale_order_draft_ids)
repartition_sales_d = {}
for sale in sale_draft_ids:
my_state = dict(self.env['sale.order']._fields['state'].selection).get(sale.state)
repartition_sales_d[sale.id] = dict(
sale_draft_id=sale.id,
sale_number=sale.sale_number,
sale_name=sale.name,
sale_title=sale.sale_title,
sale_state=my_state,
sale_amount=sale.amount_untaxed,
sale_paid=sale.invoice_amount_total,
date_order=sale.date_order,
)
values['repartition_sales_d'] = repartition_sales_d
这是我试过但不工作,我不明白
<t t-if="sale['sale_state'] != 'cancel'">
<tr>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:white !important;color:white;">
</td>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:white !important;color:white;">
</td>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:white !important;color:white;"/>
<td class="text-right" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;">
<t t-set="sum_amount_and_report" t-value="sum_amount_and_report+ sum_amount + sum_report"/>
<t t-esc="'{:,}'.format(int(sum_amount_and_report)).replace(',', ' ')"/> €
</td>
<td class="text-right" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;">
<t t-esc="'{:,}'.format(int(sum_paid)).replace(',', ' ')"/> €
</td>
<td class="text-right" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;">
<t t-if="sum_amount > 0">
<t t-set="sum_percent" t-value="(sum_paid/sum_amount) * 100"/>
</t>
<t t-esc="'{:,}'.format(int(sum_percent)).replace(',', ' ')"/> %
</td>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;"/>
</tr>
</t>
</t>
这是完整的模板问我的qweb,我尝试了很多东西,但没有工作,我想了解。每次我都得到同样的错误。抛出qwebeexception ("Error)来渲染编译ast, e, path, node和tree。Tostring (node[0], encoding='unicode'), name)除了">
<t t-set="sum_amount_and_report" t-value="0"/>
<t t-set="sum_amount" t-value="0"/>
<t t-set="sum_report" t-value="0"/>
<t t-set="sum_paid" t-value="0"/>
<t t-set="sum_percent" t-value="0"/>
<t t-set="sale_percent" t-value="0"/>
<t t-set="sale_paid" t-value="0"/>
<t t-if="repartition_sales_d">
<t t-foreach="repartition_sales_d" t-as="sale_draft_id">
<t t-set="sale" t-value="repartition_sales_d[sale_draft_id]"/>
<tr>
<td class="text-center">
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98">
<t t-esc="sale['sale_number']"/>
</a>
</td>
<td class="text-center">
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98" style="text-decoration: none !important;color:#666666;">
<t t-esc="sale['date_order']"/>
</a>
</td>
<td class="text-center">
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98" style="text-decoration: none !important;color:#666666;">
<t t-esc="sale['sale_title']"/>
</a>
</td>
<td class="text-center">
<t t-set="sum_amount" t-value="sum_amount + int(sale['sale_amount'])"/>
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98" style="text-decoration: none !important;color:#666666;">
<t t-esc="'{:,}'.format(int(sale['sale_amount'])).replace(',', ' ')"/> €
</a>
</td>
<td class="text-center">
<t t-set="sum_paid" t-value="sum_paid + int(sale['sale_paid'])"/>
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98" style="text-decoration: none !important;color:#666666;">
<t t-esc="'{:,}'.format(int(sale['sale_paid'])).replace(',', ' ')"/> €
</a>
</td>
<td class="text-center">
<t t-if="int(sale['sale_amount']) > 0">
<t t-set="sale_percent" t-value="int(sale['sale_paid']) / (int(sale['sale_amount'])) * 100"/>
</t>
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98" style="text-decoration: none !important;color:#666666;">
<t t-esc="'{:,}'.format(int(sale_percent)).replace(',', ' ')"/> %
</a>
</td>
<td class="text-center">
<a t-attf-href="/web#id=#{sale['sale_draft_id']}&active_id=#{sale['sale_draft_id']}&model=sale.order&view_type=form&cids=&menu_id=98" style="text-decoration: none !important;color:#666666;">
<t t-if="sale['sale_state'] != 'cancel'">
<t t-esc="sale['sale_state']"/>
</t>
</a>
</td>
</tr>
</t>
</t>
<tr>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:white !important;color:white;">
</td>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:white !important;color:white;">
</td>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:white !important;color:white;"/>
<td class="text-right" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;">
<t t-set="sum_amount_and_report" t-value="sum_amount_and_report+ sum_amount + sum_report "/>
<t t-esc="'{:,}'.format(int(sum_amount_and_report)).replace(',', ' ')"/> €
</td>
<td class="text-right" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;">
<t t-esc="'{:,}'.format(int(sum_paid)).replace(',', ' ')"/> €
</td>
<td class="text-right" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;">
<t t-if="sum_amount > 0">
<t t-set="sum_percent" t-value="(sum_paid/sum_amount) * 100"/>
</t>
<t t-esc="'{:,}'.format(int(sum_percent)).replace(',', ' ')"/> %
</td>
<td class="text-center" style="vertical-align: middle;font-weight:bold;padding-top:10px;background-color:#171c8f !important;color:white;"/>
</tr>
您可以将my_state
表达式更改为:
my_state = sale.state
或者将QWEB模板中的条件更改为:
<t t-if="sale['sale_state'] != 'Cancelled'">
编辑:
您在t-if
之外使用sale
变量,Odoo将始终尝试从sale
获取值,如果没有定义repartition_sales_d
,它将引发错误。
sum_amount_and_report
变量没有初始化,Odoo会抛出一个错误。你需要在
<t t-set="sum_amount_and_report"
t-value="sum_amount_and_report+ sum_amount + sum_report"/>