效果图
- XML里面写需要执行的方法名
<record id="action_summary_consolidation" model="ir.actions.server">
<field name="name">汇报合并</field>
<field name="type">ir.actions.server</field>
<field name="code">action=records.summary_consolidation()</field>
<field name="model_id" ref="model_dispatching_order_line"/>
<field name="binding_model_id" ref="odmrp.model_dispatching_order_line" />
<field name="state">code</field>
</record>
- PY里面实现逻辑
def summary_consolidation(self):
""" 汇总合并 """
picking_type_id = self.env.ref('odbase.stock_picking_gongx_in') # 生产入库
picking_id = self.with_context(interface_skip=True).env['od.stock.picking.order'].sudo().create({
'picking_type_id': picking_type_id.id,
'location_id': picking_type_id.default_location_src_id.id,
'location_dest_id': picking_type_id.default_location_dest_id.id,
'typebh': picking_type_id.typebh,
'charge_person': self.env.user.partner_id.id,
})
code_name = ''
for line in self:
code_name += line.name + ';'
picking_id.codename = code_name
for codename in picking_id.codename.split(';'):
picking_id.codename = codename
data = picking_id.with_context({'skip_create': True, 'none_data': True}).onchange_codename()
if data:
raise UserError('%s' % data)
if self[0]._context.get('barcode'): # 用于派工单接口扫码返回生成得对象
return picking_id
view_id = self.env.ref('odstock.dd_od_stock_picking_order_form_view').id
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'od.stock.picking.order',
'views': [(view_id, 'form')],
'target': 'self',
'res_id': picking_id.id,
}