在Quotation
的状态为SALES ORDER
时,sheet
的顶端会显示一个小车的图标,打开开发者模式的情况下将鼠标移到小车上,会显示delivery_count
字段,全局搜索这个字段,发现它位于在sale_stock
模块中继承的Sale.Order
模型里,在其对应的xml里搜索此字段,得到小车只能按钮所调用的方法。
下面通过注释解释这个方法:
@api.multi
def action_view_delivery(self):
'''
This function returns an action that display existing delivery orders
of given sales order ids. It can either be a in a list or in a form
view, if there is only one delivery order to show.
'''
action = self.env.ref('stock.action_picking_tree_all').read()[0] # 获取全部分拣单
# picking_ids = fields.One2many('stock.picking', 'sale_id', string='Pickings')
pickings = self.mapped('picking_ids') # 获取记录集里与本次销售订单相关的分拣单
if len(pickings) > 1: # 如果获取到的分拣单数大于1,就过滤出id在当前记录集里的记录显示
# domain (optional):
# filtering domain to implicitly add to all view search queries
action['domain'] = [('id', 'in', pickings.ids)]
elif pickings: # 如果只有一个分拣单,就以form视图显示它
# views:
# a list of (view_id, view_type) pairs.
# The second element of each pair is the category of the view (tree, form, graph, …) and the first is an
# optional database id (or False). If no id is provided, the client should fetch the default view of the
# specified type for the requested model (this is automatically done by fields_view_get()). The first type
# of the list is the default view type and will be open by default when the action is executed. Each view
# type should be present at most once in the list
action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
# res_id (optional):