Odoo 10 如何检查采购订单 "Sent PO by email" 操作是否已执行

Odoo 10 how to check if Purchase Order "Sent PO by email" action was executed or not

在 Odoo 10 中,是否可以定义一个报告来列出标记为已确认但未通过电子邮件发送给供应商的采购订单?
即,我如何检测采购订单中的操作 "sent PO by email" 是否已完成。

谢谢,

试试这个:

  1. 继承purchase.order' model and add a布尔字段`。
  2. True 写入“action_rfq_send”末尾的 Boolean 字段。
  3. report.py 中,select 查询以获取记录 boolean_field =True and state ='purchase'

希望对您有所帮助。

您可以使用以下简单的方法来完成。

第 1 步:在采购订单模型中添加一个布尔字段,并在以下方法中更新上下文。

from odoo import fields,models,api

class purchase_order(models.Model):
    _inherit="purchase.order"

    sent_po_via_email=fields.Boolean("Sent PO Via Email",default=False,copy=False)


    @api.multi
    def action_rfq_send(self):
        '''
        This function opens a window to compose an email, with the edi purchase template message loaded by default
        '''
        self.ensure_one()
        ctx = dict(self.env.context or {})
        ir_model_data = self.env['ir.model.data']
        try:
            if self.env.context.get('send_rfq', False):
                template_id = ir_model_data.get_object_reference('purchase', 'email_template_edi_purchase')[1]
            else:
                ctx.update({'sent_po_via_email':True})
                template_id = ir_model_data.get_object_reference('purchase', 'email_template_edi_purchase_done')[1]
        except ValueError:
            template_id = False
        try:
            compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]
        except ValueError:
            compose_form_id = False
        ctx.update({
            'default_model': 'purchase.order',
            'default_res_id': self.ids[0],
            'default_use_template': bool(template_id),
            'default_template_id': template_id,
            'default_composition_mode': 'comment',
        })
        return {
            'name': _('Compose Email'),
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'mail.compose.message',
            'views': [(compose_form_id, 'form')],
            'view_id': compose_form_id,
            'target': 'new',
            'context': ctx,
        }

我们有覆盖 action_rfq_send 方法 & 检查用户是否没有发送 ref 然后更新上下文 ctx.update({'sent_po_via_email':True}).

第 2 步:继承 mail.compose.messagesend_mail 方法。

class MailComposeMessage(models.TransientModel):
    _inherit = 'mail.compose.message'

    @api.multi
    def send_mail(self, auto_commit=False):
        context = self._context
        if context.get('default_model') == 'purchase.order' and \
                context.get('default_res_id') and context.get('sent_po_via_email'):
            po_order = self.env['purchase.order'].browse(context['default_res_id'])
            po_order.sent_po_via_email = True
        return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)

在上面的方法中,我们检查了用户是否通过电子邮件发送采购订单,然后设置复选标记 True

我们使用简单的上下文来识别流程,并根据上下文在采购订单中写入一个值。