~unifield-team/unifield-wm/us-826

1384.1.4 by Olivier DOSSMANN
UF-1701 [FIX] Problem @save of FO for partner type
1
# -*- coding: utf-8 -*-
2
##############################################################################
3
#
4
#    Copyright (C) 2011 MSF, TeMPO Consulting
5
#
6
#    This program is free software: you can redistribute it and/or modify
7
#    it under the terms of the GNU Affero General Public License as
8
#    published by the Free Software Foundation, either version 3 of the
9
#    License, or (at your option) any later version.
10
#
11
#    This program is distributed in the hope that it will be useful,
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
#    GNU Affero General Public License for more details.
15
#
16
#    You should have received a copy of the GNU Affero General Public License
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
#
19
##############################################################################
20
21
from osv import osv
22
from osv import fields
23
from tools.translate import _
24
25
class res_partner(osv.osv):
26
    _name = 'res.partner'
27
    _inherit = 'res.partner'
28
29
    def _get_fake(self, cr, uid, ids, fields, arg, context=None):
30
        """
31
        Fake method for 'check_partner_so' field.
32
        """
33
        if isinstance(ids, (int, long)):
34
            ids = [ids]
35
        result = {}
36
        for id in ids:
37
            result[id] = False
38
        return result
39
40
    def _check_partner_type_so(self, cr, uid, obj, name, args, context=None):
41
        """
42
        Create a domain on the field partner_id
43
        """
44
        if context is None:
45
            context = {}
46
        if not args:
47
            return []
48
        newargs = []
49
        partner_obj = self.pool.get('res.partner')
50
        for arg in args:
51
            if arg[0] == 'check_partner_so':
52
                if arg[1] != '=' \
53
                or arg[2]['order_type'] not in ['regular', 'donation_exp', 'donation_st', 'loan', 'in_kind', 'purchase_list', 'direct']\
54
                or not isinstance(arg[2]['partner_id'], (int, long)):
55
                    raise osv.except_osv(_('Error'), _('Filter check_partner_so different than (arg[0], =, %s) not implemented.') % arg[2])
56
                partner_id = arg[2]['partner_id']
57
                order_type = arg[2]['order_type']
58
                p_list = []
1864.8.1 by duy.vo at msf
UTP-952: Restriction of partner intersection for Regular FO
59
                if order_type in ['regular']:
60
                    p_list = ['internal', 'intermission', 'external'] # UTP-953: Cannot create an FO regular for Intersection due to the Push Flow sync
61
                elif order_type in ['donation_st', 'loan']:
1901 by jf
UTP-952 UTP-953 [FIX] small fixes
62
                    p_list = ['internal', 'intermission', 'section', 'external']
1384.1.4 by Olivier DOSSMANN
UF-1701 [FIX] Problem @save of FO for partner type
63
                elif order_type in ['direct', 'in_kind']:
64
                    p_list = ['internal', 'intermission', 'section', 'esc', 'external']
65
                elif order_type in ['donation_exp']:
66
                    p_list = ['internal', 'intermission', 'section']
67
                # show all supplier for non taken cases
68
                else:
69
                    pass
70
                if p_list:
71
                    newargs.append(('partner_type', 'in', p_list))
72
            else:
73
                newargs.append(args)
74
        return newargs
75
1453.12.1 by pma at tempo-consulting
Possibility to source a FO with a sync. partner
76
    def _search_partner_not_int(self, cr, uid, obj, name, args, context=None):
77
        dom = []
78
        for arg in args:
1508 by jf
UF-1838 [FIX] Possibility to source a FO with a sync. partner
79
            if not isinstance(arg[2], dict) or not arg[2].get('ids') or not arg[2].get('ids')[0]:
1453.12.1 by pma at tempo-consulting
Possibility to source a FO with a sync. partner
80
                return dom
1453.12.2 by pma at tempo-consulting
Possibility to source a FO with a sync. partner
81
            if arg[2]['type'] == 'po':
82
                for po in self.pool.get('purchase.order').browse(cr, uid, arg[2]['ids'], context=context):
83
                    if po.po_from_fo:
1453.12.5 by pma at tempo-consulting
Add section and intermission in filter
84
                        dom.append(('partner_type', 'not in', ['internal','section','intermission']))
1453.12.2 by pma at tempo-consulting
Possibility to source a FO with a sync. partner
85
            else:
1508 by jf
UF-1838 [FIX] Possibility to source a FO with a sync. partner
86
                for tender in self.pool.get('tender').browse(cr, uid, arg[2]['ids'], context=context):
1453.12.3 by pma at tempo-consulting
Correction bug
87
                    if tender.tender_from_fo:
1453.12.5 by pma at tempo-consulting
Add section and intermission in filter
88
                        dom.append(('partner_type', 'not in', ['internal','section','intermission']))
1453.12.1 by pma at tempo-consulting
Possibility to source a FO with a sync. partner
89
        return dom
90
1384.1.4 by Olivier DOSSMANN
UF-1701 [FIX] Problem @save of FO for partner type
91
    _columns = {
92
        'check_partner_so': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type On SO', fnct_search=_check_partner_type_so),
1453.12.3 by pma at tempo-consulting
Correction bug
93
        'partner_not_int': fields.function(_get_fake, method=True, type='boolean', string='Is PO/Tender from FO ?', fnct_search=_search_partner_not_int),
1384.1.4 by Olivier DOSSMANN
UF-1701 [FIX] Problem @save of FO for partner type
94
    }
95
96
res_partner()
97
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: