2017-07-03 128 views

回答

1

你可以使用以下簡單的方法。

步驟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':真})

第2步:繼承mail.compose.message的send_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) 

在如果用戶通過電子郵件發送採購爲了我們檢查了上述方法再設置對勾真。

我們已經使用簡單的情況下,以確定基於背景過程 &,寫在採購訂單值。

這可能對你有幫助。

+0

非常感謝,我會嘗試並確認回答 –

+0

謝謝,它完美的作品。容易和非侵入性。剩下的一個問題是,我找不到如何翻譯「通過電子郵件發送PO」字段說明。當我用--i18n-export運行odoo時,生成的.po缺少那個msg。任何提示? –

1

試試這個:

  1. 繼承purchase.order' model and add a布爾field`。
  2. 在'action_rfq_send'末尾寫True到這個Boolean字段。
  3. report.py中,選擇一個查詢來獲取記錄,其中boolean_field =True and state ='purchase'

希望這會對你有幫助。

相關問題