Skip to Content
Menu
This question has been flagged
2058 Views

Hi everyone,

Im trying to send a mail to perticular person in my code through odoo9.0 based on purchase order field.

My code is below.

from openerp import api, fields, models, _, SUPERUSER_ID

class PurchaseOrder(models.Model):
    _name = "purchase.order"

   contract_end_date = fields.Date(string='Contract End Date')

_defaults = {

        'contract_end_date': time.strftime('%Y-%m-%d'),

    }

in default i converted like above year,month and date

and following python code shows sending mail.

from openerp import models, fields, api import datetime as DT import dateutil.relativedelta as REL from time import gmtime, strftime from datetime import datetime


class PurchaseRenewalNotification(models.Model):
    _inherit = 'purchase.order'

    @api.model
    def send_notification(self):
        print "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
        current_date = strftime("%Y-%m-%d", gmtime())
        # today = DT.date.today()
        today = strftime("%Y-%m-%d", gmtime())
        date_today = datetime.strptime(today, "%Y-%m-%d").date()
        rd = REL.relativedelta(days=15)
        fifty_date = date_today + rd
        print "fifty_date.......",fifty_date
        for rec in self.env['purchase.order'].search([('contract_end_date', '=', fifty_date)]):
 
            print "rrrrrrrrrrrrrrrrrrr"
            message_body = ".......You can add the content here........."
            template_obj = self.env['mail.mail']
            template_data = {
                'subject': 'Renewal Notification',
                'body_html': message_body,
                'email_from': '',
                'email_to': "savitapatilmat@gmail.com"
                # 'email_to': rec.partner_id.email
            }
            template_id = template_obj.create(template_data)
            template_obj.send(template_id)

in loop its not entering n in command line rrrrr not printing

xml shows following

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="ir_cron_renew_notification" model="ir.cron">
            <field name="name">Sale Renewal Notification</field>
            <field name="active">True</field>
            <field name="user_id" ref="base.user_root"/>
            <field name="interval_number">15</field>
            <field name="interval_type">days</field>
            <field name="doall" eval="False" />
            <field name="model">purchase.order</field>
            <field name="function">send_notification</field>
            <field name="numbercall">-1</field>
        </record>
   </data>
</odoo>

I configured outgoing mail server tooo

KIndly someone help with this issue.

Thanks a lot an advance



Avatar
Discard

Hi

According to your code, I think you must set the interval of the cron job as daily.

<field name="interval_number">1</field>