# -*- coding: utf-8 -*- from odoo import api, models class PurchaseOrder(models.Model): _inherit = "purchase.order" @api.multi def _create_picking(self): stock_picking = self.env['stock.picking'] for order in self: if any([ptype in ['product', 'consu'] for ptype in order.order_line.mapped('product_id.type')]): pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel')) if not pickings: res = order._prepare_picking() picking = stock_picking.create(res) else: picking = pickings[0] moves = order.order_line._create_stock_moves(picking) moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm() seq = 0 for move in sorted(moves, key=lambda move: move.date_expected): print(move.date_expected,"gfhgbvhgjyghj") seq += 5 move.sequence = seq moves._action_assign() picking.generate_quality_alert() picking.message_post_with_view('mail.message_origin_link', values={'self': picking, 'origin': order}, subtype_id=self.env.ref('mail.mt_note').id) return True