Skip to content

Instantly share code, notes, and snippets.

@pacoguevara
Created January 13, 2016 23:29
Show Gist options
  • Save pacoguevara/890cd0eb56c1964877aa to your computer and use it in GitHub Desktop.
Save pacoguevara/890cd0eb56c1964877aa to your computer and use it in GitHub Desktop.
def calc_amount(factura, amount, rfc)
empresa = Empresa.find_by_rfc(rfc)
if (factura.estatus == "Cancelado" || !amount) && factura.polizas_of(empresa.id).blank?
return 0
end
return 0 if factura.tipo_de_comprobante == 'traslado'
if factura.tipo_cambio_id.present? && factura.tipo_cambio.present? && Factura.getMoneda(factura.moneda) != "pesos"
vartotal = amount
tipo_cambio_p = factura.tipo_cambio.precio
return 0 if !amount #check for duplicates
vartotal = amount * tipo_cambio_p
else
vartotal = amount
end
if factura.subtotal == amount
if factura.total == amount
resultado = (factura.descuento != 0.0 && !factura.descuento.nil?) ? vartotal - factura.descuento : vartotal
else
resultado = vartotal
end
else
resultado = vartotal
end
if factura.tipo_de_comprobante == "ingreso" || factura.is_nomina == true
resultado
else
-resultado
end
end
describe "class methods" do
describe ".calc_amount" do
before(:each) do
@empresa_receptora = FactoryGirl.create(:empresa, name: "40 West",
rfc: "CWG1011107T9")
@empresa_emisora = FactoryGirl.create(:empresa, name: "ABA",
rfc: "ABA920310QW0")
@factura = FactoryGirl.create(:factura, rfc_em: @empresa_emisora.rfc,
rfc_re: @empresa_receptora.rfc, md5: "5681928685ae18e3b623d1d0f1910512",
uuid: "E8027172-A541-4707-8913-C7528D67FCF3", usuario_id: 21)
@amount = 10
end
it "returns 0 when the invoice amount is nil" do
expect(Factura.calc_amount(@factura, nil, @empresa_receptora.rfc)).to eq 0
end
it "returns 0 when the invoice.tipo_comprobante is traslado" do
@factura.tipo_de_comprobante = 'traslado'
expect(Factura.calc_amount(@factura, @factura.total, @empresa_receptora.rfc)).to eq 0
end
context "when the invoice status is 'Cancelado'" do
before(:each) do
@factura.estatus = 'Cancelado'
end
it "returns 0.0 when the invoice doesnt has polizas for the company" do
expect(Factura.calc_amount(@factura, @factura.total, @empresa_receptora.rfc)).to eq 0
end
context "and when the invoice has policies for the company" do
before(:each) do
@poliza_factura = FactoryGirl.create(:poliza, factura_id: @factura.id,
status_account_id: nil, poliza_manual_id: nil, tipo_categoria: "Factura",
empresa_id: @empresa_receptora.id)
end
context "and when moneda is different to 'pesos'" do
before(:each) do
@tipo_cambio = FactoryGirl.create(:tipo_cambio)
@factura.moneda = "USD"
@factura.tipo_cambio_id = @tipo_cambio.id
end
it "returns invoice total multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
context "and factura.subtotal is equal to amount" do
before(:each) do
@factura.subtotal = @amount
end
context "and factura.total is equal to amount" do
before(:each) do
@factura.total = @amount
end
context "and factura.descuento is diffetent to 0.0 and
factura.descuento is not nil" do
before(:each) do
@factura.descuento = 5
end
it "returns invoice total * multiplied by tipo_cambio.precio
- factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio - @factura.descuento
expect(amount).to eq multiplied
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio
- factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio - @factura.descuento
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
- factura.descuento * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio - @factura.descuento
expect(amount).to eq -multiplied
end
end
end
context "and factura.descuento is 0.0 or is nil" do
before(:each) do
@factura.descuento = 0.0
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
* -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq -multiplied
end
end
end
end
context "and factura.total is different to amount" do
before(:each) do
@factura.total = @amount+5
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
* -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq -multiplied
end
end
end
end
context "factura.subtotal is different to amount" do
before(:each) do
@factura.subtotal = @amount+3
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
* -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq -multiplied
end
end
end
end
context "and when moneda is pesos" do
before(:each) do
@tipo_cambio = FactoryGirl.create(:tipo_cambio)
@factura.moneda = "MXN"
@factura.tipo_cambio_id = @tipo_cambio.id
end
context "and factura.subtotal is equal to amount" do
before(:each) do
@factura.subtotal = @amount
end
context "and factura.total is equal to amount" do
before(:each) do
@factura.total = @amount
end
context "and factura.descuento is diffetent to 0.0 and
factura.descuento is not nil" do
before(:each) do
@factura.descuento = 5
end
it "returns invoice total - factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * factura.descuento * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq -multiplied
end
end
end
context "and factura.descuento is 0.0 or is nil" do
before(:each) do
@factura.descuento = 0.0
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "and factura.total is different to amount" do
before(:each) do
@factura.total = @amount+5
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "factura.subtotal is different to amount" do
before(:each) do
@factura.subtotal = @amount+3
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "when tipo_cambio_id and tipo_cambio are not present" do
context "and factura.subtotal is equal to amount" do
before(:each) do
@factura.subtotal = @amount
end
context "and factura.total is equal to amount" do
before(:each) do
@factura.total = @amount
end
context "and factura.descuento is diffetent to 0.0 and
factura.descuento is not nil" do
before(:each) do
@factura.descuento = 5
end
it "returns invoice total - factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total - factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total - factura.descuento * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq -multiplied
end
end
end
context "and factura.descuento is 0.0 or is nil" do
before(:each) do
@factura.descuento = 0.0
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "and factura.total is different to amount" do
before(:each) do
@factura.total = @amount+5
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "factura.subtotal is different to amount" do
before(:each) do
@factura.subtotal = @amount+3
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
end
end
context "when the invoice status is not 'Cancelado'" do
before(:each) do
@factura.estatus = 'Vigente'
end
it "returns 0.0 when the invoice doesnt has polizas for the company" do
expect(Factura.calc_amount(@factura, @factura.total, @empresa_receptora.rfc)).to eq 0
end
context "and when the invoice has policies for the company" do
before(:each) do
@poliza_factura = FactoryGirl.create(:poliza, factura_id: @factura.id,
status_account_id: nil, poliza_manual_id: nil, tipo_categoria: "Factura",
empresa_id: @empresa_receptora.id)
end
context "and when moneda is different to 'pesos'" do
before(:each) do
@tipo_cambio = FactoryGirl.create(:tipo_cambio)
@factura.moneda = "USD"
@factura.tipo_cambio_id = @tipo_cambio.id
end
it "returns invoice total multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
context "and factura.subtotal is equal to amount" do
before(:each) do
@factura.subtotal = @amount
end
context "and factura.total is equal to amount" do
before(:each) do
@factura.total = @amount
end
context "and factura.descuento is diffetent to 0.0 and
factura.descuento is not nil" do
before(:each) do
@factura.descuento = 5
end
it "returns invoice total * multiplied by tipo_cambio.precio
- factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio - @factura.descuento
expect(amount).to eq multiplied
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio
- factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio - @factura.descuento
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
- factura.descuento * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio - @factura.descuento
expect(amount).to eq -multiplied
end
end
end
context "and factura.descuento is 0.0 or is nil" do
before(:each) do
@factura.descuento = 0.0
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
* -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq -multiplied
end
end
end
end
context "and factura.total is different to amount" do
before(:each) do
@factura.total = @amount+5
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
* -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq -multiplied
end
end
end
end
context "factura.subtotal is different to amount" do
before(:each) do
@factura.subtotal = @amount+3
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total * multiplied by tipo_cambio.precio" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * multiplied by tipo_cambio.precio
* -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount * @tipo_cambio.precio
expect(amount).to eq -multiplied
end
end
end
end
context "and when moneda is pesos" do
before(:each) do
@tipo_cambio = FactoryGirl.create(:tipo_cambio)
@factura.moneda = "MXN"
@factura.tipo_cambio_id = @tipo_cambio.id
end
context "and factura.subtotal is equal to amount" do
before(:each) do
@factura.subtotal = @amount
end
context "and factura.total is equal to amount" do
before(:each) do
@factura.total = @amount
end
context "and factura.descuento is diffetent to 0.0 and
factura.descuento is not nil" do
before(:each) do
@factura.descuento = 5
end
it "returns invoice total - factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * factura.descuento * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq -multiplied
end
end
end
context "and factura.descuento is 0.0 or is nil" do
before(:each) do
@factura.descuento = 0.0
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "and factura.total is different to amount" do
before(:each) do
@factura.total = @amount+5
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "factura.subtotal is different to amount" do
before(:each) do
@factura.subtotal = @amount+3
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "when tipo_cambio_id and tipo_cambio are not present" do
context "and factura.subtotal is equal to amount" do
before(:each) do
@factura.subtotal = @amount
end
context "and factura.total is equal to amount" do
before(:each) do
@factura.total = @amount
end
context "and factura.descuento is diffetent to 0.0 and
factura.descuento is not nil" do
before(:each) do
@factura.descuento = 5
end
it "returns invoice total - factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total - factura.descuento" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq multiplied
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total - factura.descuento * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
multiplied = @amount - @factura.descuento
expect(amount).to eq -multiplied
end
end
end
context "and factura.descuento is 0.0 or is nil" do
before(:each) do
@factura.descuento = 0.0
end
context "and factura.tipo_comprobante is 'ingresos' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "and factura.total is different to amount" do
before(:each) do
@factura.total = @amount+5
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingresos' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
context "factura.subtotal is different to amount" do
before(:each) do
@factura.subtotal = @amount+3
end
context "and factura.tipo_comprobante is 'ingreso' or factura
is nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'ingreso'
@factura.is_nomina = true
end
it "returns invoice total" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq @amount
end
end
context "and factura.tipo_comprobante is not 'ingreso' and is
not nomina" do
before(:each) do
@factura.tipo_de_comprobante = 'egreso'
@factura.is_nomina = false
end
it "returns invoice total * -1" do
amount = Factura.calc_amount(@factura, @amount,
@empresa_receptora.rfc)
expect(amount).to eq -@amount
end
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment