Skip to Content
Menu
This question has been flagged
1 Reply
15688 Views

I want to filter a domain with a function instead of a variable in order to show only some registers in the view.

I have done this:

 

 class SaleOrderExt(models.Model):
  _inherit = ['sale.order']
  @api.multi
  def custom_funct_date(self):
   my_date = ... (some stuff)
   return my_date

Then, in the view, I have filtered the domain:

 

    <?xml version="1.0"?>
    <openerp>
      <data>
        <record id='action_menu_custom_date' model='ir.actions.act_window'>
          <field name="name">This is a test</field>
          <field name="res_model">sale.order</field>
          <field name="view_type">form</field>
          <field name="view_mode">tree,form</field>
          <field name="domain">[('date_order','>=',custom_funct_date)]</field>
        </record>
      </data>
    </openerp>

But this is giving me an error:

    ValueError: "name 'custom_funct_date' is not defined" while evaluating
    u"[('date_order','>=',custom_funct_date)]"
Avatar
Discard
Best Answer

Hello

I suggest you to add one more field which is compute field. and then pass in domain. use custom_funct_date method in that new compute field.


Avatar
Discard
Author

Okay, I have tried this too: my_date = fields.Datetime(string="Computed date", compute="custom_funct_date")

But it gives me that error: ValueError: "name 'my_date' is not defined" while evaluating u"[('date_order','>=', my_date)]"

it's wrong syntax.

try this one.

"[('date_order','>=', 'my_date')]"

also add my_date on view file and set invisible = 1

Author

DataError: invalid input syntax for type timestamp: "my_date"

LÍNEA 1: ...ids"."res_id") AND (("sale_order"."date_order" >= 'my_date...

did you add field in form view?

Author

I think so. In my custom view, the field appears (if I quit the part of invisible).

make sure your compute function return proper date format like sale_order.date_order,

try also without ('date_order','>=', my_date)

*with ('date_order','>=', my_date)

Author

Checked and same result :(

Author

I think that if I put this:

('date_order','>=', my_date)

my_date is treated as a variable, and that variable doesn't exist.

If I put:

('date_order','>=', 'my_date')

'my_date' is treated as a string, and gives an error, because a string doen't have a datetime type

Any solution For this problem ? i have the same use case.

Related Posts Replies Views Activity
6
Sep 20
18932
2
May 18
3503
2
Sep 16
7057
2
Mar 15
11498
2
Mar 15
5443