mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 16:38:18 +00:00
prefer endless defs where it makes sense
This commit is contained in:
parent
0d8d0ee71c
commit
5e659baace
44 changed files with 200 additions and 600 deletions
|
|
@ -37,9 +37,7 @@ module API
|
|||
@expand = params[:expand].to_s.split(",").map { |e| e.strip.to_sym }
|
||||
end
|
||||
|
||||
def set_pii
|
||||
@pii = current_token&.pii?
|
||||
end
|
||||
def set_pii = @pii = current_token&.pii?
|
||||
|
||||
def authenticate!
|
||||
@current_token = authenticate_with_http_token { |t, _options| APIKey.find_by(token: t) }
|
||||
|
|
|
|||
|
|
@ -27,9 +27,7 @@ module FrickinCountryNames
|
|||
country
|
||||
end
|
||||
|
||||
def find_state(country, string_to_ponder)
|
||||
country&.find_subdivision_by_any_name(string_to_ponder)
|
||||
end
|
||||
def find_state(country, string_to_ponder) = country&.find_subdivision_by_any_name(string_to_ponder)
|
||||
|
||||
def find_state!(country, string_to_ponder)
|
||||
state = find_state(country, string_to_ponder)
|
||||
|
|
@ -53,12 +51,8 @@ module ISO3166
|
|||
end.values.first
|
||||
end
|
||||
|
||||
def stupid_compare(arr, val)
|
||||
arr.map { |s| tldc(s) }.include?(val)
|
||||
end
|
||||
def stupid_compare(arr, val) = arr.map { |s| tldc(s) }.include?(val)
|
||||
|
||||
def tldc(s)
|
||||
ActiveSupport::Inflector.transliterate(s.strip).downcase
|
||||
end
|
||||
def tldc(s) = ActiveSupport::Inflector.transliterate(s.strip).downcase
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,5 @@
|
|||
#
|
||||
# that way we don't linebreak in the middle of a zipcode when we render out in Prawn!
|
||||
class SnailButNbsp < Snail
|
||||
def city_line
|
||||
super.tr(" -", " –")
|
||||
end
|
||||
def city_line = super.tr(" -", " –")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ module SnailMail
|
|||
FIM_HEIGHT = 45
|
||||
FIM_ELEMENT_WIDTH = 2.25
|
||||
|
||||
def render_fim_d(pdf, x = 245)
|
||||
render_fim(pdf, FIM_D, x)
|
||||
end
|
||||
def render_fim_d(pdf, x = 245) = render_fim(pdf, FIM_D, x)
|
||||
|
||||
def render_fim(pdf, fim, x)
|
||||
pdf.fill do
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module SnailMail
|
||||
module Helpers
|
||||
def image_path(image_name)
|
||||
File.join(Rails.root, "app", "lib", "snail_mail", "assets", "images", image_name)
|
||||
end
|
||||
def image_path(image_name) = File.join(Rails.root, "app", "lib", "snail_mail", "assets", "images", image_name)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -113,24 +113,16 @@ module SnailMail
|
|||
end
|
||||
|
||||
# List available templates
|
||||
def self.available_templates
|
||||
Components::Registry.available_templates.uniq
|
||||
end
|
||||
def self.available_templates = Components::Registry.available_templates.uniq
|
||||
|
||||
# Get a list of all templates with their metadata
|
||||
def self.template_info
|
||||
Components::Registry.template_info
|
||||
end
|
||||
def self.template_info = Components::Registry.template_info
|
||||
|
||||
# Get templates for a specific size
|
||||
def self.templates_for_size(size)
|
||||
Components::Registry.templates_for_size(size)
|
||||
end
|
||||
def self.templates_for_size(size) = Components::Registry.templates_for_size(size)
|
||||
|
||||
# Get the default template
|
||||
def self.default_template
|
||||
Components::Registry.default_template
|
||||
end
|
||||
def self.default_template = Components::Registry.default_template
|
||||
|
||||
# Check if templates exist
|
||||
def self.templates_exist?(template_names)
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ module SnailMail
|
|||
EOA
|
||||
end
|
||||
|
||||
def us?
|
||||
country == "US"
|
||||
end
|
||||
def us? = country == "US"
|
||||
|
||||
def snailify(origin = "US")
|
||||
SnailButNbsp.new(
|
||||
|
|
|
|||
|
|
@ -34,17 +34,13 @@ class Address < ApplicationRecord
|
|||
"\u200B", # ZERO WIDTH SPACE
|
||||
].join
|
||||
|
||||
def self.strip_gremlins(str)
|
||||
str&.delete(GREMLINS)&.presence
|
||||
end
|
||||
def self.strip_gremlins(str) = str&.delete(GREMLINS)&.presence
|
||||
|
||||
validates_presence_of :first_name, :line_1, :city, :state, :postal_code, :country
|
||||
|
||||
before_validation :strip_gremlins_from_fields
|
||||
|
||||
def name_line
|
||||
[first_name, last_name].join(" ")
|
||||
end
|
||||
def name_line = [first_name, last_name].join(" ")
|
||||
|
||||
def us_format
|
||||
<<~EOA
|
||||
|
|
@ -55,9 +51,7 @@ class Address < ApplicationRecord
|
|||
EOA
|
||||
end
|
||||
|
||||
def us?
|
||||
country == "US"
|
||||
end
|
||||
def us? = country == "US"
|
||||
|
||||
def snailify(origin = "US")
|
||||
SnailButNbsp.new(
|
||||
|
|
|
|||
|
|
@ -2,23 +2,9 @@ class Airtable::WarehouseSKU < Norairrecord::Table
|
|||
self.base_key = "appK53aN0fz3sgJ4w"
|
||||
self.table_name = "tblvSJMqoXnQyN7co"
|
||||
|
||||
def sku
|
||||
fields["SKU"]
|
||||
end
|
||||
|
||||
def name
|
||||
fields["Name (Must Match Poster Requests)"]
|
||||
end
|
||||
|
||||
def in_stock
|
||||
fields["In Stock"]
|
||||
end
|
||||
|
||||
def unit_cost
|
||||
fields["Unit Cost"]
|
||||
end
|
||||
|
||||
def item_type
|
||||
fields["Item Type"]
|
||||
end
|
||||
def sku = fields["SKU"]
|
||||
def name = fields["Name (Must Match Poster Requests)"]
|
||||
def in_stock = fields["In Stock"]
|
||||
def unit_cost = fields["Unit Cost"]
|
||||
def item_type = fields["Item Type"]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,25 +37,15 @@ class APIKey < ApplicationRecord
|
|||
has_encrypted :token
|
||||
blind_index :token
|
||||
|
||||
def pretty_name
|
||||
"#{user.username}@#{name}"
|
||||
end
|
||||
def pretty_name = "#{user.username}@#{name}"
|
||||
|
||||
def revoke!
|
||||
update!(revoked_at: Time.now)
|
||||
end
|
||||
def revoke! = update!(revoked_at: Time.now)
|
||||
|
||||
def revoked?
|
||||
revoked_at.present?
|
||||
end
|
||||
def revoked? = revoked_at.present?
|
||||
|
||||
def active?
|
||||
!revoked?
|
||||
end
|
||||
def active? = !revoked?
|
||||
|
||||
def abbreviated
|
||||
"#{token[..15]}.....#{token[-5..]}"
|
||||
end
|
||||
def abbreviated = "#{token[..15]}.....#{token[-5..]}"
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -92,13 +92,9 @@ class Batch < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def attach_pdf(pdf_data)
|
||||
PdfAttachmentUtil.attach_pdf(pdf_data, self, :pdf_document)
|
||||
end
|
||||
def attach_pdf(pdf_data) = PdfAttachmentUtil.attach_pdf(pdf_data, self, :pdf_document)
|
||||
|
||||
def total_cost
|
||||
raise NotImplementedError, "Subclasses must implement total_cost"
|
||||
end
|
||||
def total_cost = raise NotImplementedError, "Subclasses must implement total_cost"
|
||||
|
||||
GREMLINS = [
|
||||
"",
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ module PublicIdentifiable
|
|||
class_attribute :public_id_prefix
|
||||
end
|
||||
|
||||
def public_id
|
||||
"#{self.public_id_prefix}!#{hashid}"
|
||||
end
|
||||
def public_id = "#{self.public_id_prefix}!#{hashid}"
|
||||
|
||||
module ClassMethods
|
||||
def set_public_id_prefix(prefix)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,9 @@ module Taggable
|
|||
after_save :update_tag_cache, if: :saved_change_to_tags?
|
||||
end
|
||||
|
||||
def zap_empty_tags
|
||||
tags.reject!(&:blank?)
|
||||
end
|
||||
def zap_empty_tags = tags.reject!(&:blank?)
|
||||
|
||||
private
|
||||
|
||||
def update_tag_cache
|
||||
UpdateTagCacheJob.perform_later
|
||||
end
|
||||
def update_tag_cache = UpdateTagCacheJob.perform_later
|
||||
end
|
||||
|
|
@ -98,17 +98,11 @@ class Letter < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def display_name
|
||||
user_facing_title || tags.compact_blank.join(", ") || public_id
|
||||
end
|
||||
def display_name = user_facing_title || tags.compact_blank.join(", ") || public_id
|
||||
|
||||
def return_address_name_line
|
||||
return_address_name.presence || return_address&.name
|
||||
end
|
||||
def return_address_name_line = return_address_name.presence || return_address&.name
|
||||
|
||||
def been_mailed?
|
||||
mailed? || received?
|
||||
end
|
||||
def been_mailed? = mailed? || received?
|
||||
|
||||
belongs_to :usps_mailer_id, class_name: "USPS::MailerId"
|
||||
|
||||
|
|
@ -210,9 +204,7 @@ class Letter < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def to_param
|
||||
self.public_id
|
||||
end
|
||||
alias_method :to_param, :public_id
|
||||
|
||||
def events
|
||||
iv = iv_mtr_events.map do |event|
|
||||
|
|
|
|||
|
|
@ -73,9 +73,7 @@ class Letter::Batch < Batch
|
|||
|
||||
after_update :update_letter_tags, if: :saved_change_to_tags?
|
||||
|
||||
def self.model_name
|
||||
Batch.model_name
|
||||
end
|
||||
def self.model_name = Batch.model_name
|
||||
|
||||
# Directly attach a PDF to this batch
|
||||
def attach_pdf(pdf_data)
|
||||
|
|
@ -169,10 +167,6 @@ class Letter::Batch < Batch
|
|||
end
|
||||
end
|
||||
|
||||
def total_cost
|
||||
postage_cost
|
||||
end
|
||||
|
||||
def postage_cost
|
||||
# Preload associations to avoid N+1 queries
|
||||
letters.includes(:address, :usps_indicium).sum do |letter|
|
||||
|
|
@ -215,6 +209,8 @@ class Letter::Batch < Batch
|
|||
end
|
||||
end
|
||||
|
||||
alias_method :total_cost, :postage_cost
|
||||
|
||||
def postage_cost_difference(us_postage_type: nil, intl_postage_type: nil)
|
||||
# Preload associations to avoid N+1 queries
|
||||
letters.includes(:address, :usps_indicium).each_with_object({ us: 0, intl: 0 }) do |letter, differences|
|
||||
|
|
|
|||
|
|
@ -54,9 +54,7 @@ class Letter::InstantQueue < Letter::Queue
|
|||
default_scope { where(type: "Letter::InstantQueue") }
|
||||
|
||||
# Methods
|
||||
def indicia?
|
||||
postage_type == "indicia"
|
||||
end
|
||||
def indicia? = postage_type == "indicia"
|
||||
|
||||
def process_letter_instantly!(address, params = {})
|
||||
Rails.logger.info("Starting process_letter_instantly! with postage_type: #{postage_type}")
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
module LSV
|
||||
SLUGS = {
|
||||
msr: MarketingShipmentRequest,
|
||||
hs: HighSeasShipment,
|
||||
boba: BobaDropsShipment,
|
||||
oo: OneOffShipment,
|
||||
pf: PrintfulShipment
|
||||
}
|
||||
SLUGS = {
|
||||
msr: MarketingShipmentRequest,
|
||||
hs: HighSeasShipment,
|
||||
boba: BobaDropsShipment,
|
||||
oo: OneOffShipment,
|
||||
pf: PrintfulShipment,
|
||||
}
|
||||
|
||||
INVERSE = SLUGS.invert.freeze
|
||||
INVERSE = SLUGS.invert.freeze
|
||||
|
||||
def self.slug_for(lsv)
|
||||
s = INVERSE[lsv.class.responsible_class]
|
||||
end
|
||||
def self.slug_for(lsv) = INVERSE[lsv.class.responsible_class]
|
||||
|
||||
TYPES = SLUGS.values.freeze
|
||||
end
|
||||
TYPES = SLUGS.values.freeze
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
module LSV
|
||||
class Base < Norairrecord::Table
|
||||
def inspect
|
||||
"<#{self.class.name} #{id}> #{fields.inspect}"
|
||||
end
|
||||
def inspect = "<#{self.class.name} #{id}> #{fields.inspect}"
|
||||
|
||||
def to_partial_path
|
||||
"lsv/type/base"
|
||||
end
|
||||
def to_partial_path = "lsv/type/base"
|
||||
|
||||
class << self
|
||||
def responsible_class
|
||||
|
|
@ -25,9 +21,7 @@ module LSV
|
|||
super
|
||||
end
|
||||
|
||||
def email_column
|
||||
responsible_class.instance_variable_get(:@email_column)
|
||||
end
|
||||
def email_column = responsible_class.instance_variable_get(:@email_column)
|
||||
|
||||
attr_writer :email_column
|
||||
|
||||
|
|
@ -37,49 +31,26 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def tracking_number
|
||||
nil
|
||||
end
|
||||
def tracking_number = nil
|
||||
def tracking_link = nil
|
||||
|
||||
def tracking_link
|
||||
nil
|
||||
end
|
||||
|
||||
def status_text
|
||||
"error fetching status! poke nora"
|
||||
end
|
||||
def status_text = "error fetching status! poke nora"
|
||||
|
||||
def source_url
|
||||
fields.dig("source_rec_url", "url")
|
||||
end
|
||||
def source_url = fields.dig("source_rec_url", "url")
|
||||
def source_id = source_url&.split("/").last
|
||||
|
||||
def source_id
|
||||
source_url&.split("/").last
|
||||
end
|
||||
def icon = "📦"
|
||||
|
||||
def icon
|
||||
"📦"
|
||||
end
|
||||
def hide_contents? = false
|
||||
|
||||
def hide_contents?
|
||||
false
|
||||
end
|
||||
def status_icon = "?"
|
||||
|
||||
def status_icon
|
||||
"?"
|
||||
end
|
||||
def shipped? = nil
|
||||
|
||||
def shipped?
|
||||
nil
|
||||
end
|
||||
def description = nil
|
||||
|
||||
def description
|
||||
nil
|
||||
end
|
||||
|
||||
def email
|
||||
fields[self.class.email_column]
|
||||
end
|
||||
def email = fields[self.class.email_column]
|
||||
|
||||
def to_json(options = {})
|
||||
{
|
||||
|
|
@ -97,8 +68,6 @@ module LSV
|
|||
}.compact.to_json
|
||||
end
|
||||
|
||||
def to_param
|
||||
id
|
||||
end
|
||||
alias_method :to_param, :id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,17 +4,11 @@ module LSV
|
|||
self.table_name = Rails.application.credentials.dig(:lsv, :boba_table)
|
||||
self.email_column = "Email"
|
||||
|
||||
def title_text
|
||||
"Boba Drops!"
|
||||
end
|
||||
def title_text = "Boba Drops!"
|
||||
|
||||
def type_text
|
||||
"Boba Drops Shipment"
|
||||
end
|
||||
def type_text = "Boba Drops Shipment"
|
||||
|
||||
def date
|
||||
self["[Shipment Viewer] Approved/pending at"] || "error!"
|
||||
end
|
||||
def date = self["[Shipment Viewer] Approved/pending at"] || "error!"
|
||||
|
||||
def status_text
|
||||
case fields["Physical Status"]
|
||||
|
|
@ -42,24 +36,13 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def tracking_link
|
||||
fields["[INTL] Tracking Link"]
|
||||
end
|
||||
def tracking_link = fields["[INTL] Tracking Link"]
|
||||
def tracking_number = fields["[INTL] Tracking ID"]
|
||||
|
||||
def tracking_number
|
||||
fields["[INTL] Tracking ID"]
|
||||
end
|
||||
def icon = "🧋"
|
||||
|
||||
def icon
|
||||
"🧋"
|
||||
end
|
||||
def shipped? = fields["Physical Status"] == "Shipped"
|
||||
|
||||
def shipped?
|
||||
fields["Physical Status"] == "Shipped"
|
||||
end
|
||||
|
||||
def description
|
||||
"shipment from boba drops <3"
|
||||
end
|
||||
def description = "shipment from boba drops <3"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,17 +12,11 @@ module LSV
|
|||
["agh_random_stickers"] => "LSV::HsRawPendingAghShipment",
|
||||
}
|
||||
|
||||
def type_text
|
||||
"High Seas order"
|
||||
end
|
||||
def type_text = "High Seas order"
|
||||
|
||||
def title_text
|
||||
"High Seas – #{fields["shop_item:name"] || "unknown?!"}"
|
||||
end
|
||||
def title_text = "High Seas – #{fields["shop_item:name"] || "unknown?!"}"
|
||||
|
||||
def date
|
||||
self["created_at"]
|
||||
end
|
||||
def date = self["created_at"]
|
||||
|
||||
def status_text
|
||||
case fields["status"]
|
||||
|
|
@ -52,25 +46,17 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def tracking_number
|
||||
fields["tracking_number"]
|
||||
end
|
||||
def tracking_number = fields["tracking_number"]
|
||||
|
||||
def tracking_link
|
||||
tracking_number && "https://parcelsapp.com/en/tracking/#{tracking_number}"
|
||||
end
|
||||
def tracking_link = tracking_number && "https://parcelsapp.com/en/tracking/#{tracking_number}"
|
||||
|
||||
def icon
|
||||
return "🎁" if fields["shop_item:name"]&.start_with? "Free"
|
||||
super
|
||||
end
|
||||
|
||||
def shipped?
|
||||
fields["status"] == "fulfilled"
|
||||
end
|
||||
def shipped? = fields["status"] == "fulfilled"
|
||||
|
||||
def internal_info_partial
|
||||
:_highseas_internal_info
|
||||
end
|
||||
def internal_info_partial = :_highseas_internal_info
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
module LSV
|
||||
class HsHqMailShipment < HighSeasShipment
|
||||
def type_text
|
||||
"High Seas shipment (from HQ)"
|
||||
end
|
||||
def type_text = "High Seas shipment (from HQ)"
|
||||
|
||||
def status_text
|
||||
case fields["status"]
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def icon
|
||||
"<EFBFBD><EFBFBD>"
|
||||
end
|
||||
def icon = "<EFBFBD><EFBFBD>"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
module LSV
|
||||
class HsRawPendingAghShipment < HighSeasShipment
|
||||
def type_text
|
||||
"Pending warehouse shipment"
|
||||
end
|
||||
def type_text = "Pending warehouse shipment"
|
||||
|
||||
def status_text
|
||||
case fields["status"]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
module LSV
|
||||
class HsThirdPartyPhysicalShipment < HighSeasShipment
|
||||
def type_text
|
||||
"High Seas 3rd-party physical"
|
||||
end
|
||||
def type_text = "High Seas 3rd-party physical"
|
||||
|
||||
def status_text
|
||||
case fields["status"]
|
||||
|
|
|
|||
|
|
@ -1,24 +1,18 @@
|
|||
module LSV
|
||||
class MarketingShipmentRequest < Base
|
||||
def to_partial_path
|
||||
"lsv/type/msr"
|
||||
end
|
||||
def to_partial_path = "lsv/type/msr"
|
||||
|
||||
self.base_key = Rails.application.credentials.dig(:lsv, :sv_base)
|
||||
self.table_name = Rails.application.credentials.dig(:lsv, :msr_table)
|
||||
self.email_column = "Email"
|
||||
|
||||
def type_text
|
||||
"Warehouse"
|
||||
end
|
||||
def type_text = "Warehouse"
|
||||
|
||||
def title_text
|
||||
fields["user_facing_title"] || fields["Request Type"]&.join(", ") || "Who knows?"
|
||||
end
|
||||
|
||||
def date
|
||||
self["Date Requested"]
|
||||
end
|
||||
def date = self["Date Requested"]
|
||||
|
||||
def status_text
|
||||
case fields["state"]
|
||||
|
|
@ -54,9 +48,7 @@ module LSV
|
|||
fields["Warehouse–Tracking Number"] unless fields["Warehouse–Tracking Number"] == "Not Provided"
|
||||
end
|
||||
|
||||
def hide_contents?
|
||||
fields["surprise"]
|
||||
end
|
||||
def hide_contents? = fields["surprise"]
|
||||
|
||||
def country
|
||||
FrickinCountryNames.find_country(fields["Country"])&.alpha2 || "US"
|
||||
|
|
@ -69,9 +61,7 @@ module LSV
|
|||
"📦"
|
||||
end
|
||||
|
||||
def shipped?
|
||||
fields["state"] == "mailed"
|
||||
end
|
||||
def shipped? = fields["state"] == "mailed"
|
||||
|
||||
def description
|
||||
return "it's a surprise!" if hide_contents?
|
||||
|
|
|
|||
|
|
@ -10,13 +10,9 @@ module LSV
|
|||
fields["tracking_link"] || (tracking_number && "https://parcelsapp.com/en/tracking/#{tracking_number}") || nil
|
||||
end
|
||||
|
||||
def date
|
||||
fields["date"] || "2027-01-31"
|
||||
end
|
||||
def date = fields["date"] || "2027-01-31"
|
||||
|
||||
def icon
|
||||
fields["icon"] || super
|
||||
end
|
||||
def icon = fields["icon"] || super
|
||||
|
||||
SUPPORTED_FIELDS.each do |field|
|
||||
define_method field do
|
||||
|
|
|
|||
|
|
@ -4,29 +4,19 @@ module LSV
|
|||
self.table_name = Rails.application.credentials.dig(:lsv, :pf_table)
|
||||
self.email_column = "%order:recipient:email"
|
||||
|
||||
def to_partial_path
|
||||
"lsv/type/printful_shipment"
|
||||
end
|
||||
def to_partial_path = "lsv/type/printful_shipment"
|
||||
|
||||
has_subtypes "subtype", {
|
||||
"mystic_tavern" => "LSV::MysticTavernShipment",
|
||||
}
|
||||
|
||||
def date
|
||||
fields["created"] || Date.parse(fields["%order:created"]).iso8601
|
||||
end
|
||||
def date = fields["created"] || Date.parse(fields["%order:created"]).iso8601
|
||||
|
||||
def title_text
|
||||
"something custom!"
|
||||
end
|
||||
def title_text = "something custom!"
|
||||
|
||||
def type_text
|
||||
"Printful shipment"
|
||||
end
|
||||
def type_text = "Printful shipment"
|
||||
|
||||
def icon
|
||||
"🧢"
|
||||
end
|
||||
def icon = "🧢"
|
||||
|
||||
def status_text
|
||||
case fields["status"]
|
||||
|
|
@ -41,9 +31,7 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def shipped?
|
||||
fields["status"] == "shipped"
|
||||
end
|
||||
def shipped? = fields["status"] == "shipped"
|
||||
|
||||
def status_icon
|
||||
if shipped?
|
||||
|
|
@ -64,17 +52,11 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def tracking_number
|
||||
fields["tracking_number"]
|
||||
end
|
||||
def tracking_number = fields["tracking_number"]
|
||||
|
||||
def tracking_link
|
||||
fields["tracking_url"] if tracking_number
|
||||
end
|
||||
def tracking_link = (fields["tracking_url"] if tracking_number)
|
||||
|
||||
def internal_info_partial
|
||||
:_printful_internal_info
|
||||
end
|
||||
def internal_info_partial = :_printful_internal_info
|
||||
|
||||
private
|
||||
|
||||
|
|
@ -86,16 +68,10 @@ module LSV
|
|||
end
|
||||
|
||||
class MysticTavernShipment < PrintfulShipment
|
||||
def title_text
|
||||
"Mystic Tavern shirts!"
|
||||
end
|
||||
def title_text = "Mystic Tavern shirts!"
|
||||
|
||||
def type_text
|
||||
"arrrrrrrrrrrrr"
|
||||
end
|
||||
def type_text = "arrrrrrrrrrrrr"
|
||||
|
||||
def icon
|
||||
"<EFBFBD><EFBFBD>"
|
||||
end
|
||||
def icon = "<EFBFBD><EFBFBD>"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,17 +4,11 @@ module LSV
|
|||
self.table_name = Rails.application.credentials.dig(:lsv, :sprig_table)
|
||||
self.email_column = "Email"
|
||||
|
||||
def title_text
|
||||
"Sprig!"
|
||||
end
|
||||
def title_text = "Sprig!"
|
||||
|
||||
def type_text
|
||||
"Sprig shipment"
|
||||
end
|
||||
def type_text = "Sprig shipment"
|
||||
|
||||
def date
|
||||
fields["Created At"]
|
||||
end
|
||||
def date = fields["Created At"]
|
||||
|
||||
def status_text
|
||||
if shipped?
|
||||
|
|
@ -32,24 +26,13 @@ module LSV
|
|||
end
|
||||
end
|
||||
|
||||
def tracking_link
|
||||
fields["Tracking"] && "#{(fields["Tracking Base Link"] || "https://parcelsapp.com/en/tracking/")}#{fields["Tracking"]}"
|
||||
end
|
||||
def tracking_link = fields["Tracking"] && "#{(fields["Tracking Base Link"] || "https://parcelsapp.com/en/tracking/")}#{fields["Tracking"]}"
|
||||
def tracking_number = fields["Tracking"]
|
||||
|
||||
def tracking_number
|
||||
fields["Tracking"]
|
||||
end
|
||||
def icon = "🌱"
|
||||
|
||||
def icon
|
||||
"🌱"
|
||||
end
|
||||
def shipped? = fields["Sprig Status"] == "Shipped"
|
||||
|
||||
def shipped?
|
||||
fields["Sprig Status"] == "Shipped"
|
||||
end
|
||||
|
||||
def description
|
||||
"a #{fields["Color"]&.downcase.concat " "}Sprig!"
|
||||
end
|
||||
def description = "a #{fields["Color"]&.downcase.concat " "}Sprig!"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,21 +37,13 @@ class Public::APIKey < ApplicationRecord
|
|||
has_encrypted :token
|
||||
blind_index :token
|
||||
|
||||
def revoke!
|
||||
update!(revoked_at: Time.now)
|
||||
end
|
||||
def revoke! = update!(revoked_at: Time.now)
|
||||
|
||||
def revoked?
|
||||
revoked_at.present?
|
||||
end
|
||||
def revoked? = revoked_at.present?
|
||||
|
||||
def active?
|
||||
!revoked?
|
||||
end
|
||||
def active? = !revoked?
|
||||
|
||||
def abbreviated
|
||||
"#{token[..15]}.....#{token[-4..]}"
|
||||
end
|
||||
def abbreviated = "#{token[..15]}.....#{token[-4..]}"
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -31,13 +31,9 @@ class Public::LoginCode < ApplicationRecord
|
|||
|
||||
TOKEN = ExternalToken.new("lc")
|
||||
|
||||
def mark_used!
|
||||
update!(used_at: Time.current)
|
||||
end
|
||||
def mark_used! = update!(used_at: Time.current)
|
||||
|
||||
def to_param
|
||||
token
|
||||
end
|
||||
def to_param = token
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,5 @@ class Public::User < ApplicationRecord
|
|||
|
||||
set_public_id_prefix :uzr
|
||||
|
||||
def create_login_code
|
||||
login_codes.create!
|
||||
end
|
||||
def create_login_code = login_codes.create!
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,9 +41,7 @@ class ReturnAddress < ApplicationRecord
|
|||
# Add an attribute accessor for the from_letter parameter
|
||||
attr_accessor :from_letter
|
||||
|
||||
def display_name
|
||||
"#{name} / #{line_1}"
|
||||
end
|
||||
def display_name = "#{name} / #{line_1}"
|
||||
|
||||
def format_for_country(other_country)
|
||||
<<~EOA
|
||||
|
|
@ -55,13 +53,9 @@ class ReturnAddress < ApplicationRecord
|
|||
.strip
|
||||
end
|
||||
|
||||
def location
|
||||
"#{city}, #{state} #{postal_code} #{country}"
|
||||
end
|
||||
def location = "#{city}, #{state} #{postal_code} #{country}"
|
||||
|
||||
def us?
|
||||
country == "US"
|
||||
end
|
||||
def us? = country == "US"
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -39,17 +39,11 @@ class User < ApplicationRecord
|
|||
|
||||
set_public_id_prefix "usr"
|
||||
|
||||
def admin?
|
||||
is_admin
|
||||
end
|
||||
def admin? = is_admin
|
||||
|
||||
def make_admin!
|
||||
update!(is_admin: true)
|
||||
end
|
||||
def make_admin! = update!(is_admin: true)
|
||||
|
||||
def remove_admin!
|
||||
update!(is_admin: false)
|
||||
end
|
||||
def remove_admin! = update!(is_admin: false)
|
||||
|
||||
def self.authorize_url(redirect_uri)
|
||||
params = {
|
||||
|
|
|
|||
|
|
@ -83,17 +83,11 @@ class USPS::Indicium < ApplicationRecord
|
|||
save
|
||||
end
|
||||
|
||||
def cost
|
||||
(postage || 0) + (fees || 0)
|
||||
end
|
||||
def cost = (postage || 0) + (fees || 0)
|
||||
|
||||
def svg
|
||||
Base64.decode64(raw_json_response["indiciaImage"])
|
||||
end
|
||||
def svg = Base64.decode64(raw_json_response["indiciaImage"])
|
||||
|
||||
private
|
||||
|
||||
def usps_proc_cat(sym)
|
||||
sym.to_s.pluralize.upcase
|
||||
end
|
||||
def usps_proc_cat(sym) = sym.to_s.pluralize.upcase
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@
|
|||
#
|
||||
class USPS::IVMTR::Event < ApplicationRecord
|
||||
include PublicIdentifiable
|
||||
set_public_id_prefix 'mtr'
|
||||
set_public_id_prefix "mtr"
|
||||
|
||||
|
||||
belongs_to :letter, optional: true
|
||||
belongs_to :batch, class_name: "USPS::IVMTR::RawJSONBatch"
|
||||
belongs_to :mailer_id, class_name: "USPS::MailerId"
|
||||
|
|
@ -39,63 +38,36 @@ class USPS::IVMTR::Event < ApplicationRecord
|
|||
scope :bogons, -> { where(letter_id: nil) }
|
||||
scope :by_scan_datetime, -> { order(scan_datetime: :desc) }
|
||||
|
||||
def bogon?
|
||||
letter.nil?
|
||||
end
|
||||
def bogon? = letter.nil?
|
||||
|
||||
def hydrated
|
||||
@h ||= IvyMeter::Event::PieceEvent.from_json(payload || {})
|
||||
end
|
||||
|
||||
def scan_datetime
|
||||
hydrated.scan_datetime
|
||||
end
|
||||
def scan_datetime = hydrated.scan_datetime
|
||||
|
||||
def scan_facility
|
||||
{
|
||||
name: hydrated.scan_facility_name,
|
||||
city: hydrated.scan_facility_city,
|
||||
state: hydrated.scan_facility_state,
|
||||
zip: hydrated.scan_facility_zip
|
||||
zip: hydrated.scan_facility_zip,
|
||||
}
|
||||
end
|
||||
|
||||
def mail_phase
|
||||
hydrated.mail_phase
|
||||
end
|
||||
|
||||
def scan_event_code
|
||||
hydrated.scan_event_code
|
||||
end
|
||||
|
||||
def handling_event_type
|
||||
hydrated.handling_event_type
|
||||
end
|
||||
|
||||
def handling_event_type_description
|
||||
hydrated.handling_event_type_description
|
||||
end
|
||||
|
||||
def imb_serial_number
|
||||
hydrated.imb_serial_number
|
||||
end
|
||||
|
||||
def imb_mid
|
||||
hydrated.imb_mid
|
||||
end
|
||||
|
||||
def imb_stid
|
||||
hydrated.imb_stid
|
||||
end
|
||||
|
||||
def imb
|
||||
hydrated.imb
|
||||
end
|
||||
def mail_phase = hydrated.mail_phase
|
||||
def scan_event_code = hydrated.scan_event_code
|
||||
def handling_event_type = hydrated.handling_event_type
|
||||
def handling_event_type_description = hydrated.handling_event_type_description
|
||||
def imb_serial_number = hydrated.imb_serial_number
|
||||
def imb_mid = hydrated.imb_mid
|
||||
def imb_stid = hydrated.imb_stid
|
||||
def imb = hydrated.imb
|
||||
|
||||
def machine_info
|
||||
{
|
||||
name: hydrated.machine_name,
|
||||
id: hydrated.machine_id
|
||||
id: hydrated.machine_id,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -110,13 +82,11 @@ class USPS::IVMTR::Event < ApplicationRecord
|
|||
letter_id: letter&.id,
|
||||
happened_at: event.scan_datetime,
|
||||
opcode: event.scan_event_code,
|
||||
zip_code: event.scan_facility_zip
|
||||
zip_code: event.scan_facility_zip,
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notify_slack
|
||||
USPS::IVMTR::NotifySlackJob.perform_later(self)
|
||||
end
|
||||
def notify_slack = USPS::IVMTR::NotifySlackJob.perform_later(self)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,17 +12,11 @@
|
|||
# updated_at :datetime not null
|
||||
#
|
||||
class USPS::MailerId < ApplicationRecord
|
||||
def display_name
|
||||
"#{name} (#{crid}/#{mid})"
|
||||
end
|
||||
def display_name = "#{name} (#{crid}/#{mid})"
|
||||
|
||||
def sn_length
|
||||
15 - mid.length
|
||||
end
|
||||
def sn_length = 15 - mid.length
|
||||
|
||||
def max_sn
|
||||
(10**sn_length) - 1
|
||||
end
|
||||
def max_sn = (10 ** sn_length) - 1
|
||||
|
||||
def next_sn_and_rollover
|
||||
transaction do
|
||||
|
|
@ -36,6 +30,6 @@ class USPS::MailerId < ApplicationRecord
|
|||
end
|
||||
save!
|
||||
end
|
||||
[ sequence_number, rollover_count ]
|
||||
[sequence_number, rollover_count]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -47,9 +47,7 @@ class Warehouse::Batch < Batch
|
|||
|
||||
has_many :orders, class_name: "Warehouse::Order"
|
||||
|
||||
def self.model_name
|
||||
Batch.model_name
|
||||
end
|
||||
def self.model_name = Batch.model_name
|
||||
|
||||
def process!(options = {})
|
||||
return false unless fields_mapped?
|
||||
|
|
@ -82,25 +80,15 @@ class Warehouse::Batch < Batch
|
|||
address
|
||||
end
|
||||
|
||||
def contents_cost
|
||||
warehouse_template.contents_actual_cost_to_hc * addresses.count
|
||||
end
|
||||
def contents_cost = warehouse_template.contents_actual_cost_to_hc * addresses.count
|
||||
|
||||
def labor_cost
|
||||
warehouse_template.labor_cost * addresses.count
|
||||
end
|
||||
def labor_cost = warehouse_template.labor_cost * addresses.count
|
||||
|
||||
def postage_cost
|
||||
orders.sum(:postage_cost)
|
||||
end
|
||||
def postage_cost = orders.sum(:postage_cost)
|
||||
|
||||
def total_cost
|
||||
contents_cost + labor_cost + postage_cost
|
||||
end
|
||||
def total_cost = contents_cost + labor_cost + postage_cost
|
||||
|
||||
def update_associated_tags
|
||||
orders.update_all(tags: tags)
|
||||
end
|
||||
def update_associated_tags = orders.update_all(tags:)
|
||||
|
||||
def process_with_zenventory!(options = {})
|
||||
return false unless fields_mapped?
|
||||
|
|
|
|||
|
|
@ -239,13 +239,9 @@ class Warehouse::Order < ApplicationRecord
|
|||
@tracking_format ||= Tracking.get_format_by_zenv_info(carrier:, service:)
|
||||
end
|
||||
|
||||
def tracking_url
|
||||
Tracking.tracking_url_for(tracking_format, tracking_number)
|
||||
end
|
||||
def tracking_url = Tracking.tracking_url_for(tracking_format, tracking_number)
|
||||
|
||||
def might_be_slow?
|
||||
%i[asendia usps].include?(tracking_format)
|
||||
end
|
||||
def might_be_slow? = %i[asendia usps].include?(tracking_format)
|
||||
|
||||
def pretty_via
|
||||
case tracking_format
|
||||
|
|
@ -328,19 +324,13 @@ class Warehouse::Order < ApplicationRecord
|
|||
item_hash
|
||||
end
|
||||
|
||||
def total_cost
|
||||
[contents_cost, labor_cost, postage_cost].compact_blank.sum
|
||||
end
|
||||
def total_cost = [contents_cost, labor_cost, postage_cost].compact_blank.sum
|
||||
|
||||
def to_param
|
||||
hc_id
|
||||
end
|
||||
def to_param = hc_id
|
||||
|
||||
private
|
||||
|
||||
def set_hc_id
|
||||
update_column(:hc_id, public_id)
|
||||
end
|
||||
def set_hc_id = update_column(:hc_id, public_id)
|
||||
|
||||
def update_costs
|
||||
# Ensure line items are loaded and include their SKUs
|
||||
|
|
|
|||
|
|
@ -29,9 +29,7 @@ class Warehouse::SKU < ApplicationRecord
|
|||
scope :in_inventory, -> { where.not(in_stock: nil, inbound: nil) }
|
||||
scope :backordered, -> { where("in_stock < 0") }
|
||||
|
||||
def declared_unit_cost
|
||||
declared_unit_cost_override || average_po_cost || 0.0
|
||||
end
|
||||
def declared_unit_cost = declared_unit_cost_override || average_po_cost || 0.0
|
||||
|
||||
enum :category, {
|
||||
sticker: 0,
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@ class ApplicationPolicy
|
|||
user_is_admin
|
||||
end
|
||||
|
||||
def create?
|
||||
false
|
||||
end
|
||||
def create? = false
|
||||
|
||||
def new?
|
||||
create?
|
||||
|
|
|
|||
|
|
@ -8,63 +8,34 @@ class BatchPolicy < ApplicationPolicy
|
|||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
|
||||
def new?
|
||||
user_can_warehouse
|
||||
end
|
||||
def new? = user_can_warehouse
|
||||
|
||||
def create?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :create?, :new?
|
||||
|
||||
def edit?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
|
||||
def update?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :update?, :edit?
|
||||
|
||||
def destroy?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
|
||||
def map_fields?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :map_fields?, :edit?
|
||||
|
||||
def set_mapping?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :set_mapping?, :map_fields?
|
||||
|
||||
def process_batch?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :process_batch?, :map_fields?
|
||||
alias_method :process_form?, :process_batch?
|
||||
|
||||
def process_form?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :mark_printed?, :update?
|
||||
|
||||
def mark_printed?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :mark_mailed?, :mark_printed?
|
||||
|
||||
def mark_mailed?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
|
||||
def update_costs?
|
||||
return true if user_is_admin
|
||||
user_can_warehouse && record_belongs_to_user
|
||||
end
|
||||
alias_method :update_costs?, :show?
|
||||
|
||||
class Scope < ApplicationPolicy::Scope
|
||||
def resolve
|
||||
|
|
@ -86,7 +57,5 @@ class BatchPolicy < ApplicationPolicy
|
|||
|
||||
private
|
||||
|
||||
def record_belongs_to_user
|
||||
user && record.user == user
|
||||
end
|
||||
def record_belongs_to_user = user && record.user == user
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,59 +1,27 @@
|
|||
class Letter::BatchPolicy < ApplicationPolicy
|
||||
def index?
|
||||
user.present?
|
||||
end
|
||||
def index? = user.present?
|
||||
|
||||
def show?
|
||||
user.present?
|
||||
end
|
||||
def show? = user.present?
|
||||
|
||||
def new?
|
||||
user.present?
|
||||
end
|
||||
def new? = user.present?
|
||||
|
||||
def create?
|
||||
user.present?
|
||||
end
|
||||
def create? = user.present?
|
||||
|
||||
def edit?
|
||||
user.present?
|
||||
end
|
||||
def edit? = user.present?
|
||||
|
||||
def update?
|
||||
user.present?
|
||||
end
|
||||
alias_method :update?, :edit?
|
||||
|
||||
def destroy?
|
||||
user.admin?
|
||||
end
|
||||
def destroy? = user.admin?
|
||||
|
||||
def map_fields?
|
||||
user.present?
|
||||
end
|
||||
def map_fields? = user.present?
|
||||
|
||||
def set_mapping?
|
||||
user.present?
|
||||
end
|
||||
alias_method :set_mapping?, :map_fields?
|
||||
alias_method :process_form?, :map_fields?
|
||||
alias_method :process_batch?, :map_fields?
|
||||
alias_method :mark_printed?, :update?
|
||||
alias_method :mark_mailed?, :mark_printed?
|
||||
|
||||
def process_form?
|
||||
user.present?
|
||||
end
|
||||
|
||||
def process_batch?
|
||||
user.present?
|
||||
end
|
||||
|
||||
def mark_printed?
|
||||
user.present?
|
||||
end
|
||||
|
||||
def mark_mailed?
|
||||
user.present?
|
||||
end
|
||||
|
||||
def update_costs?
|
||||
user.present?
|
||||
end
|
||||
alias_method :update_costs?, :show?
|
||||
|
||||
class Scope < ApplicationPolicy::Scope
|
||||
def resolve
|
||||
|
|
|
|||
|
|
@ -1,59 +1,28 @@
|
|||
class Warehouse::BatchPolicy < ApplicationPolicy
|
||||
def index?
|
||||
user_can_warehouse
|
||||
end
|
||||
def index? = user_can_warehouse
|
||||
|
||||
def show?
|
||||
user_can_warehouse
|
||||
end
|
||||
def show? = user_can_warehouse
|
||||
|
||||
def new?
|
||||
user_can_warehouse
|
||||
end
|
||||
def new? = user_can_warehouse
|
||||
|
||||
def create?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :create?, :new?
|
||||
|
||||
def edit?
|
||||
user_can_warehouse
|
||||
end
|
||||
def edit? = user_can_warehouse
|
||||
|
||||
def update?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :update?, :edit?
|
||||
|
||||
def destroy?
|
||||
user_is_admin
|
||||
end
|
||||
def destroy? = user_is_admin
|
||||
|
||||
def map_fields?
|
||||
user_can_warehouse
|
||||
end
|
||||
def map_fields? = user_can_warehouse
|
||||
|
||||
def set_mapping?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :set_mapping?, :map_fields?
|
||||
alias_method :process_form?, :map_fields?
|
||||
alias_method :process_batch?, :map_fields?
|
||||
|
||||
def process_form?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :mark_printed?, :update?
|
||||
alias_method :mark_mailed?, :update?
|
||||
|
||||
def process_batch?
|
||||
user_can_warehouse
|
||||
end
|
||||
|
||||
def mark_printed?
|
||||
user_can_warehouse
|
||||
end
|
||||
|
||||
def mark_mailed?
|
||||
user_can_warehouse
|
||||
end
|
||||
|
||||
def update_costs?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :update_costs?, :show?
|
||||
|
||||
class Scope < ApplicationPolicy::Scope
|
||||
def resolve
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
class Warehouse::OrderPolicy < ApplicationPolicy
|
||||
def new?
|
||||
user_can_warehouse
|
||||
end
|
||||
def new? = user_can_warehouse
|
||||
|
||||
def create?
|
||||
user_can_warehouse
|
||||
end
|
||||
alias_method :create?, :new?
|
||||
|
||||
alias_method :from_template?, :create?
|
||||
|
||||
|
|
@ -14,10 +10,7 @@ class Warehouse::OrderPolicy < ApplicationPolicy
|
|||
record_belongs_to_user || user_is_admin
|
||||
end
|
||||
|
||||
def update?
|
||||
return false unless user_can_warehouse
|
||||
record_belongs_to_user || user_is_admin
|
||||
end
|
||||
alias_method :update?, :edit?
|
||||
|
||||
def show?
|
||||
user_can_warehouse
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue