Holger Brunn
8 years ago
No known key found for this signature in database
GPG Key ID: 1C9760FECA3AE18
9 changed files with 196 additions and 0 deletions
-
65subscription_action/README.rst
-
4subscription_action/__init__.py
-
17subscription_action/__openerp__.py
-
4subscription_action/models/__init__.py
-
44subscription_action/models/subscription_subscription.py
-
BINsubscription_action/static/description/icon.png
-
4subscription_action/tests/__init__.py
-
37subscription_action/tests/test_subscription_action.py
-
21subscription_action/views/subscription_subscription.xml
@ -0,0 +1,65 @@ |
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
=============================== |
|||
Actions for recurring documents |
|||
=============================== |
|||
|
|||
This module was written to extend the functionality of the `subscription` |
|||
module in order to allow you to run a server action on newly created documents. |
|||
|
|||
Configuration |
|||
============= |
|||
|
|||
To configure this module, you need to: |
|||
|
|||
#. go to some recurring document |
|||
#. select or create a server action with the same base model as your recurring document |
|||
|
|||
Note that server actions already support calling multiple actions themselves, so if you need to have multiple actions, first define one umbrella action that calls the others. |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
|||
:alt: Try me on Runbot |
|||
:target: https://runbot.odoo-community.org/runbot/149/9.0 |
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues |
|||
<https://github.com/OCA/server-tools-9.0/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 |
|||
------ |
|||
|
|||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Holger Brunn <hbrunn@therp.nl> |
|||
|
|||
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: https://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: https://odoo-community.org |
|||
|
|||
This module is maintained by the OCA. |
|||
|
|||
OCA, or the Odoo Community Association, is a nonprofit organization whose |
|||
mission is to support the collaborative development of Odoo features and |
|||
promote its widespread use. |
|||
|
|||
To contribute to this module, please visit https://odoo-community.org. |
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import models |
@ -0,0 +1,17 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
{ |
|||
"name": "Actions for recurring documents", |
|||
"version": "9.0.1.0.0", |
|||
"author": "Therp BV,Odoo Community Association (OCA)", |
|||
"license": "AGPL-3", |
|||
"category": "Extra Tools", |
|||
"summary": "Run a server action on a newly created document", |
|||
"depends": [ |
|||
'subscription', |
|||
], |
|||
"data": [ |
|||
"views/subscription_subscription.xml", |
|||
], |
|||
} |
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import subscription_subscription |
@ -0,0 +1,44 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from openerp import api, fields, models |
|||
|
|||
|
|||
class SubscriptionSubscription(models.Model): |
|||
_inherit = 'subscription.subscription' |
|||
|
|||
server_action_id = fields.Many2one( |
|||
'ir.actions.server', string='Run action', |
|||
help='If you need to run multiple actions, use an umbrella action', |
|||
) |
|||
model_id = fields.Many2one('ir.model', compute='_compute_model_id') |
|||
|
|||
@api.multi |
|||
def model_copy(self): |
|||
old_history = self.env['subscription.subscription.history'].search([ |
|||
('subscription_id', 'in', self.ids), |
|||
]) |
|||
result = super(SubscriptionSubscription, self).model_copy() |
|||
new_history = self.env['subscription.subscription.history'].search([ |
|||
('subscription_id', 'in', self.ids), |
|||
]) |
|||
for history_item in new_history - old_history: |
|||
action = history_item.subscription_id.server_action_id |
|||
record = history_item.document_id |
|||
if not action: |
|||
continue |
|||
action.with_context( |
|||
active_id=record.id, active_ids=record.ids, |
|||
active_model=record._name, |
|||
).run() |
|||
return result |
|||
|
|||
@api.multi |
|||
@api.depends('doc_source') |
|||
def _compute_model_id(self): |
|||
for this in self: |
|||
if not this.doc_source: |
|||
continue |
|||
this.model_id = self.env['ir.model'].search([ |
|||
('model', '=', this.doc_source._name), |
|||
], limit=1) |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import test_subscription_action |
@ -0,0 +1,37 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from openerp.tests.common import TransactionCase |
|||
|
|||
|
|||
class TestSubscriptionAction(TransactionCase): |
|||
def test_subscription_action(self): |
|||
subscription = self.env['subscription.subscription'].create({ |
|||
'name': 'testsubscription', |
|||
'doc_source': 'res.partner,%d' % ( |
|||
self.env.ref('base.main_partner').id, |
|||
), |
|||
'server_action_id': self.env['ir.actions.server'].create({ |
|||
'name': 'Subscription server action', |
|||
'model_id': self.env.ref('base.model_res_partner').id, |
|||
'state': 'object_write', |
|||
'use_write': 'current', |
|||
'fields_lines': [ |
|||
( |
|||
0, 0, |
|||
{ |
|||
'col1': |
|||
self.env.ref('base.field_res_partner_name').id, |
|||
'type': 'value', |
|||
'value': 'Duplicated by subscription', |
|||
} |
|||
) |
|||
], |
|||
}).id, |
|||
}) |
|||
subscription.set_process() |
|||
subscription.model_copy() |
|||
self.assertEqual( |
|||
subscription.doc_lines[-1:].document_id.name, |
|||
'Duplicated by subscription', |
|||
) |
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<odoo> |
|||
<record id="view_subscription_form" model="ir.ui.view"> |
|||
<field name="model">subscription.subscription</field> |
|||
<field name="inherit_id" ref="subscription.view_subscription_form" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="cron_id" position="after"> |
|||
<field |
|||
name="server_action_id" |
|||
attrs="{'invisible': [('doc_source', '=', False)]}" |
|||
domain="[('model_id', '=', model_id)]" |
|||
context="{'default_model_id': model_id}" |
|||
/> |
|||
<field |
|||
name="model_id" |
|||
invisible="1" |
|||
/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue