Skip to Content
Menú
This question has been flagged
8 Respostes
35974 Vistes

In the search view in a tree view, when I group by date, it always group by month, there is any way to specify to group by day, year or even hour?

Avatar
Descartar

Have you found a solution?

Best Answer

It's better do it this way:

<filter string="Day" domain="[ ]" context="{'group_by': 'create_date:day'}" />
Avatar
Descartar
Autor Best Answer

I made a workaround, the idea is that you create a function field(store=True) of type char that copy the date string detail to the function field, the level of detail is determined by that you want to group, if you want to group by day copy the datetime till the day.

Then you add that new field in your groupby filters in the searchview you want

Avatar
Descartar

Hey Felipe, Your idea will work for him. This is the way used in most official addons of OpenERP out of the box. This idea works. Just check code of Sales Analysis or Invoice analysis, you will find more useful techniques

What are the name of directories and files that you pointed out? Thanks

Best Answer

This is an old question, but I thought I would add some code in case anyone is trying to do this. Mine was adding a sort by day field to account_voucher, so you may need to adjust yours to whatever you are trying to inherit. I am not putting the whole code, just the relevant snippets.

your_module.py

class ec_account_voucher(osv.osv):
_inherit = 'account.voucher'
_name = 'account.voucher'
def _get_string_date(self, cr, uid, ids, name, args, context=None):
res = {}
for voucher in self.browse(cr, uid, ids, context=context):
res[voucher.id] = str(voucher.date)
return res
_columns = {
'x_string_date': fields.function(_get_string_date, type='char', string='Date (String)', store=True)
}

your_module_view.xml

       <record model="ir.ui.view" id="voucher_form_ec">
<field name="name">account.voucher.tree.inherit</field>
<field name="model">account.voucher</field>
<field name="inherit_id" ref="account_voucher.view_voucher_tree"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="x_string_date" invisible="1"/>
</field>
</field>
</record>
<record id="ec_view_voucher_filter" model="ir.ui.view">
<field name="name">account.voucher.select.inherit</field>
<field name="model">account.voucher</field>
<field name="inherit_id" ref="account_voucher.view_voucher_filter_vendor_pay"/>
<field name="arch" type="xml">
<xpath expr="//filter[@string='Status']" position="before">
<filter string="Day" icon="terp-go-month" domain="[]" context="{'group_by':'x_string_date'}"/>
</xpath>
</field>
</record>

Hope that helps someone!

Avatar
Descartar

Thank you so much :D

No problem - glad it helped!

Related Posts Respostes Vistes Activitat
3
d’abr. 25
4655
5
de nov. 23
42967
3
de set. 23
9455
1
de set. 22
3730
1
de juny 22
12551