fix linter issues

This commit is contained in:
Mohamed ABDELLANI
2023-04-26 10:57:57 +01:00
committed by Konrad
parent d86173c509
commit 61d58df56f
37 changed files with 350 additions and 178 deletions

View File

@@ -1,27 +1,34 @@
class Invoice::DataPresenter::Address < Invoice::DataPresenter::Base
attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :company, :phone
attributes_with_presenter :state
invoice_generation_attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :company, :phone
# frozen_string_literal: false
def full_name
"#{firstname} #{lastname}".strip
end
class Invoice
class DataPresenter
class Address < Invoice::DataPresenter::Base
attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :company, :phone
attributes_with_presenter :state
invoice_generation_attributes :firstname, :lastname, :address1, :address2, :city, :zipcode,
:company, :phone
def address_part1
render_address([address1, address2])
end
def full_name
"#{firstname} #{lastname}".strip
end
def address_part2
render_address([city, zipcode, state&.name])
end
def address_part1
render_address([address1, address2])
end
def full_address
render_address([address1, address2, city, zipcode, state&.name])
end
def address_part2
render_address([city, zipcode, state&.name])
end
private
def full_address
render_address([address1, address2, city, zipcode, state&.name])
end
def render_address(address_parts)
address_parts.reject(&:blank?).join(', ')
private
def render_address(address_parts)
address_parts.compact_blank.join(', ')
end
end
end
end

View File

@@ -1,20 +1,27 @@
class Invoice::DataPresenter::Adjustment < Invoice::DataPresenter::Base
attributes :additional_tax_total, :adjustable_type, :amount, :currency, :included_tax_total,
:label
invoice_generation_attributes :additional_tax_total, :adjustable_type, :amount, :included_tax_total
invoice_update_attributes :label
def display_amount
Spree::Money.new(amount, currency: currency)
end
# frozen_string_literal: false
def display_taxes(display_zero: false)
if included_tax_total.positive?
amount = Spree::Money.new(included_tax_total, currency: currency)
I18n.t(:tax_amount_included, amount: amount)
elsif additional_tax_total.positive?
Spree::Money.new(additional_tax_total, currency: currency)
elsif display_zero
Spree::Money.new(0.00, currency: currency)
class Invoice
class DataPresenter
class Adjustment < Invoice::DataPresenter::Base
attributes :additional_tax_total, :adjustable_type, :amount, :currency, :included_tax_total,
:label
invoice_generation_attributes :additional_tax_total, :adjustable_type, :amount,
:included_tax_total
invoice_update_attributes :label
def display_amount
Spree::Money.new(amount, currency: currency)
end
def display_taxes(display_zero: false)
if included_tax_total.positive?
amount = Spree::Money.new(included_tax_total, currency: currency)
I18n.t(:tax_amount_included, amount: amount)
elsif additional_tax_total.positive?
Spree::Money.new(additional_tax_total, currency: currency)
elsif display_zero
Spree::Money.new(0.00, currency: currency)
end
end
end
end
end

View File

@@ -1,7 +1,14 @@
class Invoice::DataPresenter::Base
attr :data
def initialize(data)
@data = data
# frozen_string_literal: false
class Invoice
class DataPresenter
class Base
attr :data
def initialize(data)
@data = data
end
extend Invoice::DataPresenterAttributes
end
end
extend Invoice::DataPresenterAttributes
end

View File

@@ -1,2 +1,8 @@
class Invoice::DataPresenter::BillAddress < Invoice::DataPresenter::Address
end
# frozen_string_literal: false
class Invoice
class DataPresenter
class BillAddress < Invoice::DataPresenter::Address
end
end
end

View File

@@ -1,2 +1,8 @@
class Invoice::DataPresenter::BusinessAddress < Invoice::DataPresenter::Address
end
# frozen_string_literal: false
class Invoice
class DataPresenter
class BusinessAddress < Invoice::DataPresenter::Address
end
end
end

View File

@@ -1,3 +1,9 @@
class Invoice::DataPresenter::Contact < Invoice::DataPresenter::Base
attributes :name, :email
# frozen_string_literal: false
class Invoice
class DataPresenter
class Contact < Invoice::DataPresenter::Base
attributes :name, :email
end
end
end

View File

@@ -1,3 +1,9 @@
class Invoice::DataPresenter::Customer < Invoice::DataPresenter::Base
attributes :code, :email
# frozen_string_literal: false
class Invoice
class DataPresenter
class Customer < Invoice::DataPresenter::Base
attributes :code, :email
end
end
end

View File

@@ -1,8 +1,14 @@
class Invoice::DataPresenter::Distributor < Invoice::DataPresenter::Base
attributes :name, :abn, :acn, :logo_url, :display_invoice_logo, :invoice_text, :email_address
attributes_with_presenter :contact, :address, :business_address
# frozen_string_literal: false
def display_invoice_logo?
display_invoice_logo == true
class Invoice
class DataPresenter
class Distributor < Invoice::DataPresenter::Base
attributes :name, :abn, :acn, :logo_url, :display_invoice_logo, :invoice_text, :email_address
attributes_with_presenter :contact, :address, :business_address
def display_invoice_logo?
display_invoice_logo == true
end
end
end
end

View File

@@ -1,22 +1,29 @@
class Invoice::DataPresenter::LineItem < Invoice::DataPresenter::Base
attributes :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity, :variant_id
attributes_with_presenter :variant
invoice_generation_attributes :added_tax, :included_tax, :price_with_adjustments,
:quantity, :variant_id
# frozen_string_literal: false
delegate :name_to_display, :options_text, to: :variant
class Invoice
class DataPresenter
class LineItem < Invoice::DataPresenter::Base
attributes :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity,
:variant_id
attributes_with_presenter :variant
invoice_generation_attributes :added_tax, :included_tax, :price_with_adjustments,
:quantity, :variant_id
def display_amount_with_adjustments
Spree::Money.new(price_with_adjustments, currency: currency)
end
delegate :name_to_display, :options_text, to: :variant
def display_line_items_taxes(display_zero = true)
if included_tax.positive?
Spree::Money.new( included_tax, currency: currency)
elsif added_tax.positive?
Spree::Money.new( added_tax, currency: currency)
elsif display_zero
Spree::Money.new(0.00, currency: currency)
def display_amount_with_adjustments
Spree::Money.new(price_with_adjustments, currency: currency)
end
def display_line_items_taxes(display_zero: true)
if included_tax.positive?
Spree::Money.new( included_tax, currency: currency)
elsif added_tax.positive?
Spree::Money.new( added_tax, currency: currency)
elsif display_zero
Spree::Money.new(0.00, currency: currency)
end
end
end
end
end

View File

@@ -1,3 +1,9 @@
class Invoice::DataPresenter::OrderCycle < Invoice::DataPresenter::Base
attributes :name
# frozen_string_literal: false
class Invoice
class DataPresenter
class OrderCycle < Invoice::DataPresenter::Base
attributes :name
end
end
end

View File

@@ -1,19 +1,25 @@
class Invoice::DataPresenter::Payment < Invoice::DataPresenter::Base
attributes :amount, :currency, :state, :payment_method_id
attributes_with_presenter :payment_method
invoice_generation_attributes :amount, :payment_method_id
invoice_update_attributes :state
# frozen_string_literal: false
def created_at
datetime = data&.[](:created_at)
datetime.present? ? Time.zone.parse(datetime) : nil
end
class Invoice
class DataPresenter
class Payment < Invoice::DataPresenter::Base
attributes :amount, :currency, :state, :payment_method_id
attributes_with_presenter :payment_method
invoice_generation_attributes :amount, :payment_method_id
invoice_update_attributes :state
def display_amount
Spree::Money.new(amount, currency: currency)
end
def created_at
datetime = data&.[](:created_at)
datetime.present? ? Time.zone.parse(datetime) : nil
end
def payment_method_name
payment_method&.name
def display_amount
Spree::Money.new(amount, currency: currency)
end
def payment_method_name
payment_method&.name
end
end
end
end

View File

@@ -1,4 +1,10 @@
class Invoice::DataPresenter::PaymentMethod < Invoice::DataPresenter::Base
attributes :id,:name, :description
invoice_generation_attributes :id
# frozen_string_literal: false
class Invoice
class DataPresenter
class PaymentMethod < Invoice::DataPresenter::Base
attributes :id, :name, :description
invoice_generation_attributes :id
end
end
end

View File

@@ -1,4 +1,10 @@
class Invoice::DataPresenter::Product < Invoice::DataPresenter::Base
attributes :name
attributes_with_presenter :supplier
end
# frozen_string_literal: false
class Invoice
class DataPresenter
class Product < Invoice::DataPresenter::Base
attributes :name
attributes_with_presenter :supplier
end
end
end

View File

@@ -1,2 +1,8 @@
class Invoice::DataPresenter::ShipAddress < Invoice::DataPresenter::Address
end
# frozen_string_literal: false
class Invoice
class DataPresenter
class ShipAddress < Invoice::DataPresenter::Address
end
end
end

View File

@@ -1,4 +1,10 @@
class Invoice::DataPresenter::ShippingMethod < Invoice::DataPresenter::Base
attributes :id, :name, :require_ship_address
invoice_generation_attributes :id
# frozen_string_literal: false
class Invoice
class DataPresenter
class ShippingMethod < Invoice::DataPresenter::Base
attributes :id, :name, :require_ship_address
invoice_generation_attributes :id
end
end
end

View File

@@ -1,3 +1,9 @@
class Invoice::DataPresenter::State < Invoice::DataPresenter::Base
attributes :name
# frozen_string_literal: false
class Invoice
class DataPresenter
class State < Invoice::DataPresenter::Base
attributes :name
end
end
end

View File

@@ -1,3 +1,9 @@
class Invoice::DataPresenter::Supplier < Invoice::DataPresenter::Base
attributes :name
# frozen_string_literal: false
class Invoice
class DataPresenter
class Supplier < Invoice::DataPresenter::Base
attributes :name
end
end
end

View File

@@ -1,10 +1,16 @@
class Invoice::DataPresenter::Variant < Invoice::DataPresenter::Base
attributes :id, :display_name, :options_text
attributes_with_presenter :product
# frozen_string_literal: false
def name_to_display
return product.name if display_name.blank?
class Invoice
class DataPresenter
class Variant < Invoice::DataPresenter::Base
attributes :id, :display_name, :options_text
attributes_with_presenter :product
display_name
def name_to_display
return product.name if display_name.blank?
display_name
end
end
end
end
end

View File

@@ -6,7 +6,7 @@ class Invoice
def attributes(*attributes, prefix: nil)
attributes.each do |attribute|
define_method([prefix, attribute].reject(&:blank?).join("_")) do
define_method([prefix, attribute].compact_blank.join("_")) do
data&.[](attribute)
end
end

View File

@@ -597,9 +597,9 @@ module Spree
def current_state_invoice
Invoice.new(
order: self,
data: serialize_for_invoice,
date: Time.now.to_date,
order: self,
data: serialize_for_invoice,
date: Time.zone.today,
number: invoices.count + 1
)
end

View File

@@ -1,4 +1,8 @@
class Invoice::AddressSerializer < ActiveModel::Serializer
attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :company
has_one :state, serializer: Invoice::StateSerializer
# frozen_string_literal: false
class Invoice
class AddressSerializer < ActiveModel::Serializer
attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :company
has_one :state, serializer: Invoice::StateSerializer
end
end

View File

