Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I've inherited the write function of the model project.issue in V9 so I could send out an e-mail when the issue is changed to the final stage. The strange thing however is that this code goes of twice, but I don't see why.
The terminal output:
@api.multi def write(self, vals): res = super(project_issue, self).write(vals) self.ensure_one() _logger.critical('stage name: ' + str(self.stage_id.name)) if self.stage_id.name == self.project_id.final_fase_id.name: """ This means the issue has entered its final stage and is done. We should now notify the user by e-mail of completion.""" email_template = self.env['mail.template'].search([('name', '=', 'Issue solved')]) email_template.send_mail(self.id, force_send=True, raise_exception=True) return res
So why does this write function goes of twice?
2016-02-18 08:46:33,185 15538 INFO MyDb werkzeug: 127.0.0.1 - - [18/Feb/2016 08:46:33] "POST /web/dataset/call_kw/project.task.type/name_get HTTP/1.1" 200 -
2016-02-18 08:46:34,847 15538 CRITICAL MyDb openerp.addons.MyModule.models.project_issue: stage name: Done
2016-02-18 08:46:36,050 15538 INFO MyDb openerp.addons.mail.models.mail_mail: Mail with ID 19 and Message-Id u'<1455785194.900032924652100.686587842139294-openerp-20-project.issue@odoo8>' successfully sent
2016-02-18 08:46:36,057 15538 INFO MyDb openerp.models.unlink: User #1 deleted mail.mail records with IDs: 
2016-02-18 08:46:36,070 15538 INFO MyDb openerp.models.unlink: User #1 deleted mail.message records with IDs: 
2016-02-18 08:46:36,077 15538 CRITICAL MyDb openerp.addons.MyAddon.models.project_issue: stage name: Done
2016-02-18 08:46:37,264 15538 INFO MyDb openerp.addons.mail.models.mail_mail: Mail with ID 20 and Message-Id u'<1455785196.118980884552002.189632093322604-openerp-20-project.issue@odoo8>' successfully sent
Eventually I solved this by inheriting the default _track_subtype function from the module project_issue and by adding some custom code in it to fix my automatic e-mail. The code:
# We will inherit the default track_subtype function from the module project_issue # in order to send out our e-mail in the correct state. def _track_subtype(self, cr, uid, ids, init_values, context=None): res = super(project_issue, self)._track_subtype(cr, uid, ids, init_values, context=context) record = self.browse(cr, uid, ids, context=context) if record.stage_id.name == record.project_id.final_fase_id.name: """ This means the issue has entered its final stage and is done. We should now notify the user by e-mail of completion.""" template = self.pool.get('ir.model.data').get_object(cr, uid, 'your_module_name', 'template_email_id') mail_id = self.pool.get('mail.template').send_mail(cr, uid, template.id, record.id , force_send=True) if 'kanban_state' in init_values and record.kanban_state == 'blocked': return 'project_issue.mt_issue_blocked' elif 'kanban_state' in init_values and record.kanban_state == 'done': return 'project_issue.mt_issue_ready' elif 'user_id' in init_values and record.user_id: # assigned -> new return 'project_issue.mt_issue_new' elif 'stage_id' in init_values and record.stage_id and record.stage_id.sequence <= 1: # start stage -> new return 'project_issue.mt_issue_new' elif 'stage_id' in init_values: return 'project_issue.mt_issue_stage' return res
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 2/18/16, 3:53 AM|
|Seen: 1155 times|
|Last updated: 3/9/16, 9:06 AM|