Reputation: 5505
In Odoo 10, is it possible to define a report to list the purchase orders marked as confirmed but not sent by email to supplier?
i.e., how can I detect if in a purchase order the action "sent PO by email" was completed or not.
Thanks,
Upvotes: 3
Views: 786
Reputation: 14746
You can do it using following simple way.
Step 1 : Add one boolean field in Purchase order model and update context in 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 have override action_rfq_send
method & check if user is not sending ref then update context ctx.update({'sent_po_via_email':True})
.
Step 2: Inherit 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 above method we have checked if user is sending purchase order via email then set check mark True
.
We have used simple context to identify process & based on the context, write a value in purchase order.
Upvotes: 1
Reputation: 4174
Try this:
purchase.order' model and add a
Boolean field`.True
to this Boolean
field in the end of `action_rfq_send'.report.py
, select a query to fetch records where boolean_field =True and state ='purchase'
.Hope this will help you.
Upvotes: 1