Skip to content

Commit

Permalink
[IMP] stop checking origin of SO with origin name
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-champonnois committed Jan 11, 2025
1 parent 295dec2 commit 8c2d415
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
20 changes: 4 additions & 16 deletions contract_sale_generation_prevent_loop/models/contract.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo.exceptions import UserError
from odoo import models


class ContractContract(models.Model):
_inherit = "contract.contract"

def _recurring_create_sale(self, date_ref=False):
res = super()._recurring_create_sale(date_ref)
res.created_from_contract = True
def _prepare_recurring_sales_values(self, date_ref=False):
res = super()._prepare_recurring_sales_values(date_ref)
res[0]["created_from_contract"] = True
return res

def write(self, vals):
if "name" in vals and self.generation_type == "sale":
raise UserError(
_(
"Contracts generating sales should not be renamed. "
"In case this contracts contains a product-generating "
"contract, this will cause a loop of contract creation."
)
)
return super().write(vals)
5 changes: 1 addition & 4 deletions contract_sale_generation_prevent_loop/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class SaleOrder(models.Model):
created_from_contract = fields.Boolean(default=False, readonly=True)

def action_create_contract(self):
source_contract = self.env["contract.contract"].search(
[("name", "=", self.origin)]
)
if source_contract:
if self.created_from_contract:
return False
else:
return super().action_create_contract()

0 comments on commit 8c2d415

Please sign in to comment.