Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
971 Lượt xem

Hi, I want to add or create a new filter/search option in the Odoo financial reports.


For example, in the Odoo financial report Balance Sheet, i tried to inherit the existing template and add a new filterlike this example:


		
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="l10n_ve_reports.AccountReportCurrencySelect" t-inherit="account_reports.AccountReportFiltersCustomizable">
<xpath expr="//div[@id='filter_extra_options']" position="after">
​<div id="multi_currency_selection">
​<p>My EXAMPLE</p>​
​</div>
</xpath>
</t>
</templates>

I added my example as above, and put it on __manifest__ . py, but nothing changed in all my templates.

I want to add a new dropdown to select a currency, but for now, I just want to be able to display a dropdown.

Can someone help me with this? Thanks before hand.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

To add a custom dropdown filter (e.g., for currency selection) in Odoo 17.0 financial reports, you need to properly inherit the relevant XML templates and integrate the dropdown into the report filter system. Here's how you can achieve this:

Step-by-Step Solution

1. Identify the Correct Template to Inherit

Odoo financial reports use the account_reports.AccountReportFiltersCustomizable template for filters. Ensure you are targeting the correct template and its structure.

2. Create a Custom Module

If you haven't already, create a custom module to house your changes.

Directory structure:

custom_financial_report_filter/
├── __init__.py
├── __manifest__.py
├── views/
│   └── financial_report_filter.xml

3. Update the __manifest__.py File

Define your module and include the dependency on account_reports.

{
    'name': 'Custom Financial Report Filters',
    'version': '1.0',
    'depends': ['account_reports'],
    'author': 'Your Name',
    'data': [
        'views/financial_report_filter.xml',
    ],
    'installable': True,
    'application': False,
}

4. Inherit the Template and Add Your Dropdown

Create the financial_report_filter.xml file to extend the financial report filters.

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="add_custom_currency_filter" inherit_id="account_reports.AccountReportFiltersCustomizable">
        <xpath expr="//div[@id='filter_extra_options']" position="inside">
            <div class="form-group" id="multi_currency_selection">
                <label for="currency_dropdown">Select Currency:</label>
                <select id="currency_dropdown" class="form-control">
                    <option value="USD">USD</option>
                    <option value="EUR">EUR</option>
                    <option value="GBP">GBP</option>
                </select>
            </div>
        </xpath>
    </template>
</odoo>

5. Add Backend Logic to Handle the Dropdown

To make the dropdown functional, you need to pass the selected value to the report:

  1. Override Report Action: Modify the action context to include the selected currency value.
  2. Extend account.report Model: Add custom logic to handle the selected currency in the report.
    Example Python code:
    from odoo import models, fields
    
    class AccountReport(models.AbstractModel):
        _inherit = 'account.report'
    
        filter_currency = fields.Selection([
            ('USD', 'USD'),
            ('EUR', 'EUR'),
            ('GBP', 'GBP'),
        ], string="Currency", default='USD')
    
        def _get_report_values(self, docids, data):
            # Add custom logic to filter based on currency
            if self.filter_currency:
                data['currency'] = self.filter_currency
            return super(AccountReport, self)._get_report_values(docids, data)
    

6. Update the JavaScript (Optional)

If you want the dropdown to dynamically update the report without reloading, you can use JavaScript to handle the interaction.

  1. Add a JS File: Create a JS file to add dynamic behavior.
    Example:
    odoo.define('custom_financial_report_filter.CurrencyDropdown', function (require) {
        "use strict";
    
        const publicWidget = require('web.public.widget');
    
        publicWidget.registry.CurrencyDropdown = publicWidget.Widget.extend({
            selector: '#multi_currency_selection',
            events: {
                'change #currency_dropdown': '_onCurrencyChange',
            },
            _onCurrencyChange: function (ev) {
                const selectedCurrency = $(ev.target).val();
                // Send an AJAX request to reload the report
                console.log('Selected currency:', selectedCurrency);
            },
        });
    });
    
  2. Include the JS File in Your Module: Update the __manifest__.py to include the JS file.

7. Test Your Changes

  1. Restart your Odoo server and upgrade the module:
    ./odoo-bin -u custom_financial_report_filter
    
  2. Open the financial reports (e.g., Balance Sheet) and verify that the dropdown is displayed and functional.

Key Notes

  • Ensure Proper Dependencies: Your custom module must depend on account_reports for proper inheritance.
  • Test in Developer Mode: Use Odoo's developer mode to debug template inheritance and confirm the dropdown is rendered correctly.
  • Dynamic Behavior: If you need the dropdown to update results dynamically, you'll need to implement AJAX handling in your JavaScript.

By following these steps, you can add a custom dropdown to Odoo 17.0 financial reports. Let me know if you need further clarification or assistance!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

We’ve already developed this for one of our customers. Connect with us to learn more. 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 25
270
1
thg 4 25
865
1
thg 2 25
557
3
thg 1 25
3562
2
thg 11 24
2076