Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to make inactive the contacts that belong to inactive companies

By
George Rodopoulos
on 9/2/14, 12:28 PM 916 views

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?

0
Lucio
On 9/2/14, 12:44 PM

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>

 

 

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 ?

George Rodopoulos
on 9/2/14, 1:00 PM

I updated the answer with the changes needed!

Lucio
on 9/2/14, 1:14 PM
0
Tomasz Leppich
On 9/2/14, 1:38 PM

Hi,

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/2/14, 12:28 PM
Seen: 916 times
Last updated: 3/16/15, 8:10 AM