pub struct TaxLineGenerator { /* private fields */ }Expand description
Generates tax lines for documents (AP invoices, AR invoices, JEs).
This is a decorator generator that takes a set of pre-generated
TaxCodes and produces TaxLine records for source documents.
§Tax Determination Logic
- Exempt check — if the product category is in
config.exempt_categories, no tax lines are emitted. - Jurisdiction determination — for
VendorInvoice(input tax) the seller country is the taxing jurisdiction; forCustomerInvoice(output tax) the buyer country is used (destination-based); forJournalEntrythe seller country is used. - EU reverse charge — when both countries are in the EU and differ, reverse-charge rules apply: the buyer self-assesses at their own rate.
- Deductibility — vendor invoices are deductible (input VAT is recoverable), customer invoices and journal entries are not.
§Examples
use datasynth_generators::tax::TaxLineGenerator;
use datasynth_generators::tax::TaxLineGeneratorConfig;
use datasynth_generators::tax::TaxCodeGenerator;
let mut code_gen = TaxCodeGenerator::new(42);
let (_jurisdictions, codes) = code_gen.generate();
let mut gen = TaxLineGenerator::new(TaxLineGeneratorConfig::default(), codes, 42);Implementations§
Source§impl TaxLineGenerator
impl TaxLineGenerator
Sourcepub fn new(
config: TaxLineGeneratorConfig,
tax_codes: Vec<TaxCode>,
seed: u64,
) -> Self
pub fn new( config: TaxLineGeneratorConfig, tax_codes: Vec<TaxCode>, seed: u64, ) -> Self
Creates a new tax line generator.
tax_codes are indexed by their jurisdiction_id for O(1) lookup.
Sourcepub fn generate_for_document(
&mut self,
doc_type: TaxableDocumentType,
doc_id: &str,
seller_country: &str,
buyer_country: &str,
taxable_amount: Decimal,
date: NaiveDate,
product_category: Option<&str>,
) -> Vec<TaxLine>
pub fn generate_for_document( &mut self, doc_type: TaxableDocumentType, doc_id: &str, seller_country: &str, buyer_country: &str, taxable_amount: Decimal, date: NaiveDate, product_category: Option<&str>, ) -> Vec<TaxLine>
Generates tax lines for a single document.
Determines the applicable tax code based on:
seller_country/buyer_countryto select jurisdiction- Cross-border EU B2B transactions trigger reverse charge
product_categorymay trigger an exemptiondoc_typedetermines input (AP) vs output (AR) tax treatment
Sourcepub fn generate_batch(
&mut self,
doc_type: TaxableDocumentType,
documents: &[(String, String, String, Decimal, NaiveDate, Option<String>)],
) -> Vec<TaxLine>
pub fn generate_batch( &mut self, doc_type: TaxableDocumentType, documents: &[(String, String, String, Decimal, NaiveDate, Option<String>)], ) -> Vec<TaxLine>
Batch-generates tax lines for multiple documents.
Each tuple element: (doc_id, seller_country, buyer_country, amount, date, optional category).
Auto Trait Implementations§
impl Freeze for TaxLineGenerator
impl RefUnwindSafe for TaxLineGenerator
impl Send for TaxLineGenerator
impl Sync for TaxLineGenerator
impl Unpin for TaxLineGenerator
impl UnsafeUnpin for TaxLineGenerator
impl UnwindSafe for TaxLineGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more