odoo action automated #123
Unanswered
Hawadiallo01
asked this question in
Q&A
Replies: 1 comment
-
Hi, Here's some code that might help, I've made a action that checks for a low stock, and called that when any change to any of the records is made. Please try the code i've written below. If theres any issue, Let me know. from odoo import models, fields, api, exceptions
class ProductLowStockError(exceptions.UserError):
def __init__(self, record):
message = f"{record.name} is low on stock (only {record.stock} left). Consider updating its stock."
super(ProductLowStockError, self).__init__(message)
class Product(models.Model):
_name = 'your_module.product'
_description = 'A product model.'
name = fields.Char(string="Name")
stock = fields.Integer(string="Stock", required=True)
def check_low_stock_alert(self):
for record in self:
if record.stock < 50: # If the stock is less than 50, raise a custom warning.
raise ProductLowStockError(record)
@api.model
def create(self, vals):
record = super(Product, self).create(vals)
record.check_low_stock_alert()
return record
def write(self, vals):
result = super(Product, self).write(vals)
self.check_low_stock_alert()
return result |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello i use odoo enterprise V16 i need to automated an stock low alert with automated action if someone can help me please
Beta Was this translation helpful? Give feedback.
All reactions