对于下面的代码,我的布尔值字段不在数据库中的域(已搜索)。当我使这种方法依赖时,它就起作用了。但是我有1000多个记录,那么如何同时对所有记录进行操作?
**Python Code:**
@api.multi
def _compute_opportunity_count111(self):
value = {}
for rec in self:
operator = 'child_of' if rec.is_company else '=' # the opportunity count should counts the opportunities of this company and all its contacts
won_list = rec.env['crm.lead'].search(
[('partner_id', operator, rec.id), ('stage_id.probability', '=', 100)]).ids
if won_list:
rec.won_customer = True
value.update(won_customer=rec.won_customer)
won_customer = fields.Boolean(compute='_compute_opportunity_count111', store=True)
**XML Code:**
<record id="base.action_partner_form" model="ir.actions.act_window">
<field name="name">Customers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="context">{"search_default_customer":1}</field>
<field name="domain">[('won_customer', '=', True)]</field>
<field name="search_view_id" ref="base.view_res_partner_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a contact in your address book.
</p>
<p>
Odoo helps you easily track all activities related to
a customer: discussions, history of business opportunities,
documents, etc.
</p>
</field>
</record>
预先感谢
答案 0 :(得分:1)
您不应使用api.multi
,而应使用api.depends
->这样可以确保在相关字段更改时再次调用该方法。
您似乎依赖is_company
-> @api.depends('is_company')
另外,从我读到的您的value
字典没用->您可以将其删除