Browse Source

[REF] Rename to attachement_queue

12.0-mig-module_prototyper_last
Sébastien BEAU 5 years ago
committed by David Beal
parent
commit
e717eee18e
  1. 0
      attachment_queue/__init__.py
  2. 12
      attachment_queue/__manifest__.py
  3. 8
      attachment_queue/data/cron.xml
  4. 7
      attachment_queue/data/ir_config_parameter.xml
  5. 2
      attachment_queue/data/mail_template.xml
  6. 10
      attachment_queue/demo/attachment_queue_demo.xml
  7. 1
      attachment_queue/models/__init__.py
  8. 18
      attachment_queue/models/attachment_queue.py
  9. 0
      attachment_queue/readme/CONTRIBUTORS.rst
  10. 5
      attachment_queue/readme/DESCRIPTION.rst
  11. 4
      attachment_queue/readme/USAGE.rst
  12. 3
      attachment_queue/security/ir.model.access.csv
  13. 0
      attachment_queue/static/description/icon.png
  14. 2
      attachment_queue/tests/__init__.py
  15. 10
      attachment_queue/tests/test_attachment_queue.py
  16. 39
      attachment_queue/views/attachment_queue_view.xml
  17. 7
      base_attachment_queue/data/ir_config_parameter.xml
  18. 10
      base_attachment_queue/demo/attachment_metadata_demo.xml
  19. 1
      base_attachment_queue/models/__init__.py
  20. 6
      base_attachment_queue/readme/DESCRIPTION.rst
  21. 3
      base_attachment_queue/security/ir.model.access.csv

0
base_attachment_queue/__init__.py → attachment_queue/__init__.py

12
base_attachment_queue/__manifest__.py → attachment_queue/__manifest__.py

@ -2,12 +2,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'Base Attachment Queue',
'name': 'Attachment Queue',
'version': '12.0.1.0.0', 'version': '12.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)', 'author': 'Akretion,Odoo Community Association (OCA)',
'summary': 'This module enhances ir.attachment for better '
'control of import and export of files',
'website': 'https://www.akretion.com',
'summary': "Base module that add the concept of queue for processing file",
'website': 'https://github.com/OCA/server-tools',
'maintainers': ['florian-dacosta', 'sebastienbeau'],
'license': 'AGPL-3', 'license': 'AGPL-3',
'category': 'Generic Modules', 'category': 'Generic Modules',
'depends': [ 'depends': [
@ -15,14 +15,14 @@
'mail', 'mail',
], ],
'data': [ 'data': [
'views/attachment_view.xml',
'views/attachment_queue_view.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'data/cron.xml', 'data/cron.xml',
'data/ir_config_parameter.xml', 'data/ir_config_parameter.xml',
'data/mail_template.xml', 'data/mail_template.xml',
], ],
'demo': [ 'demo': [
'demo/attachment_metadata_demo.xml'
'demo/attachment_queue_demo.xml'
], ],
'installable': True, 'installable': True,
} }

8
base_attachment_queue/data/cron.xml → attachment_queue/data/cron.xml

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1"> <odoo noupdate="1">
<record model="ir.cron" id="cronjob_run_attachments_metadata">
<field name='name'>Run Attachments Metadata</field>
<record model="ir.cron" id="cronjob_run_attachment_queue">
<field name='name'>Run Attachments Queue</field>
<field name='interval_number'>30</field> <field name='interval_number'>30</field>
<field name='interval_type'>minutes</field> <field name='interval_type'>minutes</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field name="active">False</field> <field name="active">False</field>
<field name="doall" eval="False" /> <field name="doall" eval="False" />
<field name="model_id" ref="model_ir_attachment_metadata"/>
<field name="model_id" ref="model_attachment_queue"/>
<field name="state">code</field> <field name="state">code</field>
<field name="code">model.run_attachment_metadata_scheduler()</field>
<field name="code">model.run_attachment_queue_scheduler()</field>
</record> </record>
</odoo> </odoo>

7
attachment_queue/data/ir_config_parameter.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="attachment_queue_cron_batch_limit" model="ir.config_parameter">
<field name="key">attachment_queue_cron_batch_limit</field>
<field name="value">200</field>
</record>
</odoo>

