Skip to content

Commit

Permalink
T2167 Follow guidelines for job queues
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Feb 24, 2025
1 parent 11ff170 commit 1d2765c
Show file tree
Hide file tree
Showing 67 changed files with 341 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ def _sort_move_line(move_line):
def process_bank_statement_line(self, st_line_ids, data):
# Execute a job to speedup the interface. The returned data is not used anyway.
self.with_delay(
channel="root.reconcile_compassion"
channel="root.accounting",
priority=100,
identity_key=self._name
+ ".process_bank_statement_line."
+ str(st_line_ids),
description="Process bank statement line",
)._process_bank_statement_line(st_line_ids, data)
return {}

Expand Down
45 changes: 26 additions & 19 deletions account_reconcile_compassion/models/bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ def button_reopen(self):
def button_post(self):
self.invoice_ids.filtered(lambda i: i.state == "draft").action_post()
super().button_post()
self.with_delay(channel="root.reconcile_compassion")._auto_reconcile()
self.with_delay(
channel="root.accounting",
priority=100,
identity_key=self._name + "._auto_reconcile." + str(self.ids),
description="Automatic reconciliation of bank statement",
)._auto_reconcile()

def button_validate(self):
"""
Expand Down Expand Up @@ -103,22 +108,22 @@ def button_validate(self):

def auto_reconcile(self):
"""Auto reconcile matching invoices through jobs to avoid timeouts"""
if self.env.context.get("async_mode", True):
self.with_company(self.journal_id.company_id.id).with_delay(
channel="root.reconcile_compassion"
)._auto_reconcile()
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": "Auto reconcile",
"type": "success",
"message": "Reconciliation job has been queued",
"sticky": False,
},
}
else:
self._auto_reconcile()
self.with_company(self.journal_id.company_id.id).with_delay(
channel="root.accounting",
priority=100,
identity_key=self._name + "._auto_reconcile." + str(self.ids),
description="Automatic reconciliation of bank statement",
)._auto_reconcile()
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": "Auto reconcile",
"type": "success",
"message": "Reconciliation job has been queued",
"sticky": False,
},
}

def _auto_reconcile(self):
"""Inspired by the `if model.auto_reconcile` part of _apply_rules()"""
Expand All @@ -140,13 +145,15 @@ def _auto_reconcile(self):

for line_id, result in matching_amls.items():
self.with_delay(
channel="root.reconcile_compassion"
channel="root.accounting",
priority=100,
identity_key=self._name + "._reconcile_single_line." + str(line_id),
description="Auto reconcile single line",
)._reconcile_single_line(
line_id, result, bank_statement, reconcile_model
)

def _reconcile_single_line(self, line_id, result, bank_statement, reconcile_model):
"""Reconcile method to run it as a job"""
if result["aml_ids"]:
line = bank_statement.line_ids.browse(line_id)
move_lines = self.env["account.move.line"].browse(result["aml_ids"])
Expand Down
2 changes: 1 addition & 1 deletion child_compassion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from odoo.addons.message_center_compassion.tools.load_mappings import load_mapping_files

from . import controllers, models, wizards
from . import models, wizards


def load_mappings(cr, registry):
Expand Down
1 change: 0 additions & 1 deletion child_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
"data/fcp.spiritual.activity.csv",
"data/fo.high.risk.csv",
"data/fo.disaster.loss.csv",
"data/queue_job.xml",
"report/childpack.xml",
"report/external_layout.xml",
"report/child_picture.xml",
Expand Down
1 change: 0 additions & 1 deletion child_compassion/controllers/__init__.py

This file was deleted.

53 changes: 0 additions & 53 deletions child_compassion/controllers/web_children_hold.py

This file was deleted.

22 changes: 22 additions & 0 deletions child_compassion/data/gmc_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<field name="request_type">POST</field>
<field name="batch_send">1</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
<field name="auto_process" eval="False" />
</record>
<!-- Hold Message Release -->
<record id="release_hold" model="gmc.action">
Expand All @@ -35,6 +37,7 @@
<field name="request_type">POST</field>
<field name="batch_send">1</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Get beneficiaries details -->
<record id="beneficiaries_details" model="gmc.action">
Expand All @@ -48,6 +51,7 @@
>beneficiaries/${object.global_id}/details</field>
<field name="request_type">GET</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
<field name="success_method">details_answer</field>
<field name="no_outgoing_data" eval="True" />
</record>
Expand All @@ -63,6 +67,7 @@
>churchpartners/${object.fcp_id}/kits/icpkit</field>
<field name="request_type">GET</field>
<field name="auto_process">1</field>
<field name="job_channel">root.fcp_compassion</field>
<field name="no_outgoing_data" eval="True" />
<field name="success_method">details_answer</field>
</record>
Expand All @@ -80,6 +85,7 @@
<field name="request_type">POST</field>
<field name="no_outgoing_data">True</field>
<field name="auto_process">1</field>
<field name="job_channel">root.fcp_compassion</field>
</record>
<record id="field_office_details" model="gmc.action">
<field name="direction">out</field>
Expand All @@ -94,6 +100,7 @@
>fieldoffices/${object.field_office_id}/kits/fieldofficekit</field>
<field name="request_type">GET</field>
<field name="auto_process">1</field>
<field name="job_channel">root.field_office_compassion</field>
</record>
<!-- Reservation Message Creation -->
<record id="create_reservation" model="gmc.action">
Expand All @@ -116,6 +123,7 @@
<field name="success_method">reservation_create_answer</field>
<field name="failure_method">reservation_create_answer_fail</field>
<field name="priority">50</field>
<field name="job_channel">root.fcp_compassion</field>
</record>
<!-- Reservation Message Creation for Participant -->
<record id="beneficiary_reservation" model="gmc.action">
Expand All @@ -137,6 +145,7 @@
<field name="success_method">reservation_create_answer</field>
<field name="failure_method">reservation_create_answer_fail</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Reservation Message Release -->
<record id="cancel_reservation" model="gmc.action">
Expand All @@ -159,6 +168,7 @@
<field name="batch_send">1</field>
<field name="success_method">reservation_cancel_answer</field>
<field name="priority">50</field>
<field name="job_channel">root.fcp_compassion</field>
</record>
<record id="cancel_reservation_child" model="gmc.action">
<field name="direction">out</field>
Expand All @@ -180,6 +190,7 @@
<field name="batch_send">1</field>
<field name="success_method">reservation_cancel_answer</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Participant Major Revision -->
<record id="major_revision" model="gmc.action">
Expand All @@ -191,6 +202,7 @@
name="description"
>This will update the child with the major changes that happened.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
</record>
<record id="beneficiary_kit" model="gmc.action">
<field name="direction">in</field>
Expand All @@ -201,6 +213,7 @@
name="description"
>This will update the child with the fresh information.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- ICP Kit -->
<record id="icp_kit" model="gmc.action">
Expand All @@ -212,6 +225,7 @@
name="description"
>This will update the project with the fresh information.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.fcp_compassion</field>
</record>
<!-- Participant CDPR Messages -->
<record id="beneficiary_cdpr" model="gmc.action">
Expand All @@ -223,6 +237,7 @@
>This handles the reception of a Participant CDPR.</field>
<field name="auto_process">1</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Reservation Messages -->
<record id="reservation_to_hold" model="gmc.action">
Expand All @@ -235,6 +250,7 @@
>This handles the reception of a reserved Participant.</field>
<field name="auto_process">1</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Household Major Revision -->
<record id="major_revision_household" model="gmc.action">
Expand All @@ -246,6 +262,7 @@
>This will update the household with the major changes that happened.</field>
<field name="incoming_method">process_commkit</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Participant Note -->
<record id="beneficiary_note" model="gmc.action">
Expand All @@ -256,6 +273,7 @@
name="description"
>This handles the reception of a Participant note.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Lifecycle Message -->
<record id="new_life_cycle" model="gmc.action">
Expand All @@ -266,6 +284,7 @@
name="description"
>This will create a new life cycle event.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Project Message -->
<record id="new_project_cycle" model="gmc.action">
Expand All @@ -276,6 +295,7 @@
name="description"
>This will create a new project cycle event.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.fcp_compassion</field>
</record>
<!-- Reinstatement Message -->
<record id="new_reinstatement_notification" model="gmc.action">
Expand All @@ -287,6 +307,7 @@
name="description"
>This will create a new reinstatement notification.</field>
<field name="auto_process">1</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Deprecated ! Field Office Disaster Message -->
<record id="field_office_disaster" model="gmc.action">
Expand Down Expand Up @@ -334,6 +355,7 @@
>This handles the reception of a Participant Hold Removal.</field>
<field name="auto_process">1</field>
<field name="priority">50</field>
<field name="job_channel">root.child_compassion</field>
</record>
<!-- Weekly Planning Message Creation -->
<record id="create_demand_planning" model="gmc.action">
Expand Down
36 changes: 16 additions & 20 deletions child_compassion/data/queue_job.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
<!-- Channels -->
<record id="channel_child" model="queue.job.channel">
<field name="name">child_compassion</field>
<field name="parent_id" ref="queue_job.channel_root" />
<field
name="parent_id"
ref="message_center_compassion.channel_gmc_pool"
/>
</record>
<record id="channel_global_pool" model="queue.job.channel">
<field name="name">global_pool</field>
<field name="parent_id" ref="channel_child" />
<record id="channel_fcp" model="queue.job.channel">
<field name="name">fcp_compassion</field>
<field
name="parent_id"
ref="message_center_compassion.channel_gmc_pool"
/>
</record>

<!-- Job functions -->
<record id="unlink_job" model="queue.job.function">
<field name="model_id" ref="model_compassion_child" />
<field name="method">unlink_job</field>
<field name="channel_id" ref="channel_child" />
</record>
<record id="update_pictures_job" model="queue.job.function">
<field name="model_id" ref="model_compassion_child" />
<field name="method">update_child_pictures</field>
<field name="channel_id" ref="channel_child" />
</record>
<record id="hold_children_job" model="queue.job.function">
<field name="model_id" ref="model_compassion_childpool_search" />
<field name="method">hold_children_job</field>
<field name="channel_id" ref="channel_global_pool" />
<record model="queue.job.channel" id="channel_field_office">
<field name="name">field_office_compassion</field>
<field
name="parent_id"
ref="message_center_compassion.channel_gmc_pool"
/>
</record>
</odoo>
Loading

0 comments on commit 1d2765c

Please sign in to comment.