10 KiB
Vendor Batch Payment Merge - Technical Guide
Overview
This document provides technical details about the Vendor Batch Payment Merge addon implementation. It covers the models, views, and business logic used to extend Odoo's batch payment functionality.
Architecture
Models
account.batch.payment (Inherited)
Extended to include direct payment lines functionality:
-
Field:
direct_payment_line_ids(One2many)- Links to
account.batch.payment.linerecords - Allows creation of payment templates directly in the batch form
- Links to
-
Method:
generate_payments_from_lines()- Creates actual payment records from direct payment lines
-
Posts the payments
-
Adds them to the batch
-
Links each line to its generated payment
account.batch.payment.line (New)
Represents a direct payment line template:
-
Fields:
batch_payment_id(Many2one): Link to the parent batch paymentpartner_id(Many2one): The partner (vendor/customer)amount(Monetary): Payment amountcurrency_id(Many2one): Payment currency (related to batch)expense_account_id(Many2one): Expense/Income account for journal entrymemo(Char): Payment memodate(Date): Payment datepayment_id(Many2one): Link to generated payment (readonly)
-
Methods:
_onchange_partner_id(): Placeholder for future enhancements
account.payment (Inherited)
Extended to support expense account functionality:
-
Field:
expense_account_id(Many2one)- Specifies the account to use in journal entries instead of default payable/receivable
-
Method:
_compute_destination_account_id()- Overrides the default destination account computation
- Uses the expense account if specified
-
Method:
_prepare_move_line_default_vals()- Overrides journal entry line creation
- Uses the expense account in the counterpart line
Views
account_batch_payment_views.xml
- Inherited View:
account_batch_payment.view_batch_payment_form - Additions:
- New "Direct Payment Lines" tab with editable tree view
- "Generate Payments" button in the header
- Restored smart partner filtering based on batch type:
- For outbound payments: Shows partners with supplier_rank > 0
- For inbound payments: Shows partners with customer_rank > 0
account_payment_views.xml
- Inherited View:
account.view_account_payment_form - Additions:
- Expense account field in the main form
- Visibility condition to show only for relevant payment types
Data
account_payment_method_data.xml
- Creates two payment methods with code
direct_batch:- One for inbound payments
- One for outbound payments
Business Logic
Payment Generation Flow
- User creates direct payment lines in batch payment form
- User clicks "Generate Payments"
- System validates that all lines have a partner selected
- For each line:
- Determine payment type and partner type based on batch type
- Create payment record with specified details
- Post the payment
- Link the line to the generated payment
- Add all generated payments to the batch
Journal Entry Creation
When a payment with an expense account is posted:
- Standard liquidity line is created (bank account)
- Instead of using the partner's payable/receivable account, the expense account is used
- This allows for more flexible accounting without affecting partner balances
Implementation Details
Field Domains
-
Partner Fields:
- Restored smart filtering based on batch type:
- For outbound payments:
supplier_rank > 0 - For inbound payments:
customer_rank > 0
- For outbound payments:
- Added
no_createoption to prevent creating new partners from the payment line
- Restored smart filtering based on batch type:
-
Expense Account Fields:
account_type not in ('asset_receivable', 'liability_payable')
Payment Method Handling
The addon creates payment methods with code direct_batch and now properly handles payment method lines:
- Searches for existing payment method lines with the correct code and journal
- Automatically creates payment method lines if they don't exist
- Properly links payments to payment method lines
Error Handling
- Validates that a direct batch payment method line exists for the journal or can be created
- Validates that all payment lines have a partner selected
- Handles both inbound and outbound payment types appropriately
- Links direct payment lines to generated payments for traceability
Testing
Test Cases
-
test_create_vendor_batch_payment_with_direct_lines
- Creates a vendor batch payment with direct lines
- Verifies payment generation and linking
-
test_create_customer_batch_payment_with_direct_lines
- Creates a customer batch payment with direct lines
- Verifies payment generation and linking
-
test_expense_account_in_journal_entry
- Verifies that the expense account is used in journal entries
- Checks journal entry line balances
-
test_direct_batch_payment_method
- Verifies that the payment methods are created
- Checks for payment method lines (note: existence not asserted due to Odoo's automatic creation)
Test Data
- Demo vendor and customer partners
- Demo expense and income accounts
- Bank journal (created if not exists)
Security
Access Rights
- Standard Odoo accounting security model applies
- New model
account.batch.payment.linehas full access rights - No additional security groups required
Record Rules
- Inherits standard Odoo record rules
- No additional record rules implemented
Extensibility
Hooks for Customization
-
account.batch.payment
generate_payments_from_lines()can be extended- Additional fields can be added to direct payment lines
-
account.payment
_compute_destination_account_id()can be further customized_prepare_move_line_default_vals()can be extended for additional modifications
Integration Points
- Payment Methods: Additional payment methods can be added
- Account Types: Additional account types can be supported
- Journal Types: Extension to other journal types is possible
Performance Considerations
Batch Operations
- Payment generation is done in batch for efficiency
- Database operations are minimized through proper ORM usage
- Large batch payments should be handled efficiently
Computed Fields
- Properly decorated computed fields with dependencies
- Efficient search and filter operations
- Minimal impact on form loading times
Known Limitations
-
Payment Method Lines:
- Payment method lines are created automatically by Odoo
- Manual creation may be needed in some configurations
-
Multi-Currency:
- Standard Odoo multi-currency handling applies
- No additional currency-specific logic implemented
-
Workflow Integration:
- Standard Odoo payment workflow is used
- No additional workflow states or transitions
Dependencies
Odoo Modules
account: Core accounting functionalityaccount_batch_payment: Base batch payment functionality
Python Libraries
- Standard Odoo Python environment
- No additional Python dependencies required
Installation
File Structure
vendor_batch_payment_merge/
├── __init__.py
├── __manifest__.py
├── data/
│ ├── __init__.py
│ └── account_payment_method_data.xml
├── demo/
│ └── demo_data.xml
├── doc/
│ ├── __init__.py
│ ├── user_guide.md
│ └── technical_guide.md
├── models/
│ ├── __init__.py
│ ├── account_batch_payment.py
│ └── account_payment.py
├── security/
│ └── ir.model.access.csv
├── tests/
│ ├── __init__.py
│ └── test_vendor_batch_payment_merge.py
└── views/
├── __init__.py
├── account_batch_payment_views.xml
└── account_payment_views.xml
Installation Process
- Place addon in Odoo addons directory
- Update Apps list
- Install "Vendor Batch Payment Merge" addon
- No additional configuration required
Upgrade Considerations
Version Compatibility
- Designed for Odoo 17
- May require adjustments for other versions
- Follows standard Odoo inheritance patterns
Data Migration
- No special migration needed for new installations
- Existing batch payments unaffected
- Direct payment lines are new records with no impact on existing data
Recent Fixes
Partner Field Issues
- Removed
required=Trueconstraint on partner_id field to avoid constraint issues - Fixed incorrect reference to
property_account_expenseon partner model - Added validation in payment generation to ensure all lines have partners
- Restored smart partner filtering based on batch type
Payment Method Line Issues
- Fixed search for payment method lines to properly look for
codefield - Added automatic creation of payment method lines when they don't exist
- Improved error handling for missing payment methods
Domain Context Issues
- Fixed domain context for proper partner filtering in payment lines
- Used
parent.batch_typeinstead ofcontext.get('default_batch_type')for accurate filtering
View Improvements
- Restored smart partner filtering based on batch type
- Improved error handling for missing partners
- Added
no_createoption to prevent accidental partner creation
Troubleshooting
Common Issues
-
Payment Method Not Found
- Verify addon installation
- Check payment method data
- Ensure journal configuration
- The addon now automatically creates payment method lines if they don't exist
-
Missing Partner Error
- Ensure all payment lines have a partner selected
- Check that the partner field is not empty for any line
-
Journal Entry Account Issues
- Verify expense account specification
- Check payment posting status
- Confirm account types
-
View Errors
- Verify XML view definitions
- Check field references
- Confirm model inheritance
Debugging Tips
- Enable debug mode in Odoo
- Check server logs for error messages
- Use Odoo's developer tools to inspect views
- Verify model and field definitions
- Test with minimal data sets
Support
For technical issues or questions, consult the Odoo community or contact the addon developer.