@@ -1,3 +1,8 @@
class Invoice::AdjustmentSerializer < ActiveModel::Serializer
attributes :adjustable_type, :label, :included_tax_total,:additional_tax_total, :amount, :currency
end
# frozen_string_literal: false
class Invoice
class AdjustmentSerializer < ActiveModel::Serializer
attributes :adjustable_type, :label, :included_tax_total, :additional_tax_total, :amount,
:currency
end
end

View File

@@ -1,3 +1,7 @@
class Invoice::CustomerSerializer < ActiveModel::Serializer
attributes :code, :email
# frozen_string_literal: false
class Invoice
class CustomerSerializer < ActiveModel::Serializer
attributes :code, :email
end
end

View File

@@ -1,9 +1,13 @@
class Invoice::EnterpriseSerializer < ActiveModel::Serializer
attributes :name, :abn, :acn, :invoice_text, :email_address, :display_invoice_logo, :logo_url
has_one :contact, serializer: Invoice::UserSerializer
has_one :business_address, serializer: Invoice::AddressSerializer
has_one :address, serializer: Invoice::AddressSerializer
def logo_url
object.logo_url(:small)
# frozen_string_literal: false
class Invoice
class EnterpriseSerializer < ActiveModel::Serializer
attributes :name, :abn, :acn, :invoice_text, :email_address, :display_invoice_logo, :logo_url
has_one :contact, serializer: Invoice::UserSerializer
has_one :business_address, serializer: Invoice::AddressSerializer
has_one :address, serializer: Invoice::AddressSerializer
def logo_url
object.logo_url(:small)
end
end
end

View File

@@ -1,4 +1,9 @@
class Invoice::LineItemSerializer < ActiveModel::Serializer
attributes :id, :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity, :variant_id
has_one :variant, serializer: Invoice::VariantSerializer
# frozen_string_literal: false
class Invoice
class LineItemSerializer < ActiveModel::Serializer
attributes :id, :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity,
:variant_id
has_one :variant, serializer: Invoice::VariantSerializer
end
end

View File

@@ -1,3 +1,7 @@
class Invoice::OrderCycleSerializer < ActiveModel::Serializer
attributes :name
# frozen_string_literal: false
class Invoice
class OrderCycleSerializer < ActiveModel::Serializer
attributes :name
end
end

View File

@@ -1,27 +1,30 @@
class Invoice::OrderSerializer < ActiveModel::Serializer
attributes :number, :special_instructions, :note, :payment_state, :total, :payment_total, :state,
:currency, :additional_tax_total, :included_tax_total, :completed_at, :has_taxes_included,
:shipping_method_id
has_one :order_cycle, serializer: Invoice::OrderCycleSerializer
has_one :customer, serializer: Invoice::CustomerSerializer
has_one :distributor, serializer: Invoice::EnterpriseSerializer
has_one :bill_address, serializer: Invoice::AddressSerializer
has_one :shipping_method, serializer: Invoice::ShippingMethodSerializer
has_one :ship_address, serializer: Invoice::AddressSerializer
has_many :sorted_line_items, serializer: Invoice::LineItemSerializer
has_many :sorted_line_items, serializer: Invoice::LineItemSerializer
has_many :payments, serializer: Invoice::PaymentSerializer
has_many :all_eligible_adjustments, serializer: Invoice::AdjustmentSerializer
# frozen_string_literal: false
def all_eligible_adjustments
object.all_adjustments.eligible.where.not(originator_type: 'Spree::TaxRate')
end
class Invoice
class OrderSerializer < ActiveModel::Serializer
attributes :number, :special_instructions, :note, :payment_state, :total, :payment_total,
:state, :currency, :additional_tax_total, :included_tax_total, :completed_at,
:has_taxes_included, :shipping_method_id
has_one :order_cycle, serializer: Invoice::OrderCycleSerializer
has_one :customer, serializer: Invoice::CustomerSerializer
has_one :distributor, serializer: Invoice::EnterpriseSerializer
has_one :bill_address, serializer: Invoice::AddressSerializer
has_one :shipping_method, serializer: Invoice::ShippingMethodSerializer
has_one :ship_address, serializer: Invoice::AddressSerializer
has_many :sorted_line_items, serializer: Invoice::LineItemSerializer
has_many :payments, serializer: Invoice::PaymentSerializer
has_many :all_eligible_adjustments, serializer: Invoice::AdjustmentSerializer
def completed_at
object.completed_at.to_s
end
def all_eligible_adjustments
object.all_adjustments.eligible.where.not(originator_type: 'Spree::TaxRate')
end
def shipping_method_id
object.shipping_method&.id
def completed_at
object.completed_at.to_s
end
def shipping_method_id
object.shipping_method&.id
end
end
end

View File

@@ -1,3 +1,7 @@
class Invoice::PaymentMethodSerializer < ActiveModel::Serializer
attributes :id, :name, :description
# frozen_string_literal: false
class Invoice
class PaymentMethodSerializer < ActiveModel::Serializer
attributes :id, :name, :description
end
end

View File

@@ -1,8 +1,12 @@
class Invoice::PaymentSerializer < ActiveModel::Serializer
attributes :state, :created_at, :amount, :currency, :payment_method_id
has_one :payment_method, serializer: Invoice::PaymentMethodSerializer
# frozen_string_literal: false
def created_at
object.created_at.to_s
class Invoice
class PaymentSerializer < ActiveModel::Serializer
attributes :state, :created_at, :amount, :currency, :payment_method_id
has_one :payment_method, serializer: Invoice::PaymentMethodSerializer
def created_at
object.created_at.to_s
end
end
end

View File

@@ -1,4 +1,8 @@
class Invoice::ProductSerializer < ActiveModel::Serializer
attributes :name
has_one :supplier, serializer: Invoice::EnterpriseSerializer
end
# frozen_string_literal: false
class Invoice
class ProductSerializer < ActiveModel::Serializer
attributes :name
has_one :supplier, serializer: Invoice::EnterpriseSerializer
end
end

View File

@@ -1,3 +1,7 @@
class Invoice::ShippingMethodSerializer < ActiveModel::Serializer
attributes :name, :require_ship_address
# frozen_string_literal: false
class Invoice
class ShippingMethodSerializer < ActiveModel::Serializer
attributes :name, :require_ship_address
end
end

View File

@@ -1,3 +1,7 @@
class Invoice::StateSerializer < ActiveModel::Serializer
attributes :name
# frozen_string_literal: false
class Invoice
class StateSerializer < ActiveModel::Serializer
attributes :name
end
end

View File

@@ -1,3 +1,7 @@
class Invoice::UserSerializer < ActiveModel::Serializer
attributes :email
# frozen_string_literal: false
class Invoice
class UserSerializer < ActiveModel::Serializer
attributes :email
end
end

View File

@@ -1,4 +1,8 @@
class Invoice::VariantSerializer < ActiveModel::Serializer
attributes :id, :display_name, :options_text
has_one :product, serializer: Invoice::ProductSerializer
# frozen_string_literal: false
class Invoice
class VariantSerializer < ActiveModel::Serializer
attributes :id, :display_name, :options_text
has_one :product, serializer: Invoice::ProductSerializer
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
class InvoiceDataGenerator
attr :order

View File

@@ -1,6 +1,5 @@
# frozen_string_literal: true
FactoryBot.define do
factory :invoice, class: Invoice do
end
end
factory :invoice, class: Invoice
end

View File

@@ -61,7 +61,9 @@ describe InvoiceDataGenerator do
old_variant_name = line_item.variant.display_name
line_item.variant.update!(display_name: "NEW NAME")
expect(new_invoice_presenter.sorted_line_items.first.variant.display_name).to eq(old_variant_name)
expect(
new_invoice_presenter.sorted_line_items.first.variant.display_name
).to eq(old_variant_name)
end
end