When you try to close a sub without an invoice linked to it, Odoo raises a validation error
I'm tryin to bypass the invoice check by commenting all the relevant lines. But Odoo still performs the check. Here is my code.
# -*- coding: utf-8 -*-
from odoo import _,models, fields
# from odoo.exceptions import ValidationError
class SaleSubscriptionCloseReasonWizard(models.TransientModel):
_inherit = "sale.subscription.close.reason.wizard"
close_reason_id = fields.Many2one("sale.order.close.reason", string="Close Reason", required=True)
def new(self, values=None, origin=None, ref=None):
# sale_order = self.env['sale.order'].browse(self.env.context.get('active_id'))
# invoice_free = not any(
# state in ['draft', 'posted'] for state in sale_order.order_line.invoice_lines.move_id.mapped('state'))
# if invoice_free:
# raise ValidationError(_("""You can not churn a contract that has not been invoiced. Please cancel the contract instead."""))
return super().new(values=values, origin=origin, ref=ref)
def set_close(self):
self.ensure_one()
sale_order = self.env['sale.order'].browse(self.env.context.get('active_id'))
sale_order.close_reason_id = self.close_reason_id
sale_order.set_close(close_reason_id=self.close_reason_id.id)
Either the inheritance is not working, commenting out/deleting the relevant lines is not the way to do or the Odoo performs the check somewhere else.
thanks for the help