You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.3 KiB
30 lines
1.3 KiB
# -*- coding: utf-8 -*-
|
|
from odoo import api, models
|
|
|
|
|
|
class PurchaseOrder(models.Model):
|
|
_inherit = "purchase.order"
|
|
|
|
|
|
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):
|
|
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
|
|
|