Skip to main content

TaxLineGenerator

Struct TaxLineGenerator 

Source
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

  1. Exempt check — if the product category is in config.exempt_categories, no tax lines are emitted.
  2. Jurisdiction determination — for VendorInvoice (input tax) the seller country is the taxing jurisdiction; for CustomerInvoice (output tax) the buyer country is used (destination-based); for JournalEntry the seller country is used.
  3. EU reverse charge — when both countries are in the EU and differ, reverse-charge rules apply: the buyer self-assesses at their own rate.
  4. 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

Source

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.

Source

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_country to select jurisdiction
  • Cross-border EU B2B transactions trigger reverse charge
  • product_category may trigger an exemption
  • doc_type determines input (AP) vs output (AR) tax treatment
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more