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

Support Attaching Files - Revised #509

Merged
merged 4 commits into from
Dec 30, 2021

Conversation

cgunther
Copy link
Contributor

This is a continuation of #245, addressing some snags I had using it to address a similar need (#245 (comment)). Thanks @jordan-allan for the great starting point.

The conflict between Records#type and Invoice.search_only_field :type is now resolved and there's a check to ensure future conflicts between public/protected methods and fields aren't introduced. More on this is the commit message.

The casing of the record type is also resolved to be lower camelcase instead of just lowercase.

Broadly I have some concerns about calling this action attach_file as NetSuite actually calls it attach (with a corresponding detach) and can be used for both files and contacts as the thing being attached to another record. My immediate need was for attaching files and that aligned with @jordan-allan's work, so I stuck on that route. Thinking ahead, if we wanted to support attaching contacts, would we introduce a new action attach_contact, or would we rename attach_file to attach, leading to a breaking change/deprecation for anyone using attach_file? To support contacts, I believe the only thing that would have to change is where the attachedRecord @type is hardcoded to "file" to pull the type from the record itself (and rename the @file variable accordingly).

jordan-allan and others added 4 commits December 23, 2021 10:41
`Records#type` conflicted with the `search_only_field :type` on
`Invoice`, such that when `AttachFile` called `@object.type`, you'd get
 the search-only field value (often `nil`), rather than the result of
 `Records#type`.

`Records#type` was renamed to `Records#netsuite_type` to avoid such
conflicts.

Furthermore, I added a check to ensure that future fields and
public/protected methods don't conflict. I tried to include private
methods too for completeness, but since we want to check up the ancestor
tree to see if a method is defined, `search_only_field :print` on
`Invoice` conflicted with `Kernel#print` in the ancestor tree. For now I
opted to turning a blind eye to conflicts with private methods, however
the alternative would be to translate to another method name for
`search_only_field :print`, similar to the `class/klass` translation.
For a record like `SalesOrder`, this is expected to return `salesOrder`,
at least for the `attach_file` call, which is the only one calling
`Records#netsuite_type` currently.
Copy link
Member

@iloveitaly iloveitaly left a comment

Choose a reason for hiding this comment

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

Thank you!

Thinking ahead, if we wanted to support attaching contacts, would we introduce a new action attach_contact, or would we rename attach_file to attach, leading to a breaking change/deprecation for anyone using attach_file?

I'd be in favor of using attach_contact. attach is very vauge, and having more specific names for these methods feels more descriptive than a general attach, and would allow us to add type-specific logic more easily. I think this is worth the tradeoff of drifting from the official NetSuite name for this method.

@@ -22,6 +22,8 @@ def fields(*args)
def field(name, klass = nil)
name_sym = name.to_sym
raise "#{name} already defined on #{self.name}" if fields.include?(name_sym)
raise "#{name} conflicts with a method defined on #{self.name}" if method_defined?(name_sym)
Copy link
Member

Choose a reason for hiding this comment

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

Nice addition

end

def record_type_without_namespace
"#{self.class.to_s.split('::').last}"
Copy link
Member

Choose a reason for hiding this comment

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

Yes!! I've been wanting to get something like this in the codebase for some time!

@iloveitaly
Copy link
Member

@cgunther one thing I'd love to see in the future are some readme additions to describe how to use this functionality.

@iloveitaly iloveitaly merged commit eb4ecd7 into NetSweet:master Dec 30, 2021
@cgunther cgunther deleted the attach-file-action branch January 5, 2022 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants