zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

product_batch.ex (1668B)


      1 # Zenflows is designed to implement the Valueflows vocabulary,
      2 # written and maintained by srfsh <info@dyne.org>.
      3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>.
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Affero General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Affero General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Affero General Public License
     16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 
     18 defmodule Zenflows.VF.ProductBatch do
     19 @moduledoc """
     20 A lot or batch, defining a resource produced at the same time in the
     21 same way.
     22 """
     23 
     24 use Zenflows.DB.Schema
     25 
     26 alias Ecto.Changeset
     27 alias Zenflows.DB.{Schema, Validate}
     28 
     29 @type t() :: %__MODULE__{
     30 	batch_number: String.t(),
     31 	expiry_date: DateTime.t() | nil,
     32 	production_date: DateTime.t() | nil,
     33 }
     34 
     35 schema "vf_product_batch" do
     36 	field :batch_number, :string
     37 	field :expiry_date, :utc_datetime_usec
     38 	field :production_date, :utc_datetime_usec
     39 	timestamps()
     40 end
     41 
     42 @reqr [:batch_number]
     43 @cast @reqr ++ ~w[expiry_date production_date]a
     44 
     45 @doc false
     46 @spec changeset(Schema.t(), Schema.params()) :: Changeset.t()
     47 def changeset(schema \\ %__MODULE__{}, params) do
     48 	schema
     49 	|> Changeset.cast(params, @cast)
     50 	|> Changeset.validate_required(@reqr)
     51 	|> Validate.name(:batch_number)
     52 end
     53 end