diff --git a/lib/modules/create_invoice.ex b/lib/modules/create_invoice.ex index 9b97ede..e5d6d8e 100644 --- a/lib/modules/create_invoice.ex +++ b/lib/modules/create_invoice.ex @@ -1,12 +1,11 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice do alias ExSzamlazzHu.Modules.CreateInvoice.InvoiceData - alias ExSzamlazzHu.Modules.CreateInvoice.XMLBuilder def run(params) do params |> InvoiceData.parse() |> IO.inspect() - |> XMLBuilder.build() + |> InvoiceData.to_xml() |> IO.inspect() end end diff --git a/lib/modules/create_invoice/customer.ex b/lib/modules/create_invoice/customer.ex index d5519fc..51398d4 100644 --- a/lib/modules/create_invoice/customer.ex +++ b/lib/modules/create_invoice/customer.ex @@ -1,5 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Customer do alias ExSzamlazzHu.Modules.CreateInvoice.CustomerLedger + alias ExSzamlazzHu.Utils.StructToXML @type t :: %__MODULE__{} @@ -37,28 +38,41 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Customer do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - nev: params[:nev], - orszag: params[:orszag], - irsz: params[:irsz], - telepules: params[:telepules], - cim: params[:cim], - email: params[:email], - sendEmail: params[:sendEmail], - adoalany: params[:adoalany], - adoszam: params[:adoszam], - csoportazonosito: params[:csoportazonosito], - adoszamEU: params[:adoszamEU], - postazasiNev: params[:postazasiNev], - postazasiOrszag: params[:postazasiOrszag], - postazasiIrsz: params[:postazasiIrsz], - postazasiTelepules: params[:postazasiTelepules], - postazasiCim: params[:postazasiCim], - vevoFokonyv: CustomerLedger.parse(params[:vevoFokonyv]), - azonosito: params[:azonosito], - alairoNeve: params[:alairoNeve], - telefonszam: params[:telefonszam], - megjegyzes: params[:megjegyzes] - } + __MODULE__ + |> struct(Map.drop(params, [:vevoFokonyv])) + |> Map.put(:vevoFokonyv, CustomerLedger.parse(params[:vevoFokonyv])) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + nev: &"#{&1}", + orszag: &"#{&1}", + irsz: &"#{&1}", + telepules: &"#{&1}", + cim: &"#{&1}", + email: &"#{&1}", + sendEmail: &"#{&1}", + adoalany: &"#{&1}", + adoszam: &"#{&1}", + csoportazonosito: &"#{&1}", + adoszamEU: &"#{&1}", + postazasiNev: &"#{&1}", + postazasiOrszag: &"#{&1}", + postazasiIrsz: &"#{&1}", + postazasiTelepules: &"#{&1}", + postazasiCim: &"#{&1}", + vevoFokonyv: &CustomerLedger.to_xml(&1), + azonosito: &"#{&1}", + alairoNeve: &"#{&1}", + telefonszam: &"#{&1}", + megjegyzes: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/customer_ledger.ex b/lib/modules/create_invoice/customer_ledger.ex index 4095db2..94b0013 100644 --- a/lib/modules/create_invoice/customer_ledger.ex +++ b/lib/modules/create_invoice/customer_ledger.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.CustomerLedger do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -14,13 +16,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.CustomerLedger do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - konyvelesDatum: params[:konyvelesDatum], - vevoAzonosito: params[:vevoAzonosito], - vevoFokonyviSzam: params[:vevoFokonyviSzam], - folyamatosTelj: params[:folyamatosTelj], - elszDatumTol: params[:elszDatumTol], - elszDatumIg: params[:elszDatumIg] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + konyvelesDatum: &"#{&1}", + vevoAzonosito: &"#{&1}", + vevoFokonyviSzam: &"#{&1}", + folyamatosTelj: &"#{&1}", + elszDatumTol: &"#{&1}", + elszDatumIg: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/header.ex b/lib/modules/create_invoice/header.ex index 863875d..b082b17 100644 --- a/lib/modules/create_invoice/header.ex +++ b/lib/modules/create_invoice/header.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Header do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} @enforce_keys [ @@ -41,33 +43,44 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Header do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - keltDatum: params[:keltDatum], - teljesitesDatum: params[:teljesitesDatum], - fizetesiHataridoDatum: params[:fizetesiHataridoDatum], - fizmod: params[:fizmod], - penznem: params[:penznem], - szamlaNyelve: params[:szamlaNyelve], - megjegyzes: params[:megjegyzes], - arfolyamBank: params[:arfolyamBank], - arfolyam: params[:arfolyam], - rendelesSzam: params[:rendelesSzam], - dijbekeroSzamlaszam: params[:dijbekeroSzamlaszam], - elolegszamla: params[:elolegszamla], - vegszamla: params[:vegszamla], - elolegSzamlaszam: params[:elolegSzamlaszam], - helyesbitoszamla: params[:helyesbitoszamla], - helyesbitettSzamlaszam: params[:helyesbitettSzamlaszam], - dijbekero: params[:dijbekero], - szallitolevel: params[:szallitolevel], - logoExtra: params[:logoExtra], - szamlaszamElotag: params[:szamlaszamElotag], - fizetendoKorrekcio: params[:fizetendoKorrekcio], - fizetve: params[:fizetve], - arresAfa: params[:arresAfa], - eusAfa: params[:eusAfa], - szamlaSablon: params[:szamlaSablon], - elonezetpdf: params[:elonezetpdf] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + keltDatum: &"#{&1}", + teljesitesDatum: &"#{&1}", + fizetesiHataridoDatum: &"#{&1}", + fizmod: &"#{&1}", + penznem: &"#{&1}", + szamlaNyelve: &"#{&1}", + megjegyzes: &"#{&1}", + arfolyamBank: &"#{&1}", + arfolyam: &"#{&1}", + rendelesSzam: &"#{&1}", + dijbekeroSzamlaszam: &"#{&1}", + elolegszamla: &"#{&1}", + vegszamla: &"#{&1}", + elolegSzamlaszam: &"#{&1}", + helyesbitoszamla: &"#{&1}", + helyesbitettSzamlaszam: &"#{&1}", + dijbekero: &"#{&1}", + szallitolevel: &"#{&1}", + logoExtra: &"#{&1}", + szamlaszamElotag: &"#{&1}", + fizetendoKorrekcio: &"#{&1}", + fizetve: &"#{&1}", + arresAfa: &"#{&1}", + eusAfa: &"#{&1}", + szamlaSablon: &"#{&1}", + elonezetpdf: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/invoice_data.ex b/lib/modules/create_invoice/invoice_data.ex index f47ffbc..6c73a99 100644 --- a/lib/modules/create_invoice/invoice_data.ex +++ b/lib/modules/create_invoice/invoice_data.ex @@ -4,7 +4,8 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.InvoiceData do alias ExSzamlazzHu.Modules.CreateInvoice.Seller alias ExSzamlazzHu.Modules.CreateInvoice.Customer alias ExSzamlazzHu.Modules.CreateInvoice.Waybill - alias ExSzamlazzHu.Modules.CreateInvoice.Item + alias ExSzamlazzHu.Modules.CreateInvoice.Items + alias ExSzamlazzHu.Utils.StructToXML @type t :: %__MODULE__{} @@ -25,7 +26,30 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.InvoiceData do elado: Seller.parse(params[:elado]), vevo: Customer.parse(params[:vevo]), fuvarlevel: Waybill.parse(params[:fuvarlevel]), - tetelek: Enum.map(params[:tetelek] || [], &Item.parse(&1)) + tetelek: Items.parse(params[:tetelek]) } end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + beallitasok: &Settings.to_xml(&1), + fejlec: &Header.to_xml(&1), + elado: &Seller.to_xml(&1), + vevo: &Customer.to_xml(&1), + fuvarlevel: &Waybill.to_xml(&1), + tetelek: &Items.to_xml(&1) + ] + + """ + + + #{StructToXML.run(module, tags)} + + """ + end end diff --git a/lib/modules/create_invoice/item.ex b/lib/modules/create_invoice/item.ex index 73500f8..48e9a8b 100644 --- a/lib/modules/create_invoice/item.ex +++ b/lib/modules/create_invoice/item.ex @@ -1,5 +1,6 @@ -defmodule ExSzamlazzHu.Modules.CreateInvoice.Item do - alias ExSzamlazzHu.Modules.CreateInvoice.ItemLedger +defmodule ExSzamlazzHu.Modules.CreateInvoice.Items.Item do + alias ExSzamlazzHu.Modules.CreateInvoice.Items.Item.ItemLedger + alias ExSzamlazzHu.Utils.StructToXML @type t() :: %__MODULE__{} @@ -32,19 +33,32 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Item do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - megnevezes: params[:megnevezes], - azonosito: params[:azonosito], - mennyiseg: params[:mennyiseg], - mennyisegiEgyseg: params[:mennyisegiEgyseg], - nettoEgysegar: params[:nettoEgysegar], - afakulcs: params[:afakulcs], - arresAfaAlap: params[:arresAfaAlap], - nettoErtek: params[:nettoErtek], - afaErtek: params[:afaErtek], - bruttoErtek: params[:bruttoErtek], - megjegyzes: params[:megjegyzes], - tetelFokonyv: ItemLedger.parse(params[:tetelFokonyv]) - } + __MODULE__ + |> struct(Map.drop(params, [:tetelFokonyv])) + |> Map.put(:tetelFokonyv, ItemLedger.parse(params[:tetelFokonyv])) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + megnevezes: &"#{&1}", + azonosito: &"#{&1}", + mennyiseg: &"#{&1}", + mennyisegiEgyseg: &"#{&1}", + nettoEgysegar: &"#{&1}", + afakulcs: &"#{&1}", + arresAfaAlap: &"#{&1}", + nettoErtek: &"#{&1}", + afaErtek: &"#{&1}", + bruttoErtek: &"#{&1}", + megjegyzes: &"#{&1}", + tetelFokonyv: &ItemLedger.to_xml(&1) + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/item_ledger.ex b/lib/modules/create_invoice/item_ledger.ex index c007474..bae0dac 100644 --- a/lib/modules/create_invoice/item_ledger.ex +++ b/lib/modules/create_invoice/item_ledger.ex @@ -1,4 +1,6 @@ -defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemLedger do +defmodule ExSzamlazzHu.Modules.CreateInvoice.Items.Item.ItemLedger do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -14,13 +16,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemLedger do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - gazdasagiEsem: params[:gazdasagiEsem], - gazdasagiEsemAfa: params[:gazdasagiEsemAfa], - arbevetelFokonyviSzam: params[:arbevetelFokonyviSzam], - afaFokonyviSzam: params[:afaFokonyviSzam], - elszDatumTol: params[:elszDatumTol], - elszDatumIg: params[:elszDatumIg] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + gazdasagiEsem: &"#{&1}", + gazdasagiEsemAfa: &"#{&1}", + arbevetelFokonyviSzam: &"#{&1}", + afaFokonyviSzam: &"#{&1}", + elszDatumTol: &"#{&1}", + elszDatumIg: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/items.ex b/lib/modules/create_invoice/items.ex new file mode 100644 index 0000000..c9872a8 --- /dev/null +++ b/lib/modules/create_invoice/items.ex @@ -0,0 +1,24 @@ +defmodule ExSzamlazzHu.Modules.CreateInvoice.Items do + alias ExSzamlazzHu.Modules.CreateInvoice.Items.Item + + def parse(nil), do: [] + + def parse(params) do + Enum.map(params, &Item.parse/1) + end + + def to_xml(items) do + rendered_items = + items + |> Enum.map(&Item.to_xml/1) + |> Enum.join("\n") + |> String.replace("\n\n", "\n") + |> String.trim() + + """ + + #{rendered_items} + + """ + end +end diff --git a/lib/modules/create_invoice/mpl.ex b/lib/modules/create_invoice/mpl.ex index 7878318..a609e11 100644 --- a/lib/modules/create_invoice/mpl.ex +++ b/lib/modules/create_invoice/mpl.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.MPL do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -13,12 +15,23 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.MPL do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - vevokod: params[:vevokod], - vonalkod: params[:vonalkod], - tomeg: params[:tomeg], - kulonszolgaltatasok: params[:kulonszolgaltatasok], - erteknyilvanitas: params[:erteknyilvanitas] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + vevokod: &"#{&1}", + vonalkod: &"#{&1}", + tomeg: &"#{&1}", + kulonszolgaltatasok: &"#{&1}", + erteknyilvanitas: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/ppp.ex b/lib/modules/create_invoice/ppp.ex index c9b15d1..029ccf1 100644 --- a/lib/modules/create_invoice/ppp.ex +++ b/lib/modules/create_invoice/ppp.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.PPP do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -10,9 +12,20 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.PPP do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - vonalkodPrefix: params[:vonalkodPrefix], - vonalkodPostfix: params[:vonalkodPostfix] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + vonalkodPrefix: &"#{&1}", + vonalkodPostfix: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/seller.ex b/lib/modules/create_invoice/seller.ex index 542d101..3c18934 100644 --- a/lib/modules/create_invoice/seller.ex +++ b/lib/modules/create_invoice/seller.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Seller do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -14,13 +16,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Seller do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - bank: params[:bank], - bankszamlaszam: params[:bankszamlaszam], - emailReplyto: params[:emailReplyto], - emailTargy: params[:emailTargy], - emailSzoveg: params[:emailSzoveg], - alairoNeve: params[:alairoNeve] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + bank: &"#{&1}", + bankszamlaszam: &"#{&1}", + emailReplyto: &"#{&1}", + emailTargy: &"#{&1}", + emailSzoveg: &"#{&1}", + alairoNeve: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/settings.ex b/lib/modules/create_invoice/settings.ex index 73582a0..297ad9e 100644 --- a/lib/modules/create_invoice/settings.ex +++ b/lib/modules/create_invoice/settings.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Settings do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} @enforce_keys [:eszamla, :szamlaLetoltes] @@ -18,18 +20,29 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Settings do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - felhasznalo: params[:felhasznalo], - jelszo: params[:jelszo], - szamlaagentkulcs: params[:szamlaagentkulcs], - eszamla: params[:eszamla], - szamlaLetoltes: params[:szamlaLetoltes], - szamlaLetoltesPld: params[:szamlaLetoltesPld], - valaszVerzio: params[:valaszVerzio], - aggregator: params[:aggregator], - guardian: params[:guardian], - cikkazoninvoice: params[:cikkazoninvoice], - szamlaKulsoAzon: params[:szamlaKulsoAzon] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + felhasznalo: &"#{&1}", + jelszo: &"#{&1}", + szamlaagentkulcs: &"#{&1}", + eszamla: &"#{&1}", + szamlaLetoltes: &"#{&1}", + szamlaLetoltesPld: &"#{&1}", + valaszVerzio: &"#{&1}", + aggregator: &"#{&1}", + guardian: &"#{&1}", + cikkazoninvoice: &"#{&1}", + szamlaKulsoAzon: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/sprinter.ex b/lib/modules/create_invoice/sprinter.ex index 5b7b008..8721b7e 100644 --- a/lib/modules/create_invoice/sprinter.ex +++ b/lib/modules/create_invoice/sprinter.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.Sprinter do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -14,13 +16,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.Sprinter do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - azonosito: params[:azonosito], - feladokod: params[:feladokod], - iranykod: params[:iranykod], - csomagszam: params[:csomagszam], - vonalkodPostfix: params[:vonalkodPostfix], - szallitasiIdo: params[:szallitasiIdo] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + azonosito: &"#{&1}", + feladokod: &"#{&1}", + iranykod: &"#{&1}", + csomagszam: &"#{&1}", + vonalkodPostfix: &"#{&1}", + szallitasiIdo: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/transoflex.ex b/lib/modules/create_invoice/transoflex.ex index dcdcccd..f826328 100644 --- a/lib/modules/create_invoice/transoflex.ex +++ b/lib/modules/create_invoice/transoflex.ex @@ -1,4 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.Transoflex do + alias ExSzamlazzHu.Utils.StructToXML + @type t :: %__MODULE__{} defstruct [ @@ -14,13 +16,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.Transoflex do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - azonosito: params[:azonosito], - shipmentID: params[:shipmentID], - csomagszam: params[:csomagszam], - countryCode: params[:countryCode], - zip: params[:zip], - service: params[:service] - } + struct(__MODULE__, params) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + azonosito: &"#{&1}", + shipmentID: &"#{&1}", + csomagszam: &"#{&1}", + countryCode: &"#{&1}", + zip: &"#{&1}", + service: &"#{&1}" + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/waybill.ex b/lib/modules/create_invoice/waybill.ex index bf03e9c..f944dae 100644 --- a/lib/modules/create_invoice/waybill.ex +++ b/lib/modules/create_invoice/waybill.ex @@ -3,6 +3,7 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill do alias ExSzamlazzHu.Modules.CreateInvoice.Waybill.Sprinter alias ExSzamlazzHu.Modules.CreateInvoice.Waybill.PPP alias ExSzamlazzHu.Modules.CreateInvoice.Waybill.MPL + alias ExSzamlazzHu.Utils.StructToXML @type t :: %__MODULE__{} @@ -21,15 +22,31 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill do def parse(nil), do: nil def parse(params) do - %__MODULE__{ - uticel: params[:uticel], - futarSzolgalat: params[:futarSzolgalat], - vonalkod: params[:vonalkod], - megjegyzes: params[:megjegyzes], - tof: Transoflex.parse(params[:tof]), - ppp: PPP.parse(params[:ppp]), - sprinter: Sprinter.parse(params[:sprinter]), - mpl: MPL.parse(params[:mpl]) - } + __MODULE__ + |> struct(Map.drop(params, [:tof, :ppp, :sprinter, :mpl])) + |> Map.put(:tof, Transoflex.parse(params[:tof])) + |> Map.put(:ppp, PPP.parse(params[:ppp])) + |> Map.put(:sprinter, Sprinter.parse(params[:sprinter])) + |> Map.put(:mpl, MPL.parse(params[:mpl])) + end + + @spec to_xml(t()) :: String.t() + def to_xml(%__MODULE__{} = module) do + tags = [ + uticel: &"#{&1}", + futarSzolgalat: &"#{&1}", + vonalkod: &"#{&1}", + megjegyzes: &"#{&1}", + tof: &Transoflex.to_xml(&1), + ppp: &PPP.to_xml(&1), + sprinter: &Sprinter.to_xml(&1), + mpl: &MPL.to_xml(&1) + ] + + """ + + #{StructToXML.run(module, tags)} + + """ end end diff --git a/lib/modules/create_invoice/xml_builder.ex b/lib/modules/create_invoice/xml_builder.ex deleted file mode 100644 index 9fdde0b..0000000 --- a/lib/modules/create_invoice/xml_builder.ex +++ /dev/null @@ -1,104 +0,0 @@ -defmodule ExSzamlazzHu.Modules.CreateInvoice.XMLBuilder do - alias ExSzamlazzHu.Modules.CreateInvoice.InvoiceData - alias ExSzamlazzHu.Modules.CreateInvoice.Customer - alias ExSzamlazzHu.Modules.CreateInvoice.Item - - @spec build(InvoiceData.t()) :: {:ok, String.t()} - def build(invoice_data) do - {:ok, build_xml(invoice_data)} - end - - defp build_xml(%InvoiceData{} = invoice_data) do - """ - - - - #{invoice_data.settings.agent_key} - #{invoice_data.settings.is_e_invoice} - #{invoice_data.settings.download_invoice} - #{invoice_data.settings.response_version} - - #{build_header(invoice_data)} - - #{build_customer(invoice_data.customer)} - #{build_items(invoice_data.items)} - - """ - end - - defp build_header(%InvoiceData{} = invoice_data) do - """ - - 2020-01-20 - #{invoice_data.completion_date} - #{invoice_data.payment_deadline} - #{invoice_data.method_of_payment} - #{invoice_data.currency} - #{invoice_data.language} - #{invoice_data.comment} - MNB - 0.0 - #{invoice_data.order_id} - - false - false - - false - - #{invoice_data.is_proforma} - - - - - #{invoice_data.is_paid} - - - - - - """ - end - - defp build_customer(%Customer{} = customer) do - """ - - #{customer.name} - #{customer.country} - #{customer.zip} - #{customer.city} - #{customer.address} - #{customer.email} - true - - """ - end - - defp build_items(items) do - items = Enum.map(items, &build_item(&1)) - - """ - - #{items} - - """ - end - - def build_item(%Item{} = item) do - """ - - #{item.name} - #{item.quantity} - #{item.unit} - #{item.net_unit_price} - #{item.vat_key} - #{item.net_cost} - #{item.vat_cost} - #{item.gross_cost} - - """ - end -end diff --git a/lib/utils/struct_to_xml.ex b/lib/utils/struct_to_xml.ex new file mode 100644 index 0000000..9c5c388 --- /dev/null +++ b/lib/utils/struct_to_xml.ex @@ -0,0 +1,15 @@ +defmodule ExSzamlazzHu.Utils.StructToXML do + def run(struct, params) do + params + |> Enum.map(fn {tag, fun} -> + case Map.get(struct, tag) do + nil -> nil + value -> fun.(value) + end + end) + |> Enum.reject(&is_nil/1) + |> Enum.join("\n") + |> String.replace("\n\n", "\n") + |> String.trim() + end +end diff --git a/test/lib/modules/create_invoice/customer_ledger_test.exs b/test/lib/modules/create_invoice/customer_ledger_test.exs index 800b2cc..62a2bbc 100644 --- a/test/lib/modules/create_invoice/customer_ledger_test.exs +++ b/test/lib/modules/create_invoice/customer_ledger_test.exs @@ -20,6 +20,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.CustomerLedgerTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> CustomerLedger.parse() + |> CustomerLedger.to_xml() == + """ + + accounting_date + customer_identifier + ledger_number + continuous_delivery + settlement_date_from + settlement_date_to + + """ + end + end + def params() do CustomerLedgerFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/customer_test.exs b/test/lib/modules/create_invoice/customer_test.exs index 0d7d365..38df4e8 100644 --- a/test/lib/modules/create_invoice/customer_test.exs +++ b/test/lib/modules/create_invoice/customer_test.exs @@ -2,6 +2,7 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.CustomerTest do use ExUnit.Case, async: true alias ExSzamlazzHu.Modules.CreateInvoice.Customer alias ExSzamlazzHu.Factories.CustomerFactory + alias ExSzamlazzHu.Factories.CustomerLedgerFactory describe "parse/1" do test "should parse a valid Customer" do @@ -35,7 +36,48 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.CustomerTest do end end - def params() do - CustomerFactory.get_params(%{nope: "nope"}) + describe "to_xml/1" do + test "should return a valid XML" do + assert %{vevoFokonyv: CustomerLedgerFactory.get_params()} + |> params() + |> Customer.parse() + |> Customer.to_xml() == + """ + + name + country + zip_code + city + address + email + false + 123 + tax_identifier + group_identifier + eu_tax_identifier + mailing_name + mailing_country + mailing_zip + mailing_city + mailing_address + + accounting_date + customer_identifier + ledger_number + continuous_delivery + settlement_date_from + settlement_date_to + + identifier + name_of_signatory + phone_number + comment + + """ + end + end + + def params(params \\ %{nope: "nope"}) do + CustomerFactory.get_params(params) end end diff --git a/test/lib/modules/create_invoice/header_test.exs b/test/lib/modules/create_invoice/header_test.exs index 79da850..30af5a9 100644 --- a/test/lib/modules/create_invoice/header_test.exs +++ b/test/lib/modules/create_invoice/header_test.exs @@ -40,7 +40,49 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.HeaderTest do end end - def params() do - HeaderFactory.get_params(%{nope: "nope"}) + describe "to_xml/1" do + test "should return a valid XML" do + assert %{ + elolegSzamlaszam: "proforma_invoice_identifier", + helyesbitettSzamlaszam: "corrected_invoice_identifier" + } + |> params() + |> Header.parse() + |> Header.to_xml() == + """ + + 1997-08-29 + 1997-08-29 + 1997-08-29 + payment_method + HUF + en + comment + exchange_rate_bank + 123.4 + order_identifier + fee_request_identifier + false + true + proforma_invoice_identifier + false + corrected_invoice_identifier + false + false + logo_extra + PRFX + 123.4 + true + false + false + invoice_draft + false + + """ + end + end + + def params(params \\ %{nope: "nope"}) do + HeaderFactory.get_params(params) end end diff --git a/test/lib/modules/create_invoice/invoice_data_test.exs b/test/lib/modules/create_invoice/invoice_data_test.exs new file mode 100644 index 0000000..b27a9f0 --- /dev/null +++ b/test/lib/modules/create_invoice/invoice_data_test.exs @@ -0,0 +1,283 @@ +defmodule ExSzamlazzHu.Modules.CreateInvoice.InvoiceDataTest do + use ExUnit.Case, async: true + alias ExSzamlazzHu.Modules.CreateInvoice.InvoiceData + alias ExSzamlazzHu.Modules.CreateInvoice.Settings + alias ExSzamlazzHu.Modules.CreateInvoice.Header + alias ExSzamlazzHu.Modules.CreateInvoice.Customer + alias ExSzamlazzHu.Modules.CreateInvoice.Seller + alias ExSzamlazzHu.Modules.CreateInvoice.Waybill + alias ExSzamlazzHu.Modules.CreateInvoice.Waybill.MPL + alias ExSzamlazzHu.Modules.CreateInvoice.Items.Item + alias ExSzamlazzHu.Factories.InvoiceDataFactory + alias ExSzamlazzHu.Factories.HeaderFactory + alias ExSzamlazzHu.Factories.WaybillFactory + alias ExSzamlazzHu.Factories.CustomerFactory + alias ExSzamlazzHu.Factories.CustomerLedgerFactory + alias ExSzamlazzHu.Factories.ItemFactory + alias ExSzamlazzHu.Factories.ItemLedgerFactory + + describe "parse/1" do + test "should parse a valid InvoiceData" do + assert %{fuvarlevel: WaybillFactory.get_params(%{mpl: %{}})} + |> params() + |> InvoiceData.parse() == + %InvoiceData{ + beallitasok: %Settings{ + felhasznalo: "user", + jelszo: "password", + szamlaagentkulcs: "agent_key", + eszamla: true, + szamlaLetoltes: false, + szamlaLetoltesPld: 0, + valaszVerzio: 1, + aggregator: "aggregator", + guardian: false, + cikkazoninvoice: false, + szamlaKulsoAzon: "external_invoice_identifier" + }, + fejlec: %Header{ + keltDatum: "1997-08-29", + teljesitesDatum: "1997-08-29", + fizetesiHataridoDatum: "1997-08-29", + fizmod: "payment_method", + penznem: "HUF", + szamlaNyelve: "en", + megjegyzes: "comment", + arfolyamBank: "exchange_rate_bank", + arfolyam: "123.4", + rendelesSzam: "order_identifier", + dijbekeroSzamlaszam: "fee_request_identifier", + elolegszamla: false, + vegszamla: true, + elolegSzamlaszam: nil, + helyesbitoszamla: false, + helyesbitettSzamlaszam: nil, + dijbekero: false, + szallitolevel: false, + logoExtra: "logo_extra", + szamlaszamElotag: "PRFX", + fizetendoKorrekcio: "123.4", + fizetve: true, + arresAfa: false, + eusAfa: false, + szamlaSablon: "invoice_draft", + elonezetpdf: false + }, + vevo: %Customer{ + nev: "name", + orszag: "country", + irsz: "zip_code", + telepules: "city", + cim: "address", + email: "email", + sendEmail: false, + adoalany: 123, + adoszam: "tax_identifier", + csoportazonosito: "group_identifier", + adoszamEU: "eu_tax_identifier", + postazasiNev: "mailing_name", + postazasiOrszag: "mailing_country", + postazasiIrsz: "mailing_zip", + postazasiTelepules: "mailing_city", + postazasiCim: "mailing_address", + vevoFokonyv: nil, + azonosito: "identifier", + alairoNeve: "name_of_signatory", + telefonszam: "phone_number", + megjegyzes: "comment" + }, + elado: %Seller{ + bank: "bank", + bankszamlaszam: "bank_account_number", + emailReplyto: "email_reply_to", + emailTargy: "email_subject", + emailSzoveg: "email_text", + alairoNeve: "name_of_signatory" + }, + fuvarlevel: %Waybill{ + uticel: "destination", + futarSzolgalat: "three_pl_provider", + vonalkod: "barcode", + megjegyzes: "comment", + tof: nil, + ppp: nil, + sprinter: nil, + mpl: %MPL{ + vevokod: "buyer_identifier", + vonalkod: "barcode", + tomeg: "weight", + kulonszolgaltatasok: "extra_services", + erteknyilvanitas: "value_statement" + } + }, + tetelek: [ + %Item{ + megnevezes: "name", + azonosito: "identifier", + mennyiseg: "1.5", + mennyisegiEgyseg: "unit", + nettoEgysegar: "net_unit_price", + afakulcs: "27", + arresAfaAlap: "margin_vat_base", + nettoErtek: "100", + afaErtek: "27", + bruttoErtek: "127", + megjegyzes: "comment", + tetelFokonyv: nil + } + ] + } + end + end + + describe "to_xml/1" do + test "should return a valid XML" do + assert %{ + fejlec: + HeaderFactory.get_params(%{ + elolegSzamlaszam: "proforma_invoice_identifier", + helyesbitettSzamlaszam: "corrected_invoice_identifier" + }), + vevo: + CustomerFactory.get_params(%{vevoFokonyv: CustomerLedgerFactory.get_params()}), + fuvarlevel: WaybillFactory.get_params(%{mpl: %{}}), + tetelek: [ + ItemFactory.get_params(%{ + tetelFokonyv: ItemLedgerFactory.get_params() + }) + ] + } + |> params() + |> InvoiceData.parse() + |> InvoiceData.to_xml() == + """ + + + + user + password + agent_key + true + false + 0 + 1 + aggregator + false + false + external_invoice_identifier + + + 1997-08-29 + 1997-08-29 + 1997-08-29 + payment_method + HUF + en + comment + exchange_rate_bank + 123.4 + order_identifier + fee_request_identifier + false + true + proforma_invoice_identifier + false + corrected_invoice_identifier + false + false + logo_extra + PRFX + 123.4 + true + false + false + invoice_draft + false + + + bank + bank_account_number + email_reply_to + email_subject + email_text + name_of_signatory + + + name + country + zip_code + city + address + email + false + 123 + tax_identifier + group_identifier + eu_tax_identifier + mailing_name + mailing_country + mailing_zip + mailing_city + mailing_address + + accounting_date + customer_identifier + ledger_number + continuous_delivery + settlement_date_from + settlement_date_to + + identifier + name_of_signatory + phone_number + comment + + + destination + three_pl_provider + barcode + comment + + buyer_identifier + barcode + weight + extra_services + value_statement + + + + + name + identifier + 1.5 + unit + net_unit_price + 27 + margin_vat_base + 100 + 27 + 127 + comment + + economic_event + economic_event_vat + income_ledger_number + vat_ledger_number + settlement_date_from + settlement_date_to + + + + + """ + end + end + + def params(params \\ %{nope: "nope"}) do + InvoiceDataFactory.get_params(params) + end +end diff --git a/test/lib/modules/create_invoice/item_ledger_test.exs b/test/lib/modules/create_invoice/item_ledger_test.exs index 05b38a3..721df98 100644 --- a/test/lib/modules/create_invoice/item_ledger_test.exs +++ b/test/lib/modules/create_invoice/item_ledger_test.exs @@ -1,6 +1,6 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemLedgerTest do use ExUnit.Case, async: true - alias ExSzamlazzHu.Modules.CreateInvoice.ItemLedger + alias ExSzamlazzHu.Modules.CreateInvoice.Items.Item.ItemLedger alias ExSzamlazzHu.Factories.ItemLedgerFactory describe "parse/1" do @@ -20,6 +20,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemLedgerTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> ItemLedger.parse() + |> ItemLedger.to_xml() == + """ + + economic_event + economic_event_vat + income_ledger_number + vat_ledger_number + settlement_date_from + settlement_date_to + + """ + end + end + def params() do ItemLedgerFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/item_test.exs b/test/lib/modules/create_invoice/item_test.exs index 10610e5..009a45d 100644 --- a/test/lib/modules/create_invoice/item_test.exs +++ b/test/lib/modules/create_invoice/item_test.exs @@ -1,7 +1,8 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemTest do use ExUnit.Case, async: true - alias ExSzamlazzHu.Modules.CreateInvoice.Item + alias ExSzamlazzHu.Modules.CreateInvoice.Items.Item alias ExSzamlazzHu.Factories.ItemFactory + alias ExSzamlazzHu.Factories.ItemLedgerFactory describe "parse/1" do test "should parse a valid Item" do @@ -26,7 +27,39 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemTest do end end - def params() do - ItemFactory.get_params(%{nope: "nope"}) + describe "to_xml/1" do + test "should return a valid XML" do + assert %{tetelFokonyv: ItemLedgerFactory.get_params()} + |> params() + |> Item.parse() + |> Item.to_xml() == + """ + + name + identifier + 1.5 + unit + net_unit_price + 27 + margin_vat_base + 100 + 27 + 127 + comment + + economic_event + economic_event_vat + income_ledger_number + vat_ledger_number + settlement_date_from + settlement_date_to + + + """ + end + end + + def params(params \\ %{nope: "nope"}) do + ItemFactory.get_params(params) end end diff --git a/test/lib/modules/create_invoice/items_test.exs b/test/lib/modules/create_invoice/items_test.exs new file mode 100644 index 0000000..4c792d3 --- /dev/null +++ b/test/lib/modules/create_invoice/items_test.exs @@ -0,0 +1,70 @@ +defmodule ExSzamlazzHu.Modules.CreateInvoice.ItemsTest do + use ExUnit.Case, async: true + alias ExSzamlazzHu.Modules.CreateInvoice.Items + alias ExSzamlazzHu.Modules.CreateInvoice.Items.Item + alias ExSzamlazzHu.Factories.ItemFactory + alias ExSzamlazzHu.Factories.ItemLedgerFactory + + describe "parse/1" do + test "should parse a valid Item list" do + assert Items.parse(params()) == [ + %Item{ + megnevezes: "name", + azonosito: "identifier", + mennyiseg: "1.5", + mennyisegiEgyseg: "unit", + nettoEgysegar: "net_unit_price", + afakulcs: "27", + arresAfaAlap: "margin_vat_base", + nettoErtek: "100", + afaErtek: "27", + bruttoErtek: "127", + megjegyzes: "comment", + tetelFokonyv: nil + } + ] + end + + test "should parse an empty Item list" do + assert Items.parse(nil) == [] + end + end + + describe "to_xml/1" do + test "should return a valid XML" do + assert %{tetelFokonyv: ItemLedgerFactory.get_params()} + |> params() + |> Items.parse() + |> Items.to_xml() == + """ + + + name + identifier + 1.5 + unit + net_unit_price + 27 + margin_vat_base + 100 + 27 + 127 + comment + + economic_event + economic_event_vat + income_ledger_number + vat_ledger_number + settlement_date_from + settlement_date_to + + + + """ + end + end + + defp params(params \\ %{}) do + [ItemFactory.get_params(params)] + end +end diff --git a/test/lib/modules/create_invoice/mpl_test.exs b/test/lib/modules/create_invoice/mpl_test.exs index 4654086..3390874 100644 --- a/test/lib/modules/create_invoice/mpl_test.exs +++ b/test/lib/modules/create_invoice/mpl_test.exs @@ -19,6 +19,23 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.MPLTest do end end + describe "to_xml/1" do + test "should parse a valid waybill for MPL" do + assert params() + |> MPL.parse() + |> MPL.to_xml() == + """ + + buyer_identifier + barcode + weight + extra_services + value_statement + + """ + end + end + def params() do MPLFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/ppp_test.exs b/test/lib/modules/create_invoice/ppp_test.exs index 876b4f8..0f22cd7 100644 --- a/test/lib/modules/create_invoice/ppp_test.exs +++ b/test/lib/modules/create_invoice/ppp_test.exs @@ -16,6 +16,20 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.PPPTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> PPP.parse() + |> PPP.to_xml() == + """ + + barcode_prefix + barcode_postfix + + """ + end + end + def params() do PPPFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/seller_test.exs b/test/lib/modules/create_invoice/seller_test.exs index c46c2a7..869b011 100644 --- a/test/lib/modules/create_invoice/seller_test.exs +++ b/test/lib/modules/create_invoice/seller_test.exs @@ -20,6 +20,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.SellerTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> Seller.parse() + |> Seller.to_xml() == + """ + + bank + bank_account_number + email_reply_to + email_subject + email_text + name_of_signatory + + """ + end + end + def params() do SellerFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/settings_test.exs b/test/lib/modules/create_invoice/settings_test.exs index 3f99c5d..e514cac 100644 --- a/test/lib/modules/create_invoice/settings_test.exs +++ b/test/lib/modules/create_invoice/settings_test.exs @@ -25,6 +25,29 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.SettingsTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> Settings.parse() + |> Settings.to_xml() == + """ + + user + password + agent_key + true + false + 0 + 1 + aggregator + false + false + external_invoice_identifier + + """ + end + end + def params() do SettingsFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/sprinter_test.exs b/test/lib/modules/create_invoice/sprinter_test.exs index 30e1a6a..d3feee2 100644 --- a/test/lib/modules/create_invoice/sprinter_test.exs +++ b/test/lib/modules/create_invoice/sprinter_test.exs @@ -20,6 +20,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.SprinterTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> Sprinter.parse() + |> Sprinter.to_xml() == + """ + + identifier + sender_identifier + code_of_direction + package_identifier + barcode_postfix + delivery_deadline + + """ + end + end + def params() do SprinterFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/transoflex_test.exs b/test/lib/modules/create_invoice/transoflex_test.exs index 70df346..f31cc0f 100644 --- a/test/lib/modules/create_invoice/transoflex_test.exs +++ b/test/lib/modules/create_invoice/transoflex_test.exs @@ -20,6 +20,24 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.Waybill.TransoflexTest do end end + describe "to_xml/1" do + test "should return a valid XML" do + assert params() + |> Transoflex.parse() + |> Transoflex.to_xml() == + """ + + identifier + shipment_id + package_identifier + country_code + zip + service + + """ + end + end + def params() do TransoflexFactory.get_params(%{nope: "nope"}) end diff --git a/test/lib/modules/create_invoice/waybill_test.exs b/test/lib/modules/create_invoice/waybill_test.exs index 4c6db02..e15e599 100644 --- a/test/lib/modules/create_invoice/waybill_test.exs +++ b/test/lib/modules/create_invoice/waybill_test.exs @@ -29,9 +29,51 @@ defmodule ExSzamlazzHu.Modules.CreateInvoice.WaybillTest do end end - def params(custom_params \\ %{}) do - %{nope: "nope", mpl: %{}} - |> Map.merge(custom_params) - |> WaybillFactory.get_params() + describe "to_xml/1" do + test "should return a valid XML" do + assert %{tof: %{}, ppp: %{}, sprinter: %{}, mpl: %{}} + |> params() + |> Waybill.parse() + |> Waybill.to_xml() == + """ + + destination + three_pl_provider + barcode + comment + + identifier + shipment_id + package_identifier + country_code + zip + service + + + barcode_prefix + barcode_postfix + + + identifier + sender_identifier + code_of_direction + package_identifier + barcode_postfix + delivery_deadline + + + buyer_identifier + barcode + weight + extra_services + value_statement + + + """ + end + end + + def params(params \\ %{nope: "nope", mpl: %{}}) do + WaybillFactory.get_params(params) end end diff --git a/test/support/factories/invoice_data_factory.ex b/test/support/factories/invoice_data_factory.ex new file mode 100644 index 0000000..a10d323 --- /dev/null +++ b/test/support/factories/invoice_data_factory.ex @@ -0,0 +1,19 @@ +defmodule ExSzamlazzHu.Factories.InvoiceDataFactory do + alias ExSzamlazzHu.Factories.SettingsFactory + alias ExSzamlazzHu.Factories.HeaderFactory + alias ExSzamlazzHu.Factories.CustomerFactory + alias ExSzamlazzHu.Factories.SellerFactory + alias ExSzamlazzHu.Factories.WaybillFactory + alias ExSzamlazzHu.Factories.ItemFactory + + def get_params(params \\ %{}) do + %{} + |> Map.merge(params) + |> Map.put_new_lazy(:beallitasok, fn -> SettingsFactory.get_params() end) + |> Map.put_new_lazy(:fejlec, fn -> HeaderFactory.get_params() end) + |> Map.put_new_lazy(:elado, fn -> SellerFactory.get_params() end) + |> Map.put_new_lazy(:vevo, fn -> CustomerFactory.get_params() end) + |> Map.put_new_lazy(:fuvarlevel, fn -> WaybillFactory.get_params() end) + |> Map.put_new_lazy(:tetelek, fn -> [ItemFactory.get_params()] end) + end +end diff --git a/test/support/factories/waybill_factory.ex b/test/support/factories/waybill_factory.ex index 41d73a0..a1d5a64 100644 --- a/test/support/factories/waybill_factory.ex +++ b/test/support/factories/waybill_factory.ex @@ -4,7 +4,7 @@ defmodule ExSzamlazzHu.Factories.WaybillFactory do alias ExSzamlazzHu.Factories.TransoflexFactory alias ExSzamlazzHu.Factories.SprinterFactory - @three_pls [:transoflex, :ppp, :sprinter, :mpl] + @three_pls [:tof, :ppp, :sprinter, :mpl] def get_params(params \\ %{}) do %{ @@ -22,14 +22,6 @@ defmodule ExSzamlazzHu.Factories.WaybillFactory do end defp maybe_add_3pl(params) do - if Enum.all?(@three_pls, &(params[&1] == nil)) do - params - else - add_specific_3pl(params) - end - end - - defp add_specific_3pl(params) do @three_pls |> Enum.filter(&(params[&1] != nil)) |> Enum.reduce(params, fn three_pl, params -> @@ -37,7 +29,7 @@ defmodule ExSzamlazzHu.Factories.WaybillFactory do case three_pl do :mpl -> MPLFactory.get_params(params[:mpl]) :ppp -> PPPFactory.get_params(params[:ppp]) - :transoflex -> TransoflexFactory.get_params(params[:transoflex]) + :tof -> TransoflexFactory.get_params(params[:tof]) :sprinter -> SprinterFactory.get_params(params[:sprinter]) end