1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use crate::com::{FromDispatch, FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use crate::wrappers::cpta::objects::EcritureG;
use std::ops::Deref;
use windows::Win32::System::Com::IDispatch;
/// Wrapper pour l'objet EcritureOD de Sage 100c (IBOEcritureOD3)
///
/// Représente une écriture d'opérations diverses (OD).
/// Hérite de toutes les propriétés d'EcritureG avec des spécificités pour les OD.
pub struct EcritureOD {
pub ecriture: EcritureG,
}
impl EcritureOD {
/// Crée un SafeDispatch temporaire pour les appels
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.ecriture.dispatch)
}
// ==================== PROPRIÉTÉS SPÉCIFIQUES OD ====================
/// Obtient le type d'opération diverse
/// 0 = OD Générale, 1 = À-nouveaux, 2 = Situation
pub fn od_type(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("OD_Type", &[])?
.to_i32()
}
/// Définit le type d'opération diverse
pub fn set_od_type(&self, value: i32) -> SageResult<()> {
let param = SafeVariant::from_i32(value);
self.dispatch().call_property_put("OD_Type", &[param])?;
Ok(())
}
/// Obtient l'origine de l'OD
/// Chaîne décrivant la source de l'écriture (import, saisie manuelle, etc.)
pub fn od_origine(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("OD_Origine", &[])?
.to_string()
}
/// Définit l'origine de l'OD
pub fn set_od_origine(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("OD_Origine", &[param])?;
Ok(())
}
/// Obtient la référence externe de l'OD
pub fn od_reference(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("OD_Reference", &[])?
.to_string()
}
/// Définit la référence externe de l'OD
pub fn set_od_reference(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("OD_Reference", &[param])?;
Ok(())
}
// ==================== MÉTHODES IBIPersistObject ====================
/// Enregistre l'objet dans la base de données
pub fn write(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Write", &[])?;
Ok(())
}
/// Lit l'objet depuis la base de données
pub fn read(&self) -> SageResult<SafeVariant> {
self.dispatch().call_method_by_name("Read", &[])
}
/// Supprime l'objet de la base de données
pub fn remove(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Remove", &[])?;
Ok(())
}
// ==================== MÉTHODES UTILITAIRES ====================
/// Retourne une description formatée de l'écriture OD
/// Format: "OD [Type] - [Intitulé] - [Montant] €"
pub fn description(&self) -> SageResult<String> {
let type_val = self.od_type().unwrap_or(0);
let intitule = self.ecriture.ec_intitule()?;
let montant = self.ecriture.ec_montant()?;
let type_str = match type_val {
0 => "Générale",
1 => "À-nouveaux",
2 => "Situation",
_ => "Inconnue",
};
Ok(format!("OD {} - {} - {:.2} €", type_str, intitule, montant))
}
/// Retourne le type d'OD sous forme textuelle
pub fn type_description(&self) -> SageResult<String> {
let type_val = self.od_type()?;
Ok(match type_val {
0 => "OD Générale".to_string(),
1 => "À-nouveaux".to_string(),
2 => "Situation".to_string(),
_ => format!("Type inconnu ({})", type_val),
})
}
}
// Implémentation de Deref pour accéder directement aux méthodes d'EcritureG
impl Deref for EcritureOD {
type Target = EcritureG;
fn deref(&self) -> &Self::Target {
&self.ecriture
}
}
impl FromDispatch for EcritureOD {
fn from_dispatch(dispatch: IDispatch) -> SageResult<Self> {
Ok(EcritureOD {
ecriture: EcritureG { dispatch },
})
}
}
impl FromDispatchNew for EcritureOD {
fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
Ok(Self {
ecriture: EcritureG { dispatch },
})
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_ecriture_od_documentation() {
// Test de documentation - nécessite un environnement Sage pour s'exécuter
// Utilisation typique :
// let factory = app.factory_ecriture_od()?;
// let od = factory.read_numero(12345)?;
//
// // Propriétés spécifiques OD
// println!("Type: {}", od.type_description()?);
// println!("Origine: {}", od.od_origine()?);
// println!("Référence: {}", od.od_reference()?);
//
// // Propriétés héritées d'Ecriture
// println!("Intitulé: {}", od.ec_intitule()?);
// println!("Montant: {:.2} €", od.ec_montant()?);
// println!("Pièce: {}", od.ec_piece()?);
//
// // Création d'une nouvelle OD
// let nouvelle = factory.create()?;
// nouvelle.set_od_type(0)?; // OD Générale
// nouvelle.set_od_origine("Import")?;
// nouvelle.set_od_reference("REF-2025-001")?;
// nouvelle.write()?;
}
}