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.
 
 
 
 
 

50 lines
2.1 KiB

# -*- coding: utf-8 -*-
###############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author:Jumana Jabin MP (odoo@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 <https://www.gnu.org/licenses/>.
#
###############################################################################
from datetime import date
from odoo import models
class SaleOrder(models.Model):
"""Inherit Sale Order to add functionality for canceling expired
quotations."""
_inherit = 'sale.order'
def cancel_expired_quotation(self):
"""Automatically cancel the expired quotations."""
expired_quotation = self.search([('state', 'in', ['draft', 'sent']),
('validity_date', '<', date.today())])
if expired_quotation:
for rec in expired_quotation:
cancel_warning = rec._show_cancel_wizard()
if cancel_warning:
mail_template = self.env.ref(
'sale.mail_template_sale_cancellation',
raise_if_not_found=False
)
cancel = self.env['sale.order.cancel'].create({
'order_id': rec.id,
'template_id': mail_template.id
})
cancel.action_send_mail_and_cancel()
else:
rec._action_cancel()