Skip to content

Commit

Permalink
[ADD] mail_activity_automation: create module
Browse files Browse the repository at this point in the history
  • Loading branch information
lav-adhoc committed Aug 8, 2023
1 parent b102c1e commit b8f6be8
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
71 changes: 71 additions & 0 deletions mail_activity_automation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.. |company| replace:: ADHOC SA

.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
:alt: ADHOC SA
:target: https://www.adhoc.com.ar

.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

========================
Mail Activity Automation
========================

* This module incorporates the functionality of automatically executing the activity, whether it is sending an email or marking Done.

Installation
============

To install this module, you need to:

#. Just install

Configuration
=============

To configure this module, you need to:

#. In the activities type configure with "run automatically".


Usage
=====

To use this module, you need to:

#. Scheduler an activity using the activity type with "Run automatically" on.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: http://runbot.adhoc.com.ar/

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/ingadhoc/miscellaneous/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Images
------

* |company| |icon|

Contributors
------------

Maintainer
----------

|company_logo|

This module is maintained by the |company|.

To contribute to this module, please visit https://www.adhoc.com.ar.
1 change: 1 addition & 0 deletions mail_activity_automation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions mail_activity_automation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

{
'name': 'Mail Activity Automation',
'version': "16.0.1.0.0",
'category': 'Communications',
'sequence': 14,
'summary': '',
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'images': [
],
'depends': [
'mail',
],
'data': [
'views/mail_activity_type_views.xml',
'data/ir_cron_data.xml',
],
'installable': True,
'auto_install': False,
'application': False,
}
13 changes: 13 additions & 0 deletions mail_activity_automation/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="run_activities_automatically" model="ir.cron">
<field name="name">Run Activities Automatically</field>
<field name="model_id" ref="mail.model_mail_activity"/>
<field name="state">code</field>
<field name="code">model._cron_run_activities()</field>
<field name="active" eval="True"/>
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions mail_activity_automation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_activity
from . import mail_activity_type
16 changes: 16 additions & 0 deletions mail_activity_automation/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import models
import datetime


class MailActivity(models.Model):
_inherit = "mail.activity"

def _cron_run_activities(self):
activities = self.search([('activity_type_id.run_automatically', '=', True), ('date_deadline', '<=', datetime.date.today())])
for activity in activities:
activity.with_context(from_bot=True).action_done_schedule_next()

def _action_done(self, feedback=False, attachment_ids=None):
if self._context.get('from_bot') and len(self.activity_type_id.mail_template_ids) == 1:
self.env[self.res_model].browse(self.res_id).message_post_with_template(self.activity_type_id.mail_template_ids.id)
return super()._action_done(feedback, attachment_ids)
12 changes: 12 additions & 0 deletions mail_activity_automation/models/mail_activity_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models, fields


class MailActivityType(models.Model):
_inherit = "mail.activity.type"

run_automatically = fields.Boolean(help="Si marca esta opción, llegada la fecha de vencimiento, se enviará la plantilla seleccionada y se marcará la actividad como realizado.")
mail_template_ids_count = fields.Integer(compute="_compute_mail_template_ids_count")

def _compute_mail_template_ids_count(self):
for rec in self:
rec.mail_template_ids_count = len(rec.mail_template_ids)
14 changes: 14 additions & 0 deletions mail_activity_automation/views/mail_activity_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="mail_activity_type_view_form" model="ir.ui.view">
<field name="name">mail.activity.type.view.form</field>
<field name="model">mail.activity.type</field>
<field name="inherit_id" ref="mail.mail_activity_type_view_form"/>
<field name="arch" type="xml">
<field name="decoration_type" position="after">
<field name="mail_template_ids_count" invisible="1"/>
<field name="run_automatically" attrs="{'invisible': [('mail_template_ids_count', '!=', 1)]}"/>
</field>
</field>
</record>
</odoo>

0 comments on commit b8f6be8

Please sign in to comment.