Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
6424 Widoki

Is there any way to automatically change the status (active/inactive) of multiple Contacts based on the status (active/inactive) of the parent Company?

I would be able to do this if I could (but I can't) :

  1. Filter the 'Persons' that belong to Companies that are inactive
  2. Mass update the status of multiple Partners (Companies and Persons)

Is there any way to achieve this?

Awatar
Odrzuć
Najlepsza odpowiedź

Hi, 

you can do this from the DB directly. Do you have access to the database?

Execute:
    
    UPDATE res_partner SET active = 'f' WHERE parent_id in (SELECT id FROM res_partner WHERE is_company = 't' AND active = 'f')

Also, you can create a function on_change for the active field of a partner like this:


    def onchange_active_partner(self, cr, uid, ids, active, context=None):
        if not active:
            childs_ids = self.search(cr, uid, [('parent_id','in',ids)])
            self.write(cr, uid, childs_ids, {'active': False})
        return {'value' : {}, }

Hope this helps!

UPDATE:

You will have to create a new file (a good name will be res_partner.py)

# -*- coding: utf-8 -*-

from openerp.osv import osv, fields

class res_partner(osv.osv):
    _inherit = 'res.partner'

        def onchange_active_partner(self, cr, uid, ids, active, context=None):
            if not active:
                childs_ids = self.search(cr, uid, [('parent_id','in',ids)])
                self.write(cr, uid, childs_ids, {'active': False})
            return {'value' : {}, }

res_partner()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

And put it into the __init__.py file like
import res_partner

Finally add the onchange function to the views:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record id="view_partner_form_onchange_inherit" model="ir.ui.view">
            <field name="name">res.partner.with.onchange.form.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <field name="active" position="attributes" >
                  <attribute name="on_change">onchange_active_partner(active)</attribute>
                </field>
            </field>
        </record>
    </data>
</openerp>

 

 

Awatar
Odrzuć
Autor

I used the query that you provided and it worked as expected. Thanks! Where should I add the function that you provided, if I want all the contacts to automatically inherit any changes made to the Parent company status ?

I updated the answer with the changes needed!

Najlepsza odpowiedź

Hi,

I think you could do it also via import/export feature. 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
mar 24
3566
1
paź 23
5497
1
cze 22
6766
4
cze 21
16032
2
sie 17
12765