-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] lighting_import_attachment_product_queue_job: new module
- Loading branch information
Showing
17 changed files
with
780 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
==================================== | ||
Lighting Attachment Import Queue Job | ||
==================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:840af3aeacaef5a0f3a40a1ca30d83e77e18df2bb394f02083249556620ff324 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-NuoBiT%2Flighting--vertical-lightgray.png?logo=github | ||
:target: https://github.com/NuoBiT/lighting-vertical/tree/16.0/lighting_import_attachment_product_queue_job | ||
:alt: NuoBiT/lighting-vertical | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Management and processing of the import of product attachments with queues jobs | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/NuoBiT/lighting-vertical/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/NuoBiT/lighting-vertical/issues/new?body=module:%20lighting_import_attachment_product_queue_job%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* NuoBiT Solutions SL | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `NuoBiT <https://www.nuobit.com>`__: | ||
|
||
* Frank Cespedes <[email protected]> | ||
* Eric Antones <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `NuoBiT/lighting-vertical <https://github.com/NuoBiT/lighting-vertical/tree/16.0/lighting_import_attachment_product_queue_job>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
20 changes: 20 additions & 0 deletions
20
lighting_import_attachment_product_queue_job/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
{ | ||
"name": "Lighting Attachment Import Queue Job", | ||
"summary": "Management and processing of the import of product " | ||
"attachments with queues jobs", | ||
"version": "16.0.1.0.0", | ||
"author": "NuoBiT Solutions SL", | ||
"license": "AGPL-3", | ||
"category": "Lighting", | ||
"website": "https://github.com/NuoBiT/lighting-vertical", | ||
"depends": ["lighting_import_attachment_product", "queue_job"], | ||
"data": [ | ||
"data/lighting_import_attachment_product_queue_job.xml", | ||
"views/queue_job_views.xml", | ||
"views/lighting_import_attachment_views.xml", | ||
"views/lighting_import_attachment_file_views.xml", | ||
], | ||
} |
20 changes: 20 additions & 0 deletions
20
...import_attachment_product_queue_job/data/lighting_import_attachment_product_queue_job.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) --> | ||
<odoo> | ||
<record id="import_attachment_file" model="queue.job.channel"> | ||
<field name="name">import_attachment_file</field> | ||
<field name="parent_id" ref="queue_job.channel_root" /> | ||
</record> | ||
<record | ||
id="job_function_execute_delayed_import_attachments" | ||
model="queue.job.function" | ||
> | ||
<field | ||
name="model_id" | ||
ref="lighting_import_attachment_product_queue_job.model_lighting_import_attachment_file" | ||
/> | ||
<field name="method">execute_delayed_import_attachments</field> | ||
<field name="channel_id" ref="import_attachment_file" /> | ||
</record> | ||
</odoo> |
3 changes: 3 additions & 0 deletions
3
lighting_import_attachment_product_queue_job/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import lighting_import_attachment | ||
from . import lighting_import_attachment_file | ||
from . import queue_job |
54 changes: 54 additions & 0 deletions
54
lighting_import_attachment_product_queue_job/models/lighting_import_attachment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class LightingImportAttachment(models.Model): | ||
_inherit = "lighting.import.attachment" | ||
|
||
@api.model | ||
def change_state_workflow(self): | ||
state = super().change_state_workflow() | ||
state["checked"].append("pending") | ||
state["pending"] = ["imported"] | ||
return state | ||
|
||
queue_job_import = fields.Boolean(default=False) | ||
error_file_ids = fields.One2many( | ||
comodel_name="lighting.import.attachment.file", | ||
inverse_name="import_attachment_id", | ||
domain=[ | ||
"|", | ||
("message_info", "not in", (False, "checked", "imported")), | ||
("job_state", "not in", (False, "done")), | ||
], | ||
) | ||
state = fields.Selection( | ||
selection=[ | ||
("draft", "Draft"), | ||
("checked", "Checked"), | ||
("pending", "Pending"), | ||
("imported", "Imported"), | ||
], | ||
ondelete={"pending": "set default"}, | ||
default="draft", | ||
compute="_compute_state", | ||
store=True, | ||
required=True, | ||
) | ||
|
||
@api.depends( | ||
"file_ids", | ||
"file_ids.message_info", | ||
"file_ids.job_state", | ||
"file_ids.message_info", | ||
) | ||
def _compute_state(self): | ||
res = super()._compute_state() | ||
for rec in self: | ||
if rec.queue_job_import: | ||
job_states = {file.job_state for file in rec.file_ids} | ||
if {"pending", "error"} & job_states: | ||
rec.state = "pending" | ||
return res |
77 changes: 77 additions & 0 deletions
77
lighting_import_attachment_product_queue_job/models/lighting_import_attachment_file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import _, api, fields, models | ||
|
||
|
||
class LightingImportAttachmentFile(models.Model): | ||
_inherit = "lighting.import.attachment.file" | ||
|
||
file_jobs_ids = fields.Many2many( | ||
comodel_name="queue.job", | ||
relation="lighting_import_attachment_file_queue_job_rel", | ||
column1="file_id", | ||
column2="job_id", | ||
string="Queue Jobs", | ||
copy=False, | ||
) | ||
job_state = fields.Selection( | ||
selection=[ | ||
("pending", "Pending"), | ||
("done", "Done"), | ||
("error", "Error"), | ||
("cancel", "Cancelled"), | ||
], | ||
compute="_compute_job_state", | ||
default=False, | ||
store=True, | ||
) | ||
|
||
@api.depends("file_jobs_ids", "file_jobs_ids.state") | ||
def _compute_job_state(self): | ||
for rec in self: | ||
if rec.file_jobs_ids: | ||
states = set(rec.file_jobs_ids.mapped("state")) | ||
if {"enqueued", "pending", "started", "wait_dependencies"} & states: | ||
rec.job_state = "pending" | ||
elif {"done"} & states: | ||
rec.job_state = "done" | ||
elif {"failed"} & states: | ||
rec.job_state = "error" | ||
elif {"cancelled"} & states: | ||
rec.job_state = "cancel" | ||
else: | ||
rec.job_state = False | ||
|
||
def import_attachments(self): | ||
if not self.import_attachment_id.queue_job_import: | ||
return super().import_attachments() | ||
queue_obj = self.env["queue.job"] | ||
for rec in self: | ||
new_delay = rec.with_delay().execute_delayed_import_attachments() | ||
job = queue_obj.search([("uuid", "=", new_delay.uuid)], limit=1) | ||
rec.file_jobs_ids |= job | ||
|
||
def execute_delayed_import_attachments(self): | ||
self.ensure_one() | ||
return super().import_attachments() | ||
|
||
def action_show_queue_job_details(self): | ||
self.ensure_one() | ||
view = self.env.ref( | ||
"lighting_import_attachment_product_queue_job." | ||
"lighting_import_attachment_file_queue_job_view_form" | ||
) | ||
return { | ||
"name": _("Queue Job Details"), | ||
"type": "ir.actions.act_window", | ||
"view_mode": "form", | ||
"res_model": "lighting.import.attachment.file", | ||
"views": [(view.id, "form")], | ||
"view_id": view.id, | ||
"target": "new", | ||
"res_id": self.id, | ||
"context": dict( | ||
self.env.context, | ||
), | ||
} |
12 changes: 12 additions & 0 deletions
12
lighting_import_attachment_product_queue_job/models/queue_job.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
|
||
from odoo import models | ||
|
||
|
||
class QueueJob(models.Model): | ||
_inherit = "queue.job" | ||
|
||
def requeue_sudo(self): | ||
self.sudo().requeue() |
4 changes: 4 additions & 0 deletions
4
lighting_import_attachment_product_queue_job/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* `NuoBiT <https://www.nuobit.com>`__: | ||
|
||
* Frank Cespedes <[email protected]> | ||
* Eric Antones <[email protected]> |
1 change: 1 addition & 0 deletions
1
lighting_import_attachment_product_queue_job/readme/DESCRIPTION.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Management and processing of the import of product attachments with queues jobs |
Binary file added
BIN
+6.19 KB
lighting_import_attachment_product_queue_job/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.