Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
6451 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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!

Jawaban Terbai

Hi,

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

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
4
Mar 24
3632
1
Okt 23
5529
1
Jun 22
6818
4
Jun 21
16064
2
Agu 17
12784