İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
6466 Görünümler

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?

Avatar
Vazgeç
En İyi Yanıt

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>

 

 

Avatar
Vazgeç
Üretici

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!

En İyi Yanıt

Hi,

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

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
4
Mar 24
3658
1
Eki 23
5556
1
Haz 22
6851
4
Haz 21
16114
2
Ağu 17
12817