您好我想发送电子邮件,以防产品余额低于自定义模块中的最低设置;我尝试了这个代码,我得到了一个内部服务器错误,任何帮助PLZ,我新到odoo
class stock_minimum(models.Model):
_name = "rcs.stock_minimum"
warehouse = fields.Many2one("stock.warehouse")
product = fields.Many2one("product.product")
available = fields.Float(compute="_compute_balance", string="Available Quantity")
percentage = fields.Float(compute="_compute_balance", string="Percentage %")
quantity = fields.Float(string="Minimum Quantity")
@api.one
def _compute_balance(self):
transactions = self.env['rcs.stock_transaction'].search([('product','=',self.product.id),('warehouse','=',self.warehouse.id)])
balance = 0.0
for transaction in transactions:
if transaction.trans_type == "incoming":
balance = balance + transaction.quantity
else:
balance = balance - transaction.quantity
self.available = balance
self.percentage = self.available / self.quantity * 100
#check from here the additional codes
if (self.available <= quantity):
def send_mail(self, cr, uid, ids, context=None, template="minimumstock"):
for object in self.browse(cr, uid, ids, context=context):
template_id = self.pool.get('email.template').search(cr, uid, [("name","=",template)])
mail_message = self.pool.get('email.template').send_mail(cr,uid,template_id[0],object.id)
答案 0 :(得分:0)
我想我明白你的问题是什么。你的Python语法错了。使用Odoo框架也是错误的。
我不知道使用email.template是否与你的方式一致,但从语法/框架的角度来看,这是我能做的最好的
class stock_minimum(models.Model):
_name = "rcs.stock_minimum"
warehouse = fields.Many2one("stock.warehouse")
product = fields.Many2one("product.product")
available = fields.Float(compute="_compute_balance", string="Available Quantity")
percentage = fields.Float(compute="_compute_balance", string="Percentage %")
quantity = fields.Float(string="Minimum Quantity")
@api.one
def _compute_balance(self):
transactions = self.env['rcs.stock_transaction'].search([('product','=',self.product.id),('warehouse','=',self.warehouse.id)])
balance = 0.0
for transaction in transactions:
if transaction.trans_type == "incoming":
balance = balance + transaction.quantity
else:
balance = balance - transaction.quantity
self.available = balance
self.percentage = self.available / self.quantity * 100
#check from here the additional codes
if (self.available <= self.quantity):
template = self.env['email.template'].search([("name","=","minimumstock")])
mail_message = self.env['email.template'].send_mail(template[0].id,self.id)