Skip to content

Commit

Permalink
fixed 'Local Grade Level' is empty in revision, fixed revision applie…
Browse files Browse the repository at this point in the history
…s all revisions to same type on single child, need to see how to handle update/create
  • Loading branch information
Prazn committed Aug 7, 2024
1 parent 67a87e9 commit cda14ef
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion child_compassion/models/child_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def major_revision(self, commkit_data):
child = self.search([("global_id", "=", global_id)])
if child:
child_ids.append(child.id)
child._major_revision(self.json_to_data(child_data))
child._major_revision(self.json_to_data(child_data, data_filter=("child_id", "=", child.id)))
return child_ids

@api.model
Expand Down
4 changes: 2 additions & 2 deletions child_compassion/models/global_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def _compute_image_thumb(self):
self._load_image(True, False)

@api.model
def json_to_data(self, json, mapping_name=None):
odoo_data = super().json_to_data(json, mapping_name)
def json_to_data(self, json, mapping_name=None, data_filter=None):
odoo_data = super().json_to_data(json, mapping_name, data_filter)

# Put firstname in preferred_name if not defined
preferred_name = odoo_data.get("preferred_name")
Expand Down
1 change: 1 addition & 0 deletions child_compassion/models/major_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def get_child_field_mapping(self):
"Last Name": "lastname",
"Planned Completion Date": "completion_date",
"Preferred Name": "preferred_name",
"Local Grade Level": "local_grade_level",
}

def get_field_value(self):
Expand Down
4 changes: 2 additions & 2 deletions message_center_compassion/models/compassion_mapped_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def data_to_json(self, mapping_name=None):
return result[0] if len(result) == 1 else result

@api.model
def json_to_data(self, json, mapping_name=None):
def json_to_data(self, json, mapping_name=None, data_filter=None):
"""
Function to convert JSON into odoo record values.
Expand Down Expand Up @@ -104,7 +104,7 @@ def json_to_data(self, json, mapping_name=None):
)
data.update(json_spec.from_json(sub_data))
else:
data.update(json_spec.from_json(json_value, ("child_id", "=", json_spec.mapping_id.id)))
data.update(json_spec.from_json(json_value, data_filter))
break # break from attempts if successful
res.append(data)
return res[0] if len(res) == 1 and not isinstance(res[0], tuple) else res
13 changes: 7 additions & 6 deletions message_center_compassion/models/field_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def to_json(self, odoo_value):

return res

def from_json(self, json_value, filter=None):
def from_json(self, json_value, data_filter=None):
"""
Converts the JSON value to Odoo field value.
:param json_value: JSON representation of the field
Expand Down Expand Up @@ -200,7 +200,7 @@ def from_json(self, json_value, filter=None):
},
)
if self.relational_field or self.sub_mapping_id:
converted_value = self._json_to_relational_value(converted_value, filter)
converted_value = self._json_to_relational_value(converted_value, data_filter)
if converted_value == "deep_relation":
# We cannot handle data for a complex relational field
# (only one descendent).
Expand All @@ -212,7 +212,7 @@ def from_json(self, json_value, filter=None):
return {}
return {field_name: converted_value}

def _json_to_relational_value(self, value, filter=None):
def _json_to_relational_value(self, value, data_filter=None):
"""
Converts a received JSON value into valid data for a relational record
Example of output:
Expand Down Expand Up @@ -257,8 +257,8 @@ def _json_to_relational_value(self, value, filter=None):
(search_field, "=ilike", str(search_val)),
]

if filter:
search_arguments.extend(["&", filter])
if data_filter:
search_arguments[:0] = ["&", data_filter]

records = relational_model.search(search_arguments)

Expand All @@ -276,7 +276,8 @@ def _json_to_relational_value(self, value, filter=None):
if not records and self.allow_relational_creation:
to_create.append(val)
continue
orm_vals.extend([(4, rid) for rid in records.ids])
orm_operation = 4 if self.relational_write_mode == "overwrite" else 4
orm_vals.extend([(orm_operation , rid) for rid in records.ids])
if to_update:
orm_vals.extend([(1, rid, val) for rid in records.ids])
else:
Expand Down

0 comments on commit cda14ef

Please sign in to comment.