| 1 |
|
defmodule DaProductApp.Merchants.MerchantInvoice do |
| 2 |
|
@moduledoc """ |
| 3 |
|
Merchant invoice extracted from RespValQr. |
| 4 |
|
""" |
| 5 |
|
use Ecto.Schema |
| 6 |
|
import Ecto.Changeset |
| 7 |
|
|
| 8 |
|
@primary_key {:id, :binary_id, autogenerate: true} |
| 9 |
|
@foreign_key_type :binary_id |
| 10 |
:-( |
schema "merchant_invoices" do |
| 11 |
|
field :invoice_name, :string |
| 12 |
|
field :invoice_number, :string |
| 13 |
|
field :invoice_date, :utc_datetime |
| 14 |
|
belongs_to :merchant, DaProductApp.Merchants.Merchant |
| 15 |
|
belongs_to :qr_validation, DaProductApp.QRValidation.QRValidation |
| 16 |
|
field :inserted_at, :utc_datetime |
| 17 |
|
end |
| 18 |
|
|
| 19 |
|
@required ~w(merchant_id)a |
| 20 |
|
@optional ~w(invoice_name invoice_number invoice_date qr_validation_id)a |
| 21 |
|
|
| 22 |
|
def changeset(struct, attrs) do |
| 23 |
|
struct |
| 24 |
|
|> cast(attrs, @required ++ @optional) |
| 25 |
:-( |
|> validate_required(@required) |
| 26 |
|
end |
| 27 |
|
end |