Wire Odoo invoices to billing view (Fixes #13)
This commit is contained in:
parent
808765ef5a
commit
f762f5c030
3 changed files with 79 additions and 4 deletions
36
lib/recycledcloud/billing/invoice.ex
Normal file
36
lib/recycledcloud/billing/invoice.ex
Normal file
|
@ -0,0 +1,36 @@
|
|||
defmodule RecycledCloud.Billing.Invoice do
|
||||
alias RecycledCloud.Billing.{Partner, Invoice}
|
||||
alias RecycledCloud.Odoo
|
||||
|
||||
use Ecto.Schema
|
||||
|
||||
embedded_schema do
|
||||
field :display_name, :string
|
||||
field :invoice_date, :date
|
||||
field :invoice_date_due, :date
|
||||
field :amount_total, :float
|
||||
field :access_url, :string
|
||||
field :state, :string
|
||||
end
|
||||
|
||||
def get_all_for(%Partner{} = partner) do
|
||||
fields = ["id", "display_name", "invoice_date", "invoice_date_due",
|
||||
"amount_total", "access_url", "state"]
|
||||
result = Odoo.query([
|
||||
"account.move",
|
||||
"search_read",
|
||||
[[["commercial_partner_id", "=", partner.id]]],
|
||||
%{"fields" => fields}
|
||||
])
|
||||
|
||||
structify = fn raw ->
|
||||
args = raw |> Enum.map(fn {k, v} -> {String.to_atom(k), v} end)
|
||||
struct(Invoice, args)
|
||||
end
|
||||
|
||||
case result do
|
||||
{:ok, entries} -> entries |> Enum.map(structify)
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
defmodule RecycledCloudWeb.BillingController do
|
||||
use RecycledCloudWeb, :controller
|
||||
|
||||
alias RecycledCloud.Billing.Partner
|
||||
alias RecycledCloud.Billing.{Partner, Invoice}
|
||||
alias RecycledCloud.Repo
|
||||
|
||||
def current_partner(conn) do
|
||||
|
@ -12,8 +12,15 @@ defmodule RecycledCloudWeb.BillingController do
|
|||
def index(conn, _params) do
|
||||
partner = conn |> current_partner
|
||||
changeset = partner |> Partner.changeset(%{})
|
||||
invoices = partner |> Invoice.get_all_for
|
||||
|
||||
render(conn, "index.html", partner: partner, partner_changeset: changeset)
|
||||
render(
|
||||
conn,
|
||||
"index.html",
|
||||
partner: partner,
|
||||
partner_changeset: changeset,
|
||||
invoices: invoices
|
||||
)
|
||||
end
|
||||
|
||||
def update(conn, %{"partner" => changes} = params) do
|
||||
|
@ -26,8 +33,15 @@ defmodule RecycledCloudWeb.BillingController do
|
|||
|> put_flash(:info, "Billing Partner has been updated")
|
||||
|> redirect(to: Routes.billing_path(conn, :index))
|
||||
{:error, changeset} ->
|
||||
render(conn, "index.html", partner: partner, partner_changeset:
|
||||
changeset)
|
||||
|
||||
invoices = partner |> Invoice.get_all_for
|
||||
render(
|
||||
conn,
|
||||
"index.html",
|
||||
partner: partner,
|
||||
partner_changeset: changeset,
|
||||
invoices: invoices
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,3 +38,28 @@
|
|||
<%= submit "Change address" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<h2>Invoices</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Created On</th>
|
||||
<th>Due on</th>
|
||||
<th>Amount</th>
|
||||
<th>State</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for invoice <- @invoices do %>
|
||||
<tr>
|
||||
<td><%= invoice.display_name %></td>
|
||||
<td><%= invoice.invoice_date %></td>
|
||||
<td><%= invoice.invoice_date_due %></td>
|
||||
<td><%= invoice.amount_total %></td>
|
||||
<td><%= invoice.state %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
Loading…
Reference in a new issue