2
base_attachment_queue/data/mail_template.xml → attachment_queue/data/mail_template.xml

@ -5,7 +5,7 @@
<field name="email_to">${object.failure_emails}</field> <field name="email_to">${object.failure_emails}</field>
<field name="name">Attachment Failure notification</field> <field name="name">Attachment Failure notification</field>
<field name="subject">The attachment ${object.name} has failed</field> <field name="subject">The attachment ${object.name} has failed</field>
<field name="model_id" ref="base_attachment_queue.model_ir_attachment_metadata"/>
<field name="model_id" ref="attachment_queue.model_attachment_queue"/>
<field name="body_html"><![CDATA[ <field name="body_html"><![CDATA[
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">Hello,<br><br></p> <p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">Hello,<br><br></p>
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">The attachment ${object.name} has failed with the following error message : <br>${object.state_message}<br></p><p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;"></p> <p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">The attachment ${object.name} has failed with the following error message : <br>${object.state_message}<br></p><p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;"></p>

10
attachment_queue/demo/attachment_queue_demo.xml

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<odoo noupdate="1">
<record id="attachment_queue_demo" model="attachment.queue">
<field name="datas">bWlncmF0aW9uIHRlc3Q=</field>
<field name="datas_fname">attachment_queue_demo.doc</field>
<field name="name">attachment_queue_demo.doc</field>
</record>
</odoo>

1
attachment_queue/models/__init__.py

@ -0,0 +1 @@
from . import attachment_queue

18
base_attachment_queue/models/attachment.py → attachment_queue/models/attachment_queue.py

@ -7,8 +7,8 @@ from odoo import api, fields, models, registry
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class IrAttachmentMetadata(models.Model):
_name = 'ir.attachment.metadata'
class AttachmentQueue(models.Model):
_name = 'attachment.queue'
_inherits = {'ir.attachment': 'attachment_id'} _inherits = {'ir.attachment': 'attachment_id'}
_inherit = ['mail.thread'] _inherit = ['mail.thread']
@ -19,7 +19,7 @@ class IrAttachmentMetadata(models.Model):
selection=[], selection=[],
help="The file type determines an import method to be used " help="The file type determines an import method to be used "
"to parse and transform data before their import in ERP or an export") "to parse and transform data before their import in ERP or an export")
sync_date = fields.Datetime()
date_done = fields.Datetime()
state = fields.Selection([ state = fields.Selection([
('pending', 'Pending'), ('pending', 'Pending'),
('failed', 'Failed'), ('failed', 'Failed'),
@ -42,11 +42,11 @@ class IrAttachmentMetadata(models.Model):
return "" return ""
@api.model @api.model
def run_attachment_metadata_scheduler(self, domain=None):
def run_attachment_queue_scheduler(self, domain=None):
if domain is None: if domain is None:
domain = [('state', '=', 'pending')] domain = [('state', '=', 'pending')]
batch_limit = self.env.ref( batch_limit = self.env.ref(
'base_attachment_queue.attachment_sync_cron_batch_limit') \
'attachment_queue.attachment_queue_cron_batch_limit') \
.value .value
if batch_limit and batch_limit.isdigit(): if batch_limit and batch_limit.isdigit():
limit = int(batch_limit) limit = int(batch_limit)
@ -59,10 +59,10 @@ class IrAttachmentMetadata(models.Model):
def run(self): def run(self):
""" """
Run the process for each attachment metadata
Run the process for each attachment queue
""" """
failure_tmpl = self.env.ref( failure_tmpl = self.env.ref(
'base_attachment_queue.attachment_failure_notification')
'attachment_queue.attachment_failure_notification')
for attachment in self: for attachment in self:
with api.Environment.manage(): with api.Environment.manage():
with registry(self.env.cr.dbname).cursor() as new_cr: with registry(self.env.cr.dbname).cursor() as new_cr:
@ -86,7 +86,7 @@ class IrAttachmentMetadata(models.Model):
else: else:
vals = { vals = {
'state': 'done', 'state': 'done',
'sync_date': fields.Datetime.now(),
'date_done': fields.Datetime.now(),
} }
attach.write(vals) attach.write(vals)
attach.env.cr.commit() attach.env.cr.commit()
@ -95,7 +95,7 @@ class IrAttachmentMetadata(models.Model):
@api.multi @api.multi
def _run(self): def _run(self):
self.ensure_one() self.ensure_one()
_logger.info('Start to process attachment metadata id %d', self.id)
_logger.info('Start to process attachment queue id %d', self.id)
@api.multi @api.multi
def set_done(self): def set_done(self):

0
base_attachment_queue/readme/CONTRIBUTORS.rst → attachment_queue/readme/CONTRIBUTORS.rst

5
attachment_queue/readme/DESCRIPTION.rst

@ -0,0 +1,5 @@
This module implement a queue for processing file.
File are stored in Odoo standard ir.attachment.
The attachments will be processed depending on their type.
An example of the use of this module, can be found in the module `attachment_synchronize`.

4
base_attachment_queue/readme/USAGE.rst → attachment_queue/readme/USAGE.rst

@ -1,8 +1,8 @@
Go the menu Settings > Technical > Database Structure > Meta Data Attachments
Go the menu Settings > Technical > Database Structure > Attachments Queue
You can create / see standard attachments with additional fields You can create / see standard attachments with additional fields
Configure the batch limit for attachments that can be sync by the cron task at a go: Configure the batch limit for attachments that can be sync by the cron task at a go:
Settings > Technical > System parameters > attachment_sync_cron_batch_limit
Settings > Technical > System parameters > attachment_queue_cron_batch_limit

3
attachment_queue/security/ir.model.access.csv

@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_attachment_queue_user,attachment.queue.user,model_attachment_queue,,1,0,0,0
access_attachment_queue_manager,attachment.queue.manager,model_attachment_queue,base.group_no_one,1,1,1,1

0
base_attachment_queue/static/description/icon.png → attachment_queue/static/description/icon.png

Before

Width: 128  |  Height: 128  |  Size: 9.2 KiB

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

2
base_attachment_queue/tests/__init__.py → attachment_queue/tests/__init__.py

@ -1,3 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_attachment_base_queue
from . import test_attachment_queue

10
base_attachment_queue/tests/test_attachment_base_queue.py → attachment_queue/tests/test_attachment_queue.py

@ -12,22 +12,20 @@ class TestAttachmentBaseQueue(TransactionCase):
self.registry.enter_test_mode(self.env.cr) self.registry.enter_test_mode(self.env.cr)
self.env = api.Environment(self.registry.test_cr, self.env.uid, self.env = api.Environment(self.registry.test_cr, self.env.uid,
self.env.context) self.env.context)
self.attachment = self.env.ref(
'base_attachment_queue.attachment_metadata')
self.ir_attachment_metadata = self.env['ir.attachment.metadata']
self.attachment = self.env.ref('attachment_queue.attachment_queue_demo')
def tearDown(self): def tearDown(self):
self.registry.leave_test_mode() self.registry.leave_test_mode()
super().tearDown() super().tearDown()
def test_attachment_metadata(self):
"""Test run_attachment_metadata_scheduler to ensure set state to done
def test_attachment_queue(self):
"""Test run_attachment_queue_scheduler to ensure set state to done
""" """
self.assertEqual( self.assertEqual(
self.attachment.state, self.attachment.state,
'pending' 'pending'
) )
self.ir_attachment_metadata.run_attachment_metadata_scheduler()
self.env['attachment.queue'].run_attachment_queue_scheduler()
self.env.cache.invalidate() self.env.cache.invalidate()
with odoo.registry(self.env.cr.dbname).cursor() as new_cr: with odoo.registry(self.env.cr.dbname).cursor() as new_cr:
new_env = api.Environment( new_env = api.Environment(

39
base_attachment_queue/views/attachment_view.xml → attachment_queue/views/attachment_queue_view.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<odoo> <odoo>
<record id="view_attachment_improved_form" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<record id="view_attachment_queue_form" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="inherit_id" ref="base.view_attachment_form"/> <field name="inherit_id" ref="base.view_attachment_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="/form/*" position="before"> <xpath expr="/form/*" position="before">
@ -14,7 +14,7 @@
</header> </header>
</xpath> </xpath>
<field name="url" position="after"> <field name="url" position="after">
<field name="sync_date"/>
<field name="date_done"/>
<field name="state"/> <field name="state"/>
<field name="file_type"/> <field name="file_type"/>
</field> </field>
@ -26,8 +26,8 @@
</field> </field>
</record> </record>
<record id="view_external_attachment_tree" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<record id="view_attachment_queue_tree" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree default_order='create_date desc'> <tree default_order='create_date desc'>
<field name="name"/> <field name="name"/>
@ -40,8 +40,8 @@
</field> </field>
</record> </record>
<record id="view_external_attachment_search" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<record id="view_attachment_queue_search" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Attachments"> <search string="Attachments">
<field name="name" filter_domain="['|', ('name','ilike',self), ('datas_fname','ilike',self)]" string="Attachment"/> <field name="name" filter_domain="['|', ('name','ilike',self), ('datas_fname','ilike',self)]" string="Attachment"/>
@ -74,34 +74,33 @@
</field> </field>
</record> </record>
<record id="action_attachment" model="ir.actions.act_window">
<field name="name">Meta data Attachments</field>
<record id="action_attachment_queue" model="ir.actions.act_window">
<field name="name">Attachments Queue</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="res_model">ir.attachment.metadata</field>
<field name="res_model">attachment.queue</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="view_id" eval="False"/> <field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_external_attachment_search"/>
<field name="search_view_id" ref="view_attachment_queue_search"/>
</record> </record>
<record id="ir_attachment_view2" model="ir.actions.act_window.view">
<record id="act_open_attachment_que_view_tree" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/> <field eval="10" name="sequence"/>
<field name="view_mode">tree</field> <field name="view_mode">tree</field>
<field name="view_id" ref="view_external_attachment_tree"/>
<field name="act_window_id" ref="action_attachment"/>
<field name="view_id" ref="view_attachment_queue_tree"/>
<field name="act_window_id" ref="action_attachment_queue"/>
</record> </record>
<record id="ir_attachment_view3" model="ir.actions.act_window.view">
<record id="act_open_attachment_que_view_form" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/> <field eval="10" name="sequence"/>
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="view_id" ref="view_attachment_improved_form"/>
<field name="act_window_id" ref="action_attachment"/>
<field name="view_id" ref="view_attachment_queue_form"/>
<field name="act_window_id" ref="action_attachment_queue"/>
</record> </record>
<menuitem id="menu_ir_attachment"
<menuitem id="menu_attachment_queue"
parent="base.next_id_9" parent="base.next_id_9"
sequence="20" sequence="20"
action="action_attachment"/>
action="action_attachment_queue"/>
</odoo> </odoo>

7
base_attachment_queue/data/ir_config_parameter.xml

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="attachment_sync_cron_batch_limit" model="ir.config_parameter">
<field name="key">attachment_sync_cron_batch_limit</field>
<field name="value">200</field>
</record>
</odoo>

10
base_attachment_queue/demo/attachment_metadata_demo.xml

@ -1,10 +0,0 @@
<?xml version="1.0"?>
<odoo noupdate="1">
<record id="attachment_metadata" model="ir.attachment.metadata">
<field name="datas">bWlncmF0aW9uIHRlc3Q=</field>
<field name="datas_fname">attachment_metadata.doc</field>
<field name="name">attachment_metadata.doc</field>
</record>
</odoo>

1
base_attachment_queue/models/__init__.py

@ -1 +0,0 @@
from . import attachment

6
base_attachment_queue/readme/DESCRIPTION.rst

@ -1,6 +0,0 @@
This module extends ir.attachment model with some new fields for a better control for import and export of files.
The main feature is the possibility to create a queue of attachment and have a cron process it.
The attachments will be processed depending on their type.
An example of the use of this module, can be found in the module `attachment_synchronize`.

3
base_attachment_queue/security/ir.model.access.csv

@ -1,3 +0,0 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_attachment_metadata_user,ir.attachment.metadata.user,model_ir_attachment_metadata,,1,0,0,0
access_attachment_metadata_manager,ir.attachment.metadata.manager,model_ir_attachment_metadata,base.group_no_one,1,1,1,1
Loading…
Cancel
Save