Skip to Content
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
3170 Представления

I 'm trying to add custom filter to balance sheet report and profit and loss report in odoo 17
I added the following code :



i added this code in filter.xml in this path:
hat_account_report_multi_currency\static\src\components\hat_account_report_multi_currency\filters.xml
and i added te following code in manifest file:
'assets': {
'web.assets_backend': [
'hat_account_report_multi_currency/static/src/components/**/*',
],
},
but there is nothing appears in the report

Аватар
Отменить

Did you find any solution for it ?

Has anyone got guide to add in additional data column to the Aged Receivable reports. How does that work out? and how do we add similar dropdown in Aged Receivable reports.

Лучший ответ

Not like this you need to do 3 things in js and xml and py 
i think that you want currency filter will be like 
lets start with js we need extend AccountReportFilters to use our new template which we inherit it to add our new filter
xml like you did 
<?xml version="1.0" encoding="UTF-8" ?>
<templates> 
​<t t-name="your_module_name.ExtendedAccountReportFilters" t- ​inherit="account_reports.AccountReportFiltersCustomizable"> 

​<xpath expr="//div[@id='filter_extra_options']" position="before"> <t t-if="'currency' in controller.options"> 

​<Dropdown togglerClass="'btn btn-secondary'"> <t t-set-slot="toggler"> <i class="fa fa-folder-open me-1"/>Currencies </t> <MultiRecordSelector t-props="getMultiRecordSelectorProps('res.currency', 'currency_ids')"/> 

​</Dropdown> 

​</t> 
 </xpath> 
 </t>
</templates>

and in js 

/** @odoo-module **/
import { AccountReport } from "@account_reports/components/account_report/account_report";
import { AccountReportFilters } from "@account_reports/components/account_report/filters/filters";
export class ExtendedAccountReportFilters extends AccountReportFilters { 
  ​static template = 'your_module_name.ExtendedAccountReportFilters';

  ​setup() { 
  ​super.setup();
  ​}
}
AccountReport.registerCustomComponent(ExtendedAccountReportFilters);

			​this new component to make odoo use our new template 
lets go to python side 
first inherit account.report 

class AccountReport(models.Model): 
​ _inherit = 'account.report'
​ filter_currency = fields.Boolean(string="Currencies",compute=lambda x: x._compute_report_option_filter('filter_currency'), readonly=False, store=True, depends=['root_report_id', 'section_main_report_ids'],)
##################################################### 
OPTIONS: currencys 
####################################################
​​def _init_options_currency(self, options, previous_options=None): 
​if not self.filter_currency: 
​return 
​options['currency'] = True 
​previous_currency_ids = previous_options and previous_options.get('currency_ids') or []
​​selected_currency_ids = [int(currency) for currency in previous_currency_ids]  
​selected_currencys = selected_currency_ids and self.env['res.currency'].with_context(active_test=False).search([('id', 'in', selected_currency_ids)]) or self.env['res.currency']
​options['selected_currency_ids'] = selected_currencys.mapped('name') 
​@api.model 
​def _get_options_currency_domain(self, options): 
​​domain = [] 
​if options.get('currency_ids'): 
​ currency_ids = [int(currency) for currency in options['currency_ids']] ​               
​domain.append(('currency_id', 'in', currency_ids)) ​ 
​return domain
​​def _get_options_domain(self, options, date_scope): 
​domain = super()._get_options_domain(options, date_scope) 
​domain += self._get_options_city_domainoptions)  
​domain += self._get_options_currency_domain(options) 
​return domain

and in report you want we will inherit it's handler and override _get_custom_display_config func like to make odoo you our component


from odoo import models, fields, api 
class AccountPartnerLedgerReportHandler(models.AbstractModel): 
​_inherit = 'account.partner.ledger.report.handler'
​def _get_custom_display_config(self): 
​return { 'css_custom_class': 'partner_ledger',
​'templates': ​{'AccountReportLineName':'account_reports.PartnerLedgerLineName',}, 
​ 'components': {'AccountReportFilters': 'your_module_name.ExtendedAccountReportFilters',}}
 
last thing in in account.report form we need add currency_filter field to check it to show filter

<?xml version="1.0" encoding="utf-8"?>
<odoo> 
 <!-- View account.report form --> 
​<record id="view_account_report_form" model="ir.ui.view"> 
​<field name="name">view.account.report.form</field> 
​<field name="model">account.report</field> 
​<field name="inherit_id" ref="account_reports.account_report_form"/> 
​<field name="arch" type="xml"> 
​<xpath expr="//field[@name='filter_partner']" position="after"> 
​​<field name="filter_currency" /> 
​</xpath> 
​</field> 
​ </record>
</odoo>
Аватар
Отменить
Лучший ответ

From your screenshot and description, you are trying to add a custom dropdown filter in financial reports like the Balance Sheet and Profit and Loss reports in Odoo 17. However, it seems the filter is not appearing as expected. Here’s how you can troubleshoot and implement it correctly:

1. Verify the Inherited Template

You are inheriting the account_reports.AccountReportFiltersCustomizable template, which is correct. Ensure that:

  • The template ID is correct.
  • The XPath expression accurately targets the desired location in the template.

Your XPath:

<xpath expr="//div[@id='filter_date']" position="before">

Checklist:

  • Open the Odoo developer tools in your browser.
  • Inspect the DOM structure of the filters section in the financial report to confirm the filter_date ID exists.
  • Ensure there are no typos or missing elements.

If the ID filter_date is dynamic or not found, try targeting a broader or adjacent parent element.

Example:

<xpath expr="//div[contains(@class, 'o_account_reports_filter')]//div[1]" position="before">

2. Ensure the Dropdown Component is Correct

You are using a Dropdown component, which appears to be a custom or Odoo-provided widget. Verify that:

  • The Dropdown component is correctly defined in your codebase.
  • Any dependencies required by the component are loaded properly.

For debugging, replace the dropdown with static HTML to check if it appears:

<div id="curr" class="curr">
    <button class="btn btn-secondary">Test Dropdown</button>
</div>

If this appears, the issue is likely with the Dropdown component configuration.

3. Validate Asset Loading

Ensure the assets are correctly declared and loaded:

  • Manifest File Configuration:
    'assets': {
        'web.assets_backend': [
            'hat_account_report_multi_currency/static/src/components/**/*',
        ],
    },
    
    Confirm the path matches your file structure. The wildcard **/* includes all files under components.
  • Rebuild Odoo Assets: After making changes to the manifest, rebuild assets to ensure they are properly loaded:
    ./odoo-bin -c odoo.conf --dev=assets
    
  • Check Browser Console: Open the browser developer tools and check for errors or missing assets.

4. Confirm Template Usage

The financial reports might use specific rendering logic for filters. Confirm that:

  • The account_reports.AccountReportFiltersCustomizable template is used for Balance Sheet and Profit and Loss reports.
  • The inheritance chain is correctly applied.

5. Test Component Integration

Add debugging logs or a simple placeholder message to verify the component is rendered:

<div id="curr" class="curr">
    <p>Custom filter test message</p>
</div>

If this doesn’t appear, your XPath or asset declaration might be incorrect.

6. Add the Custom Filter Logic

If the dropdown is successfully displayed but doesn’t affect the report, implement the filter logic in the corresponding account.report model.

For example:

  1. Add a Field for the Filter: Add a field to handle the filter's value in the backend:
    class AccountReport(models.AbstractModel):
        _inherit = 'account.report'
    
        filter_currency = fields.Many2one('res.currency', string="Currency Filter")
    
  2. Update the Report Values: Override the _get_report_values method to include the custom filter's logic:
    def _get_report_values(self, docids, data):
        report_values = super()._get_report_values(docids, data)
        if data.get('filter_currency'):
            # Add custom filtering logic here
            report_values['currency_filter'] = data['filter_currency']
        return report_values
    
  3. Pass Filter Value from Frontend to Backend: Use JavaScript to handle the dropdown selection and pass the selected value to the report.

7. Testing

  1. Reload the Odoo server and activate developer mode.
  2. Check if the filter appears in the financial reports.
  3. Test the functionality by applying different filter values.

Common Debugging Tips:

  • Check Logs: Look for any server-side or frontend errors in the browser console or Odoo logs.
  • Inspect DOM: Ensure your XML changes are reflected in the DOM.
  • Minimal Testing: Use a simple <div> to verify if the XPath and template inheritance work.

Let me know if you need further assistance!

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
авг. 24
2046
0
сент. 21
2752
0
мар. 15
4693
2
мая 24
674
0
февр. 24
635