【问题标题】:Sending email on minimum qty in odoo8在odoo8中以最小数量发送电子邮件
【发布时间】:2016-03-02 16:07:00
【问题描述】:

您好,我想发送一封电子邮件,以防产品余额低于自定义模块中设置的最小值;我试过这段代码,我得到一个内部服务器错误,任何帮助请,我是 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)

【问题讨论】:

  • 请编辑添加整个异常跟踪的问题
  • 另外请修正缩进
  • 让我试着去追踪
  • 虽然我不认为这是一个缩进问题,我也在修复它
  • 我编辑了缩进,但仍然

标签: python email openerp odoo-8


【解决方案1】:

我想我明白你的问题是什么。你的 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)

【讨论】:

  • 我确实将代码更改为没有错误但仍然没有发送电子邮件
  • 可能你应该配置你的 smtp。顺便说一句,这段代码应该可以工作 99%
  • 是的,我的 smtp 即使在测试连接上也显示 -2 错误,我会尝试修复它,然后我会确认代码
  • @Alessandro_ruffolo 我更正了 smtp,但它仍然没有发送电子邮件,但没有错误
猜你喜欢
  • 2016-11-02
  • 1970-01-01
  • 2014-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-11
  • 1970-01-01
相关资源
最近更新 更多