[FIX] *: missing date filter for stat button

Reproduction:
1. Install Sale, Inventory
2. Go to Sale->products, search for “Customizable Desk”
3. Hover the cursor on the stat button “Sold”, from its definition, the
analysis should show the sold items in last 365 days
4. Click on the “Sold” button, no filter for “Order Date”

Reason: in V14, the “time_ranges” feature is removed. Thus using it in
the context won’t create any filter for searching

Fix: We use a custom filter to replace the time range "last_365_days".
We also make sure that the domain produced by that filter is the same as
the one used to compute the button count server side (this was not the
case in Odoo 13 when "last_365_days" was used). Similar fix is also done
in mrp and l10n_ar. Mind the utc convert for correct results.

opw-3000595

Related commits:
Removal of time_ranges: https://github.com/odoo-dev/odoo/commit/be5a51a345b8986da0e19627260f64f984e11ae9
Date filter fix: https://github.com/odoo/enterprise/pull/10938

closes odoo/odoo#108951

X-original-commit: 03057029b210a59f3d7012aeea66cfa95790a8c8
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Signed-off-by: Liu Jinjiu (jili) <jili@odoo.com>
This commit is contained in:
Jinjiu Liu
2023-01-02 20:39:53 +01:00
parent f100decbf4
commit b5e8f85eaa
6 changed files with 8 additions and 5 deletions
@@ -9,6 +9,7 @@
<search>
<field name="l10n_ar_state_id"/>
<filter name="with_document" string="With Document" domain="[('l10n_latam_document_type_id', '!=', False)]"/>
<filter name="filter_accounting_date_this_year" invisible="1" string="Accounting Date: This Year" domain="[('date', '&lt;', (context_today() + relativedelta(years=1, month=1, day=1)).strftime('%Y-%m-%d')), ('date', '&gt;=', (context_today() + relativedelta(month=1, day=1)).strftime('%Y-%m-%d'))]"/>
</search>
<filter name="user" position="after">
<filter string="State" name="groupby_l10n_ar_state_id" context="{'group_by': 'l10n_ar_state_id'}"/>
@@ -21,7 +22,7 @@
<field name="name">IIBB - Sales by jurisdiction</field>
<field name="res_model">account.invoice.report</field>
<field name="view_mode">pivot</field>
<field name="context">{'search_default_current': 1, 'search_default_customer': 1, 'search_default_with_document': 1, 'search_default_company': 1, 'search_default_groupby_l10n_ar_state_id': 2, 'search_default_groupby_account_id': 3, 'time_ranges': {'field': 'date', 'range': 'this_year'}}</field>
<field name="context">{'search_default_current': 1, 'search_default_customer': 1, 'search_default_with_document': 1, 'search_default_company': 1, 'search_default_groupby_l10n_ar_state_id': 2, 'search_default_groupby_account_id': 3, 'search_default_filter_accounting_date_this_year': 1}</field>
</record>
<menuitem
@@ -34,7 +35,7 @@
<field name="name">IIBB - Purchases by jurisdiction</field>
<field name="res_model">account.invoice.report</field>
<field name="view_mode">pivot</field>
<field name="context">{'search_default_current': 1, 'search_default_supplier': 1, 'search_default_with_document': 1, 'search_default_company': 1, 'search_default_groupby_l10n_ar_state_id': 2, 'search_default_groupby_account_id': 3, 'time_ranges': {'field': 'date', 'range': 'this_year'}}</field>
<field name="context">{'search_default_current': 1, 'search_default_supplier': 1, 'search_default_with_document': 1, 'search_default_company': 1, 'search_default_groupby_l10n_ar_state_id': 2, 'search_default_groupby_account_id': 3, 'search_default_filter_accounting_date_this_year': 1}</field>
</record>
<menuitem
+1 -1
View File
@@ -83,7 +83,7 @@ class ProductTemplate(models.Model):
action['domain'] = [('state', '=', 'done'), ('product_tmpl_id', 'in', self.ids)]
action['context'] = {
'graph_measure': 'product_uom_qty',
'time_ranges': {'field': 'date_planned_start', 'range': 'last_365_days'}
'search_default_filter_plan_date': 1,
}
return action
@@ -556,6 +556,7 @@
<filter invisible="1" string="Future Activities" name="activities_upcoming_all"
domain="[('my_activity_date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]"/>
<filter name="filter_date_planned_start" string="Scheduled Date" date="date_planned_start"/>
<filter name="filter_plan_date" invisible="1" string="Scheduled Date: Last 365 Days" domain="[('date_planned_start', '>', (datetime.datetime.now() + relativedelta(days=-365)).to_utc().strftime('%Y-%m-%d %H:%M:%S'))]"/>
<separator/>
<filter string="Warnings" name="activities_exception"
domain="[('activity_exception_decoration', '!=', False)]"/>
+1 -1
View File
@@ -50,7 +50,7 @@ class ProductProduct(models.Model):
'active_id': self._context.get('active_id'),
'search_default_Sales': 1,
'active_model': 'sale.report',
'time_ranges': {'field': 'date', 'range': 'last_365_days'},
'search_default_filter_order_date': 1,
}
return action
+1 -1
View File
@@ -88,7 +88,7 @@ class ProductTemplate(models.Model):
'active_id': self._context.get('active_id'),
'active_model': 'sale.report',
'search_default_Sales': 1,
'time_ranges': {'field': 'date', 'range': 'last_365_days'}
'search_default_filter_order_date': 1,
}
return action
+1
View File
@@ -54,6 +54,7 @@
<filter string="Sales Orders" name="Sales" domain="[('state','not in',('draft', 'cancel', 'sent'))]"/>
<separator/>
<filter name="filter_date" date="date" default_period="this_month"/>
<filter name="filter_order_date" invisible="1" string="Order Date: Last 365 Days" domain="[('date', '&gt;=', (datetime.datetime.combine(context_today() + relativedelta(days=-365), datetime.time(0,0,0))).strftime('%Y-%m-%d %H:%M:%S'))]"/>
<separator/>
<field name="user_id"/>
<field name="team_id"/>