我想在树状视图中过滤那些具有stock.pickings和一些stock.moves的采摘处于“已分配”状态的
我创建了计算和fnct_search方法的选择字段,但没有触发。我的代码有什么问题?和逻辑。
picking_id_states = fields.Selection([
('draft', 'Draft'), ('cancel', 'Cancelled'),
('waiting', 'Waiting Another Operation'),
('confirmed', 'Waiting Availability'),
('partially_available', 'Partially Available'),
('assigned', 'Available'), ('done', 'Done')], compute='compute_picking_state', string='Picking State',
fnct_search='_move_search', store=False, copy=False, index=True, readonly=True)
def _move_search(self, operator, value):
print "test"
for so in self:
moves = so.picking_ids.mapped('move_lines')
filtered_moves = moves.filtered(lambda l: l.state == 'assigned')
if filtered_moves:
so_ids = filtered_moves.mapped('picking_id.sale_id')
return [('id', 'in', so_ids)]
@api.depends('order_line.move_ids', 'order_line.move_ids.state')
def compute_picking_state(self):
for order in self:
for picking in order.picking_ids:
order.picking_id_state = picking.state
XML代码是
<record id="view_sale_order_search_picking_state" model="ir.ui.view">
<field name="name">Config Hetlta picking state</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_sales_order_filter" />
<field name="arch" type="xml">
<field name="user_id" position="after">
<field name="picking_id_state"/>
<field name="note"/>
</field>
<filter name="sales" position="after">
<filter string="Picking state" name="picking_id_states" />
</filter>
</field>
</record>
答案 0 :(得分:1)
计算字段中的self
搜索方法始终为空,没有记录集。您必须使用运算符和值(搜索词)并为订单ID创建自己的“间接”搜索。
但也许更简单的方法是只存储计算字段。 Odoo只能按存储时给出的数据库持久性字段进行搜索。