Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6805aea8f | |||
| 59bbeaf9de |
Generated
+4
-4
@@ -139,7 +139,7 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
|
||||
|
||||
[[package]]
|
||||
name = "fiscus-capture"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"fiscus-ledger",
|
||||
"proptest",
|
||||
@@ -150,7 +150,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fiscus-insight"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"fiscus-ledger",
|
||||
"serde",
|
||||
@@ -159,7 +159,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fiscus-ledger"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"proptest",
|
||||
"serde",
|
||||
@@ -169,7 +169,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fiscus-statement"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"fiscus-ledger",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/fiscus-ledger", "crates/fiscus-statement", "crates/fiscus-insight", "crates/fiscus-capture"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
repository = "https://gitea.marek-novak.cz/mnovak/FiscusPublic"
|
||||
|
||||
@@ -226,4 +226,12 @@ pub enum EventBody {
|
||||
/// An invoice issued for a business project, and the time entries it bills (none: not from time).
|
||||
#[serde(rename = "invoice.projected")]
|
||||
InvoiceProjected { invoice: InvoiceId, project: ProjectId, entries: Vec<EntryId> },
|
||||
/// The project is shared with the members of a shared budget: the app mirrors its name, dates, status, lines,
|
||||
/// phases and tasks through that budget's log. Time, invoices and project rules are never shared. One budget
|
||||
/// at a time.
|
||||
#[serde(rename = "project.shared")]
|
||||
ProjectShared { project: ProjectId, budget: BudgetId },
|
||||
/// Not shared any more: the members keep the copy they have.
|
||||
#[serde(rename = "project.unshared")]
|
||||
ProjectUnshared { project: ProjectId },
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! the month, so nothing is counted twice. Personal log only, like plans and goals.
|
||||
|
||||
use crate::date::Date;
|
||||
use crate::event::PaymentId;
|
||||
use crate::event::{BudgetId, PaymentId};
|
||||
use crate::goal::Colour;
|
||||
use crate::invoice::InvoiceId;
|
||||
use crate::money::Haler;
|
||||
@@ -160,6 +160,9 @@ pub struct Projects {
|
||||
pub payments: BTreeMap<PaymentId, (ProjectId, Option<LineId>)>,
|
||||
/// "Always this merchant → this project", by merchant key.
|
||||
pub rules: BTreeMap<String, ProjectId>,
|
||||
/// A project shared with a shared budget's members → that budget (`project.shared`).
|
||||
#[serde(default)]
|
||||
pub shared: BTreeMap<ProjectId, BudgetId>,
|
||||
}
|
||||
|
||||
/// The Monday of `d`'s week.
|
||||
|
||||
@@ -1166,6 +1166,23 @@ impl State {
|
||||
}
|
||||
self.projects.projects.get_mut(project).expect("checked").invoices.insert(invoice.clone());
|
||||
}
|
||||
EventBody::ProjectShared { project, budget } => {
|
||||
if !self.projects.projects.contains_key(project) {
|
||||
return Err("no such project");
|
||||
}
|
||||
if !self.budgets.contains_key(budget) {
|
||||
return Err("no such budget");
|
||||
}
|
||||
if self.projects.shared.contains_key(project) {
|
||||
return Err("the project is shared already");
|
||||
}
|
||||
self.projects.shared.insert(project.clone(), budget.clone());
|
||||
}
|
||||
EventBody::ProjectUnshared { project } => {
|
||||
if self.projects.shared.remove(project).is_none() {
|
||||
return Err("the project is not shared");
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -34,6 +34,38 @@ fn log(entry: &str, project: &str, minutes: u32, on: &str) -> EventBody {
|
||||
EventBody::TimeLogged { entry: entry.into(), project: project.into(), task: None, minutes, on: d(on), rate: Haler(80_000), note: String::new() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_project_is_shared_with_one_budget_at_a_time_and_unshared_once() {
|
||||
let budget = |id: &str| EventBody::BudgetShared { budget: id.into(), name: "Home".into(), limit: Haler(0) };
|
||||
let base = vec![project("p1", Kind::Simple), budget("home"), budget("chata")];
|
||||
let share = |b: &str| EventBody::ProjectShared { project: "p1".into(), budget: b.into() };
|
||||
assert_eq!(refusal(&base, share("home")), None);
|
||||
assert_eq!(refusal(&base, EventBody::ProjectShared { project: "nope".into(), budget: "home".into() }).as_deref(), Some("no such project"));
|
||||
assert_eq!(refusal(&base, share("nope")).as_deref(), Some("no such budget"));
|
||||
let mut shared = base.clone();
|
||||
shared.push(share("home"));
|
||||
assert_eq!(refusal(&shared, share("chata")).as_deref(), Some("the project is shared already"));
|
||||
assert_eq!(refusal(&shared, share("home")).as_deref(), Some("the project is shared already"));
|
||||
let state = State::replay(&shared.iter().enumerate().map(|(i, b)| ev(&format!("s{i}"), b.clone())).collect::<Vec<_>>());
|
||||
assert_eq!(state.projects.shared.get("p1").map(String::as_str), Some("home"));
|
||||
assert_eq!(refusal(&base, EventBody::ProjectUnshared { project: "p1".into() }).as_deref(), Some("the project is not shared"));
|
||||
shared.push(EventBody::ProjectUnshared { project: "p1".into() });
|
||||
assert_eq!(refusal(&shared, EventBody::ProjectUnshared { project: "p1".into() }).as_deref(), Some("the project is not shared"));
|
||||
assert_eq!(refusal(&shared, share("chata")), None, "shared again, elsewhere");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_shared_events_keep_their_names_on_the_wire() {
|
||||
let json = serde_json::to_string(&EventBody::ProjectShared { project: "p1".into(), budget: "home".into() }).unwrap();
|
||||
assert!(json.contains("\"project.shared\""), "{json}");
|
||||
let json = serde_json::to_string(&EventBody::ProjectUnshared { project: "p1".into() }).unwrap();
|
||||
assert!(json.contains("\"project.unshared\""), "{json}");
|
||||
// A state saved before sharing existed still reads.
|
||||
let old = serde_json::json!({ "projects": {}, "tasks": {}, "time": {}, "payments": {}, "rules": {} });
|
||||
let p: fiscus_ledger::project::Projects = serde_json::from_value(old).unwrap();
|
||||
assert!(p.shared.is_empty());
|
||||
}
|
||||
|
||||
/// The base ledger, then `body`: the reason it was refused, or `None` when it was accepted.
|
||||
fn refusal(base: &[EventBody], body: EventBody) -> Option<String> {
|
||||
let mut log: Vec<Event> = base.iter().enumerate().map(|(i, b)| ev(&format!("b{i}"), b.clone())).collect();
|
||||
|
||||
@@ -18,6 +18,7 @@ still builds only `payment.shared`.
|
||||
| `task.created { task, project, fields }` / `task.changed` / `task.status_set` | title, phase, due, estimate, line, assignee, milestone; to do, doing, done (with the day) |
|
||||
| `time.logged { entry, project, task?, minutes, on, rate, note }` / `time.removed` | business only; invoiced time is not removed |
|
||||
| `invoice.projected { invoice, project, entries }` | an invoice for a business project, and the time entries it bills (each once) |
|
||||
| `project.shared { project, budget }` / `project.unshared { project }` | shared with a shared budget's members, one budget at a time; the app mirrors the name, dates, status, lines, phases and tasks through that budget's log, never time, invoices or project rules. Unshared, the members keep their copy |
|
||||
|
||||
**What each event accepts:**
|
||||
- names: 1–60 characters, task titles 1–120, assignees 1–40;
|
||||
|
||||
Reference in New Issue
Block a user