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

[14.0][IMP] edi_oca: recompute exchange filename after getting related record #21

Closed
wants to merge 1 commit into from

Conversation

QuocDuong1306
Copy link
Owner

@QuocDuong1306 QuocDuong1306 commented Aug 8, 2024

Context:

  • When a related record exists, {record_name} uses the display name of the related record to differentiate the filename appropriately.

  • When there is no related record (e.g., when creating an exchange record from storage or an endpoint), {record_name} uses the exchange record's display name.

    • In this case, if {record_name} and {type.code} are both used in the filename pattern (e.g., "{record_name}-{type.code}-{dt}"), then the filename will end up with some redundant information when the exchange type name and code have similar slugs (e.g., "Test CSV Output" and "test_csv_output").
    • To avoid that, we remove the type name from the exc record's display name when these conditions are met

Changes:

  • Remove the type name from the exc record's display name when a duplication of the type code occurs, utilizing the context to handle this adjustment.

@trobz-bot trobz-bot bot added enhancement New feature or request Tests labels Aug 8, 2024
Repository owner deleted a comment from trobz-bot bot Aug 8, 2024
Repository owner deleted a comment from trobz-bot bot Aug 8, 2024
Comment on lines 100 to 97
self.assertEqual(
record.exchange_filename,
"wood-corner-test_csv_output-2020-10-21-12-00-00.csv",
)

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual(
record.exchange_filename,
"wood-corner-test_csv_output-2020-10-21-12-00-00.csv",
)
self.assertEqual(
record.exchange_filename,
f"{slugify(self.partner.display_name)}-test_csv_output-2020-10-21-12-00-00.csv",
)

@thienvh332
Copy link

Hello @QuocDuong1306,
Can you be more specific about why we need this change in the description?

I'm not seeing the benefit of renaming here. Because even if it's a {record_name}-{type.code} use case, like your test case, it still contains the identifier in the file_name. It can still differentiate the file_name between 2 edi.exchange.record with the same exchange.record.type.

@QuocDuong1306
Copy link
Owner Author

Can you be more specific about why we need this change in the description?

Did you have a look at the card (3395)?

Because even if it's a {record_name}-{type.code} use case, like your test case, it still contains the identifier in the file_name. It can still differentiate the file_name between 2 edi.exchange.record with the same exchange.record.type

Actually, we don't want the test-csv-output (exchange type) appear twice

@QuocDuong1306 QuocDuong1306 force-pushed the 14.0-imp-edi_oca-exchange-filename branch from 7d4e588 to 6808be3 Compare August 23, 2024 03:38
@thienvh332
Copy link

Thanks for your reply @QuocDuong1306 ,

  • I have no context for this issue if you don't mention it. So if possible please think about people like me.
  • About the problem of avoiding duplicate names with the same record_name and type.code, you can check and fix them right at the first calculation, right? Because if you recalculate when it is assigned to releated, it will be duplicated before it is assigned.

@QuocDuong1306 QuocDuong1306 force-pushed the 14.0-imp-edi_oca-exchange-filename branch from 6808be3 to 185be18 Compare August 27, 2024 02:59
@QuocDuong1306
Copy link
Owner Author

Hello a @thienvh332 , thanks for your suggestions, the PR has been updated, could you have a look?

@@ -130,7 +130,7 @@ def _compute_related_name(self):
related_record = rec.record
rec.related_name = related_record.display_name if related_record else ""

@api.depends("model", "type_id")
@api.depends("model", "res_id", "type_id")

Choose a reason for hiding this comment

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

If it is not possible to duplicate then I think there is no need to recalculate when res_id changes

Suggested change
@api.depends("model", "res_id", "type_id")
@api.depends("model", "type_id")

@QuocDuong1306 QuocDuong1306 force-pushed the 14.0-imp-edi_oca-exchange-filename branch from 185be18 to 9963071 Compare August 29, 2024 03:21
Copy link

@thienvh332 thienvh332 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@nilshamerlinck nilshamerlinck left a comment

Choose a reason for hiding this comment

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

commit message seems outdated

name = "[{}] {}".format(rec.type_id.name, rec_name)
name = (
"[{}] {}".format(rec.type_id.name, rec_name)
if rec._context.get("display_exchange_type_name", True)

Choose a reason for hiding this comment

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

Suggested change
if rec._context.get("display_exchange_type_name", True)
if rec._context.get("include_exchange_type_name", True)

# Avoid duplicating type code in filename
if "{type.code}" in pattern and slugify(self.code) == slugify(self.name):
exchange_record = exchange_record.with_context(
display_exchange_type_name=False

Choose a reason for hiding this comment

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

Suggested change
display_exchange_type_name=False
include_exchange_type_name=False

@@ -222,6 +222,11 @@ def _make_exchange_filename(self, exchange_record):
ext = self.exchange_file_ext
pattern = pattern + ".{ext}"
dt = self._make_exchange_filename_datetime()
# Avoid duplicating type code in filename
if "{type.code}" in pattern and slugify(self.code) == slugify(self.name):

Choose a reason for hiding this comment

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

this will be true in most cases:

image

wasn't the case occurring only without a related record?

Copy link
Owner Author

@QuocDuong1306 QuocDuong1306 Aug 29, 2024

Choose a reason for hiding this comment

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

yes nils, updated

Actually, this context will not affect if we go through a related record. But maybe needing a check for a related record is better

Choose a reason for hiding this comment

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

ok, can you improve the PR description to distinct the 2 cases:

  • when we have a related record, {record_name} will...
  • when we don't, ..., which can lead to redundant information in the filename due to...

also need to update commit name to reflect the new implementation

Copy link
Owner Author

@QuocDuong1306 QuocDuong1306 Aug 29, 2024

Choose a reason for hiding this comment

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

Thank nils, the PR is updated as suggested

@QuocDuong1306 QuocDuong1306 force-pushed the 14.0-imp-edi_oca-exchange-filename branch from 9963071 to 9f62e85 Compare August 29, 2024 04:41
@QuocDuong1306 QuocDuong1306 force-pushed the 14.0-imp-edi_oca-exchange-filename branch from 9f62e85 to e9a26ed Compare August 29, 2024 07:55
@nilshamerlinck
Copy link

Without a related record (e.g., when creating an exchange record from storage or an endpoint), the exchange type name and code may appear similar when "slugified"

I think something is missing in that part about {record_name}

@QuocDuong1306
Copy link
Owner Author

Hi nils, updated for that part

@nilshamerlinck
Copy link

In these cases, the exchange type name and code might become similar when "slugified" (e.g., "Test CSV Output" and "test_csv_output"), leading to redundant information in the filename if {record_name} and {type.code} are both used in the filename pattern (e.g., "{record_name}-{type.code}-{dt}").

I believe you are referring to the second case, right? So it should be: "In this case" (singular), and it should be indented under that case

  • In this case, if {record_name} and {type.code} are both used in the filename pattern (e.g., "{record_name}-{type.code}-{dt}"), then the filename will end up with some redundant information when the exchange type name and code have similar slugs (e.g., "Test CSV Output" and "test_csv_output").
    • To avoid that, we remove the type name from the exc record's display name when these conditions are met

@QuocDuong1306
Copy link
Owner Author

QuocDuong1306 commented Aug 29, 2024

Very sensitive, thank nils, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants