Skip to content

Commit

Permalink
Merge commit 'refs/pull/144/head' of github.com:acsone/acsone-addons …
Browse files Browse the repository at this point in the history
…into 10.0-lih_master
  • Loading branch information
benwillig committed Jul 14, 2017
2 parents 90372fc + 068f75e commit 9e7750c
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions mail_record_creation_partner_notification/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions mail_record_creation_partner_notification/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Mail Record Creation Partner Notification',
'description': """
Provides a model to inherit to notify partners when
a record is created""",
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV',
'website': 'https://www.acsone.eu',
'depends': [
'partner_to_notify',
],
'data': [
],
'demo': [
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_partner_notification
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class MailPartnerNotification(models.AbstractModel):

_name = 'mail.partner.notification.mixin'
_description = 'Mail Partner Notification (Abstract)'

_subscribe_notified_partner_on_creation = True

@api.model
def create(self, values):
partners_to_notify = self.get_partners_to_notify_on_creation(values)
if partners_to_notify:
self = self.with_context(partners_to_notify=partners_to_notify.ids)
record = super(MailPartnerNotification, self).create(values)
record.subscribe_partners(partners_to_notify)
return record

@api.model
def get_partners_to_notify_on_creation(self, values):
"""
Inherit this method to get partners to notify when a record
is created.
:param values: creation values
:return: recordset('res.partner')
"""
return self.env['res.partner']

@api.multi
def subscribe_partners(self, partners):
self.ensure_one()
if not self._subscribe_notified_partner_on_creation or not partners:
return
self.message_subscribe(partner_ids=partners.ids)
1 change: 1 addition & 0 deletions partner_to_notify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions partner_to_notify/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Mail Partner To Notify',
'description': """
Allow to force partners to be notified when posting a message
on a record.""",
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV',
'website': 'https://www.acsone.eu',
'depends': [
'mail',
],
'data': [
],
'demo': [
],
}
2 changes: 2 additions & 0 deletions partner_to_notify/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_message
from . import res_partner
20 changes: 20 additions & 0 deletions partner_to_notify/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class MailMessage(models.Model):

_inherit = 'mail.message'

@api.model
def create(self, values):
partners_to_notify = self.env.context.get('partners_to_notify')
if partners_to_notify:
partner_ids = values.get('partner_ids', [])
for partner_id in partners_to_notify:
partner_ids.append((4, partner_id))
values['partner_ids'] = partner_ids
return super(MailMessage, self).create(values)
20 changes: 20 additions & 0 deletions partner_to_notify/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class ResPartner(models.Model):

_inherit = 'res.partner'

@api.multi
def _notify(self, message, force_send=False, send_after_commit=True,
user_signature=True):
partners_to_notify = self.env.context.get('partners_to_notify')
if partners_to_notify:
self = self.browse(partners_to_notify)
super(ResPartner, self)._notify(
message, force_send=force_send,
send_after_commit=send_after_commit, user_signature=user_signature)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/mail_record_creation_partner_notification/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/partner_to_notify/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions setup/partner_to_notify/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions setup/partner_to_notify/odoo/addons/partner_to_notify
6 changes: 6 additions & 0 deletions setup/partner_to_notify/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 9e7750c

Please sign in to comment.