Hello odoo community,
I would like to make a function that controls when a user adds a price request to a supplier the code controls if there is already an open order from the same supplier. this my code:
from odoo import api, models, _
from odoo.exceptions import UserError
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
def check_open_purchase_order(self):
for order in self:
domain = [
('partner_id', '=', order.partner_id.id),
('state', '=', 'purchase'),
]
open_orders = self.env['purchase.order'].search(domain)
if open_orders:
message = "Une commande chez le même fournisseur est ouverte."
raise UserError(message)
class YourModel(models.Model):
_name = 'your.model'
@api.model
def your_method_trigger_popup(self):
# Call the method to check open purchase orders
self.env['purchase.order'].check_open_purchase_order()