Contributors mailing list archives
contributors@odoo-community.org
Browse archives
Re: Well practise on rewrite action domain
by
Axel Mendoza
Hi all
There is an alternative to do it completely incremental by using python code, re-implementing the search method of the target model, that is sale.order in this case, to add the extra domain rules to the domain of the search.
This is a valid way of do it and you could find examples of use in the Odoo core modules like in addons/base/res/res_bank.py of v9
Here is how can be done:
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
pos = 0
while pos < len(args):
if args[pos] == ('state', 'not in', ('draft', 'sent', 'cancel')):
args[pos] = ('state', 'not in', ('draft', 'sent', 'cancel', 'archived'))
return super(ResPartnerBank, self).search(args, offset, limit, order, count=count)
# or
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
pos = 0
while pos < len(args):
if args[pos][0] == 'state' and args[pos][1] == 'not in':
elems = list(args[pos][2])
elems.append('archived')
args[pos] = ('state', 'not in', elems)
return super(ResPartnerBank, self).search(args, offset, limit, order, count=count)
What better works for your case.
You could also check if isinstance(args[pos], (list, tuple, set)) and len(args[pos]) == 3, values of the context or anything you need to be sure that you are modifying the search of an specific action since the same search method will be used by everything that try to search on the model using the conditions that match the if statement
Hope this make it clear
On Thu, Jan 26, 2017 at 3:23 PM, Richard deMeester <richardd@willdooit.com> wrote:
Hi Michael,I understand your pain on this type of thing.A solution of sorts, particularly if module A and module B are not dependent in either direction is:Module A:....<field name="domain">[('state', 'not in', ('draft', 'sent', 'cancel')),('x_type_contract','=','1')]Module B:....<field name="domain">[('state', 'not in', ('archived')),]Module C: (depends on A, B and the clever part, auto_install = True so this module is automatic when A and B are both installed)....<field name="domain">[('state', 'not in', ('draft', 'sent', 'cancel', 'archived')),('x_type_contract','=','1')]Of course, this is not as elegant as could be, and does mean rewriting the domain in two modules if it ever needs to change, and does not extend any base domains (or domains that a third party module may have just added to the same action!)--On 13 January 2017 at 07:38, Michael Delvoye <mdelvoye@misyl-services.com> wrote:Hi every bodyi need to rewrite action sale order like this in one module :<record id="sale.action_orders" model="ir.actions.act_window">
<field name="view_id" ref="sale.view_order_tree"/>
<field name="domain">[
('state', 'not in', ('draft', 'sent', 'cancel')),
('x_type_contract','=','1')
]
</field>
</record>Bu in an other module i need to exclude 'state' '=' 'archived')I don't know the best practise to do that.Can you orient me. Of course I . can centralize it in one module but i would prefer to keep each module and to "cumulate" the domain.Thanks for help--Michael DelvoyeDirecteur TechniqueMISYL SERVICES______________________________
_________________
Mailing-List: http://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: http://odoo-community.org/groups?unsubscribe ______________________________
_________________
Mailing-List: http://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: http://odoo-community.org/groups?unsubscribe
Reference
-
Well practise on rewrite action domain
byMISYL SERVICES., Michael Delvoye-
Re: Well practise on rewrite action domain
byMISYL SERVICES., Michael Delvoye -
Re: Well practise on rewrite action domain
byMISYL SERVICES., Michael Delvoye -
Re: Well practise on rewrite action domain
byMISYL SERVICES., Michael Delvoye -
Re: Well practise on rewrite action domain
byWilldooIT, Richard deMeester -
Re: Well practise on rewrite action domain
byMISYL SERVICES., Michael Delvoye -
Re: Well practise on rewrite action domain
byWeb-veistämö Oy/Avoin.Systems, Miku Laitinen. -
Re: Well practise on rewrite action domain
byOpen Architects Consulting, Houssine BAKKALI -
Re: Well practise on rewrite action domain
byMISYL SERVICES., Michael Delvoye -
Re: Well practise on rewrite action domain
byOpen Architects Consulting, Houssine BAKKALI
-