# -*- coding: utf-8 -*- ############################################################################### # # Cybrosys Technologies Pvt. Ltd. # Copyright (C) 2025-TODAY Cybrosys Technologies(). # Author: Dhanya B() # # This program is free software: you can modify # it under the terms of the GNU Affero General Public License (AGPL) as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################### from odoo import models class PurchaseOrder(models.Model): _inherit = "purchase.order" def _create_picking(self): """Creates a stock picking for the order if applicable.""" 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): seq += 5 move.sequence = seq moves._action_assign() picking.generate_quality_alert() self.message_post_with_source( 'mail.message_origin_link', render_values={ 'self': picking, 'origin': order}, subtype_xmlid='mail.mt_note', ) return True