Skip to content

Commit

Permalink
[ADD] lighting_import_attachment_product_queue_job: new module
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed Apr 29, 2024
1 parent 55e5e07 commit a2ca97e
Show file tree
Hide file tree
Showing 16 changed files with 691 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lighting_import_attachment_product_queue_job/README.rst
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.
1 change: 1 addition & 0 deletions lighting_import_attachment_product_queue_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions lighting_import_attachment_product_queue_job/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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": [
"views/queue_job_views.xml",
"views/lighting_import_attachment_views.xml",
"views/lighting_import_attachment_file_views.xml",
],
}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import fields, models


class LightingImportAttachment(models.Model):
_inherit = "lighting.import.attachment"

queue_job_import = fields.Boolean(default=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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,
)
file_job_error = fields.Boolean(compute="_compute_file_job_error")

@api.depends("file_jobs_ids", "file_jobs_ids.state")
def _compute_file_job_error(self):
for rec in self:
rec.file_job_error = bool(
rec.file_jobs_ids.filtered(lambda r: r.state == "failed")
)

def import_attachments(self):
if not self.import_attachment_id.queue_job_import:
return super().import_attachments()
for rec in self:
queue_obj = self.env["queue.job"]
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 lighting_import_attachment_product_queue_job/models/queue_job.py
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()
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]>
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a2ca97e

Please sign in to comment.