# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2013 XCG Consulting (www.xcg-consulting.fr)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields,osv
from openerp.tools.translate import _

class res_partner(osv.osv):
    _name = 'res.partner'
    _inherit =  ['res.partner','mail.thread', 'ir.needaction_mixin']

    def _check_supplier_account(self, cr, uid, obj, ctx=None):
        print "*"*35
        print obj['supplier']
        print obj.property_account_payable.type
        res = obj['supplier'] and not obj.property_account_payable.type == 'payable'
        return res

    def _check_customer_account(self, cr, uid, obj, ctx=None):
        print "*"*35
        print obj['customer']
        print obj.property_account_receivable.type
        res = obj['customer'] and not obj.property_account_receivable.type == 'receivable'
        return res

    _track = {
        'property_account_payable': {
            'account_streamline.mt_partner_supplier': _check_supplier_account,
            },
        'property_account_receivable': {
            'account_streamline.mt_partner_customer': _check_customer_account,
            },
        }
@@ -2000,16 +2000,1664 @@
     %7D,%0A        %7D
+%0A%0A    def create(self, cr, uid, values, context=None):%0A        %22%22%22 Override to control notifications %22%22%22%0A        if context is None:%0A            context = %7B%7D%0A        context.update(%7B'mail_create_nolog':True, 'mail_create_nosubscribe':True%7D)%0A        cur_id = super(res_partner, self).create(cr, uid, values, context=context)%0A        new_partner = self.browse(cr, uid, cur_id, context=context)%0A        if self._check_supplier_account(cr, uid, new_partner):%0A            self.message_post(cr, uid, cur_id,%0A                          type='comment', subtype='account_streamline.mt_partner_supplier', context=context)%0A        elif self._check_customer_account(cr, uid, new_partner):%0A            self.message_post(cr, uid, cur_id,%0A                              type='comment', subtype='account_streamline.mt_partner_customer', context=context)%0A        return cur_id%0A%0A    def get_needaction_user_ids(self, cr, uid, ids, context=None):%0A        result = dict.fromkeys(ids)%0A        # retrieve users from accounts creators group which comes from related module data%0A        obj = self.pool.get('ir.model.data')%0A        followers = obj.get_object(cr, uid, 'mail.message.group', 'group_account_creators').member_ids%0A        for partner in self.browse(cr, uid, ids, context=context):%0A        # set the list void by default%0A            result%5Bpartner.id%5D = %5B%5D%0A            # if partner is not correctly set: manager is required to perform an action%0A            if self._check_supplier_account(cr, uid, partner, context=context) or self._check_customer_account(cr, uid, partner, context=context):%0A                result%5Bpartner.id%5D = %5Bfollowers%5D%0A        return result

manage needaction post message subtype on create