Odoo 10 how to check if purchase order "Sent by email" has been completed or not

In Odoo 10, is it possible to define a report to list purchase orders marked as confirmed but not emailed to the supplier?
that is, how can I tell if the purchase order had an "emailed software" action or not.

Thank,

+3


source to share


2 answers


You can do it using the following simple way.

Step 1: Add one boolean field to the PO Model and update the context with the following method.

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,
        }

      

we override the action_rfq_send method and check if the user is submitting a ref, then update the context ctx.update ({'sent_po_via_email': True}) .

Step 2: Inherit the send_mail method of mail.compose.message.



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)

      

In the above method, we checked if the user is submitting the PO by email and then check the box True.

We used a simple context to identify the process and based on the context , write the value in order .

This might help you.

+1


source


Try the following:

  • Inherit purchase.order' model and add a

    Boolean field `.
  • Write True

    in this field Boolean

    at the end of `action_rfq_send '.
  • In report.py

    select query to retrieve records, where boolean_field =True and state ='purchase'

    .


Hope this helps you.

+1


source







All Articles