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.
56 lines
2.4 KiB
56 lines
2.4 KiB
# -*- coding: utf-8 -*-
|
|
###############################################################################
|
|
#
|
|
# Cybrosys Technologies Pvt. Ltd.
|
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
|
|
# Author: Dhanya B(<https://www.cybrosys.com>)
|
|
#
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
#
|
|
###############################################################################
|
|
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
|
|
|