This question has been flagged

Hi all

Putting this here in case it's of use to anyone who has the same business need I had. Maybe there's a simpler way of doing things, but this way worked for me after some digging around....

The problem: I need an automated action to send a mail to contacts based on certain trigger criteria. However it should only be sent to contacts which meet certain criteria, including how long ago their contact record was created (I.e a dynamic date referenced to current date) 

As standard we can't do this. Every time we save the domain filter with the code for dynamic dates it gets overwritten with static dates. 

E.g. ["&",["partner_id.title","=","Doctor"]["partner_id.create_date","<", time.strftime('%y-%m-%d 00:00:00')]

gets overwritten with

["&",["partner_id.title","=","Doctor"],["partner_id.create_date","<", "2020-01-09 00:00:00"]]

The reason is mentioned here:  \https://github.com/odoo/odoo/issues/22956

This\ page\ gives\ a\ clue\ as\ to\ the\ code\ changes\ that\ introduced\ the\ widget\ for\ domain\:\\

\\https://gitlab.openminds.be/mirror/odoo/commit/e3f99885ca789b338a4cb9ab9a154db50dff500d

My Solution. The URL from Automated Actions tells us which model to use: 

\https://<myserver>/web?debug#id=5&view_type=form&model=base.automation&menu_id=273&action=397 

Under Technical > Views, we can find the Form view for that model. It is called Automations.

Duplicate that view, calling it ZAutomations.

overwrite the <field name="filter_pre_domain" ... and <field name="filter_domain" ... lines with these two lines:

<field name="filter_pre_domain" widget="char_domain" options="{'model_field': 'model'}"/>
<field name="filter_domain" widget="char_domain" options="{'model_field': 'model'}"/>

Set the sequence value for this new view to 10 (i.e. higher than the default 16 for the standard Automations view

Now when I go back to edit my Automated Actions the widget for domain is replaced by a field where I can paste my dynamic filter code. (e.g.   ["&",["partner_id.title","=","Doctor"]["partner_id.create_date","<", time.strftime('%y-%m-%d 00:00:00')] ) from my example above.

The dynamic entries are no longer overwritten by static values on save.

Whenever I want to revert to the standard view (for example if I'm testing a new filter and need to find the right fields and definitions), I can just change the sequence value of my Zautomations view to 20. Then when I view the Automated Actions I'm back to the standard view with the domain widget.

Cheers

Mike



     

Avatar
Discard