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

« back to all changes in this revision

Viewing changes to msf_custom_settings/sale.py

  • Committer: jf
  • Date: 2012-11-29 13:00:27 UTC
  • mfrom: (1287.9.8 unifield-wm)
  • Revision ID: jfb@tempo-consulting.fr-20121129130027-564r4yns8t5d2v7d
UTP-368 [FIX] Shouldn't be possible to source a non-stockable product to stock in the order sourcing tool (fix unit test)
lp:~unifield-team/unifield-wm/utp-368

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
#-*- encoding:utf-8 -*-
3
 
##############################################################################
4
 
#
5
 
#    OpenERP, Open Source Management Solution
6
 
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
 
#    All Rigts Reserved
8
 
#    Developer: Olivier DOSSMANN
9
 
#
10
 
#    This program is free software: you can redistribute it and/or modify
11
 
#    it under the terms of the GNU Affero General Public License as
12
 
#    published by the Free Software Foundation, either version 3 of the
13
 
#    License, or (at your option) any later version.
14
 
#
15
 
#    This program is distributed in the hope that it will be useful,
16
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
#    GNU Affero General Public License for more details.
19
 
#
20
 
#    You should have received a copy of the GNU Affero General Public License
21
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
#
23
 
##############################################################################
24
 
 
25
 
from osv import osv
26
 
from tools.translate import _
27
 
 
28
 
class sale_order(osv.osv):
29
 
    _name = 'sale.order'
30
 
    _inherit = 'sale.order'
31
 
 
32
 
    def onchange_order_type(self, cr, uid, id, order_type=None, partner_id=None, context=None):
33
 
        """
34
 
        """
35
 
        res = {}
36
 
        if not order_type:
37
 
            return res
38
 
        msg = _('Partner type is not compatible with given Order Type!')
39
 
        if order_type in ['regular', 'donation_st', 'loan']:
40
 
            # Check that partner correspond
41
 
            if partner_id:
42
 
                partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
43
 
                if partner and partner.partner_type not in ['internal', 'intermission', 'section', 'external']:
44
 
                    return {'warning': {'title': _('Error'), 'message': msg}}
45
 
        elif order_type in ['donation_exp']:
46
 
            # Check that partner correspond
47
 
            if partner_id:
48
 
                partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
49
 
                if partner and partner.partner_type not in ['internal', 'intermission', 'section']:
50
 
                    return {'warning': {'title': _('Error'), 'message': msg}}
51
 
        else:
52
 
            pass
53
 
 
54
 
 
55
 
        if partner_id and order_type:
56
 
            res.update({'value': {'order_policy': 'picking'}})
57
 
            partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
58
 
            if order_type != 'regular' or (order_type == 'regular' and partner.partner_type == 'internal'):
59
 
                res.update({'value': {'order_policy': 'manual'}})
60
 
 
61
 
        return res
62
 
 
63
 
    def _check_order_type_and_partner(self, cr, uid, ids, context=None):
64
 
        """
65
 
        Check that partner and order type are compatibles
66
 
        """
67
 
        compats = {
68
 
            'regular':      ['internal', 'intermission', 'section', 'external'],
69
 
            'donation_st':  ['internal', 'intermission', 'section', 'external'],
70
 
            'loan':         ['internal', 'intermission', 'section', 'external'],
71
 
            'donation_exp': ['internal', 'intermission', 'section'],
72
 
            'in_kind':      ['internal', 'intermission', 'section', 'external', 'esc'],
73
 
            'direct':       ['internal', 'intermission', 'section', 'external', 'esc'],
74
 
        }
75
 
        # Browse SO
76
 
        for so in self.browse(cr, uid, ids):
77
 
            if so.order_type not in compats or so.partner_id.partner_type not in compats[so.order_type]:
78
 
                return False
79
 
        return True
80
 
 
81
 
    _constraints = [
82
 
       (_check_order_type_and_partner, "Partner type and order type are incompatible! Please change either order type or partner.", ['order_type', 'partner_id']),
83
 
    ]
84
 
 
85
 
sale_order()
86
 
 
87
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: