Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move import match to base #8

Merged
merged 4 commits into from
Sep 7, 2023
Merged

move import match to base #8

merged 4 commits into from
Sep 7, 2023

Conversation

emjay0921
Copy link
Collaborator

No description provided.

@emjay0921 emjay0921 linked an issue Jul 5, 2023 that may be closed by this pull request
Comment on lines 132 to 149
@api.onchange("field_id")
def _onchange_field_id(self):
for rec in self:
field_id = rec.field_id.id
fields_list = []
for field in rec.match_id.field_ids:
new_id_str = str(field.id)
if not new_id_str.find("NewId_'virtual"):
fields_list.append(field.field_id.id)

duplicate_counter = 0
for duplicate_field in fields_list:
if duplicate_field == field_id:
duplicate_counter += 1

if duplicate_counter > 1:
raise ValidationError(_("Field '%s', already exists!") % rec.field_id.field_description)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@api.onchange("field_id")
def _onchange_field_id(self):
for rec in self:
field_id = rec.field_id.id
fields_list = []
for field in rec.match_id.field_ids:
new_id_str = str(field.id)
if not new_id_str.find("NewId_'virtual"):
fields_list.append(field.field_id.id)
duplicate_counter = 0
for duplicate_field in fields_list:
if duplicate_field == field_id:
duplicate_counter += 1
if duplicate_counter > 1:
raise ValidationError(_("Field '%s', already exists!") % rec.field_id.field_description)
_sql_constraints = [
(
"field_id_uniq",
"UNIQUE(field_id, match_id)",
"Field should be unique for each match",
)
]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is edited, sql_constraints is not good here is we should allow different sub-fields for a one2many field.

required=True,
help="Fields to Match in Importing",
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_sql_constraints = [
(
"model_id_uniq",
"UNIQUE(model_id)",
"Model should be unique!",
)
]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed, as we can have multiple Import Match Configuration for a single model.

Comment on lines 87 to 93
available = self.search([("model_name", "=", model_name)])
field_to_match = []
for record in available:
field_to_match.append(record.field_ids.mapped("name"))
for f in record.field_ids:
if f.name in fields or f.field_id.name in fields:
result |= record
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
available = self.search([("model_name", "=", model_name)])
field_to_match = []
for record in available:
field_to_match.append(record.field_ids.mapped("name"))
for f in record.field_ids:
if f.name in fields or f.field_id.name in fields:
result |= record
available = self.search([("model_name", "=", model_name)], limit=1)
if not available:
return [], []
field_to_match = []
for f in available.field_ids:
if f.name in fields or f.field_id.name in fields:
result |= available
field_to_match.append(f.name)

@emjay0921
Copy link
Collaborator Author

Added a boolean field in import match to have an option if matched data will overwitten or ignored.

@gonzalesedwin1123 gonzalesedwin1123 changed the base branch from 15.0 to 15.1 August 13, 2023 21:45
Copy link
Member

@gonzalesedwin1123 gonzalesedwin1123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the errors in the automated test

@gonzalesedwin1123 gonzalesedwin1123 merged commit f3b3c49 into 15.1.1 Sep 7, 2023
1 check passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend Importing Function with the Import Matching
3 participants