create_journal_voucher
Create journal vouchers for adjustment or contra entries in TallyPrime by specifying date, ledgers, amount, and optional narration.
Instructions
Create a journal voucher in TallyPrime (adjustment or contra entry).
Args: date: Voucher date YYYYMMDD. debit_ledger: Ledger to debit. credit_ledger: Ledger to credit. amount: Journal amount. narration: Optional description.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | ||
| debit_ledger | Yes | ||
| credit_ledger | Yes | ||
| amount | Yes | ||
| narration | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- MCP tool handler for create_journal_voucher. Decorated with @mcp.tool(), it accepts date, debit_ledger, credit_ledger, amount, and optional narration. Calls client.create_journal_voucher() and returns a success/failure message.
@mcp.tool() async def create_journal_voucher( date: str, debit_ledger: str, credit_ledger: str, amount: float, narration: str = "", ) -> str: """ Create a journal voucher in TallyPrime (adjustment or contra entry). Args: date: Voucher date YYYYMMDD. debit_ledger: Ledger to debit. credit_ledger: Ledger to credit. amount: Journal amount. narration: Optional description. """ try: result = await client.create_journal_voucher( date=date, debit_ledger=debit_ledger, credit_ledger=credit_ledger, amount=amount, narration=narration, ) if result["success"]: return f"Journal voucher created. Dr: {debit_ledger}, Cr: {credit_ledger}, Amount: {amount:.2f}, Date: {date}" return f"Failed: {result['message']}" except TallyError as e: return f"Error: {e}" - TallyClient.create_journal_voucher — async client method that builds XML via create_journal_voucher_xml(), sends it to TallyPrime, parses the response, and returns a dict with success/message.
async def create_journal_voucher(self, **kwargs) -> dict: from .xml_builder import create_journal_voucher_xml return self._check_import_result(self._parse(await self.send_xml(create_journal_voucher_xml(**kwargs)))) - create_journal_voucher_xml — builds the Tally XML string for a Journal voucher with debit/credit ledger entries, wrapped in a voucher import envelope.
def create_journal_voucher_xml( date: str, debit_ledger: str, credit_ledger: str, amount: float, narration: str = "", ) -> str: voucher = f"""<VOUCHER ACTION="Create" VCHTYPE="Journal"> <DATE>{date}</DATE> <VOUCHERTYPENAME>Journal</VOUCHERTYPENAME> <NARRATION>{narration}</NARRATION> <ALLLEDGERENTRIES.LIST> <LEDGERNAME>{debit_ledger}</LEDGERNAME> <ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE> <AMOUNT>-{amount}</AMOUNT> </ALLLEDGERENTRIES.LIST> <ALLLEDGERENTRIES.LIST> <LEDGERNAME>{credit_ledger}</LEDGERNAME> <ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE> <AMOUNT>{amount}</AMOUNT> </ALLLEDGERENTRIES.LIST> </VOUCHER>""" return _voucher_import_envelope(voucher) - src/tallyprime_mcp/tools/__init__.py:7-12 (registration)register_all calls vouchers.register(mcp, client) which registers the create_journal_voucher tool onto the FastMCP instance via decorator pattern.
def register_all(mcp: FastMCP, client: TallyClient): company.register(mcp, client) ledgers.register(mcp, client) vouchers.register(mcp, client) reports.register(mcp, client)