Skip to content

Commit

Permalink
ODK Importer: Fixed Program enrollement issue
Browse files Browse the repository at this point in the history
Signed-off-by: Manoj Kumar <[email protected]>
  • Loading branch information
mkumar-02 committed Dec 9, 2024
1 parent 3e660d2 commit 6477725
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion g2p_odk_importer_program/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Part of Newlogic G2P. See LICENSE file for full copyright and licensing details.

from . import odk_client
from . import odk_config
from . import odk_import
19 changes: 10 additions & 9 deletions g2p_odk_importer_program/models/odk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@


def patched_addl_data(self, mapped_json):
config = self.env["odk.config"].browse(self.id)
odk_import = self.env["odk.import"].browse(self.id)

program_id = config.program.id

if "program_registrant_info_ids" in mapped_json:
prog_reg_info = mapped_json.get("program_registrant_info_ids", None)

if not program_id:
del mapped_json["program_registrant_info_ids"]
return mapped_json
program_id = odk_import.target_program.id

if program_id:
mapped_json["program_membership_ids"] = [
(
0,
Expand All @@ -27,6 +21,13 @@ def patched_addl_data(self, mapped_json):
)
]

if "program_registrant_info_ids" in mapped_json:
prog_reg_info = mapped_json.get("program_registrant_info_ids", None)

if not program_id:
del mapped_json["program_registrant_info_ids"]
return mapped_json

mapped_json["program_registrant_info_ids"] = [
(
0,
Expand Down
7 changes: 0 additions & 7 deletions g2p_odk_importer_program/models/odk_config.py

This file was deleted.

12 changes: 12 additions & 0 deletions g2p_odk_importer_program/models/odk_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import api, fields, models


class OdkImport(models.Model):
_inherit = "odk.import"

target_program = fields.Many2one("g2p.program", domain="[('target_type', '=', target_registry)]")

@api.onchange("target_registry")
def onchange_target_registry(self):
for rec in self:
rec.target_program = None
6 changes: 2 additions & 4 deletions g2p_odk_importer_program/views/odk_import_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
<field name="model">odk.import</field>
<field name="inherit_id" ref="g2p_odk_importer.view_odk_import_form" />
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<group string="Program details">
<field name="program" />
</group>
<xpath expr="//field[@name='target_registry']" position="after">
<field name="target_program" />
</xpath>
</field>
</record>
Expand Down

0 comments on commit 6477725

Please sign in to comment.