~akretion-team/openobject-extension/openobject-extension-abstract-automatic-task

« back to all changes in this revision

Viewing changes to base_onchange_player/onchange_osv.py

  • Committer: Sébastien Beau
  • Date: 2012-12-07 13:12:37 UTC
  • mfrom: (376.1.35 openobject-extension)
  • Revision ID: sebastien.beau@akretion.com-20121207131237-1u9znrzxdcc161ha
[MERGE] merge from cleanning branch : please do not forget to start an update on the module updated.
base_external_referential :
    REFACTOR
        - redesign the view and for commun fields between various e-commerce the visibility can be set withthe variable REF_VISIBLE_FIELD
        ex : REF_VISIBLE_FIELDS['Magento'] = ['location', 'apiusername', 'apipass']

    FIX
        - fix copy method on mapping
        - fix export resource when ids an empty tuple or an empty list
        - increase the size of the field action on the report line to avoid error
        - FIX Call the onchange correctly using args and kwargs

    ADD
        - add the type url in the mapping
        - improve reporting system, avoid the creation of unlimited error message on some object
        - add the posibility to send an email when an error occure


file_exchange / base_file_protocol:
    ADD
        - add support of xls

base_external_file_protocole 
    REFACTOR
        - improve file.buffer (need for amazon)

report_syncronizer
    REFACTOR
        - refactor the export of file (needed for exporting OpenERP PDf into magento)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
################################################################################
3
3
#                                                                              #
4
4
#    base_onchange_player for OpenERP                                          #
5
 
#    Copyright (C) 2011 Akretion Sébastien BEAU <sebastien.beau@akretion.com>  #
 
5
#    Copyright (C) 2011 Akretion http://www.akretion.com/                      #
 
6
#    @author Sébastien BEAU <sebastien.beau@akretion.com>                      #
6
7
#                                                                              #
7
8
#    This program is free software: you can redistribute it and/or modify      #
8
9
#    it under the terms of the GNU Affero General Public License as            #
19
20
#                                                                              #
20
21
################################################################################
21
22
 
22
 
from osv import osv
23
 
import netsvc
 
23
from openerp.osv.orm import Model
 
24
from openerp.osv.osv import except_osv
24
25
from tools.translate import _
25
26
from openerp.tools.config import config
26
27
 
27
28
def call_onchange(self, cr, uid, onchange_name, vals, defaults=None, **kwargs):
28
29
    """
29
 
    Used in base_sale_multichannel in order to call onchange method on sale_order_line and sale_order
30
 
    In order to call onchange you must have to create a function "_get_kwargs_my_onchange_name"
31
 
    that will return the kwargs for your onchange
 
30
    Used in base_sale_multichannel in order to call onchange method on sale_order_line and sale_order.
 
31
    In order to call onchange, you must have to create a function "_get_kwargs_my_onchange_name"
 
32
    that will return the kwargs for your onchange.
32
33
 
33
 
    @param onchange_name: string that contain the onchange method to call
34
 
    @param vals: dictionnary of value that have been filled for the object
 
34
    @param onchange_name: string that contains the onchange method to call
 
35
    @param vals: dictionnary of values that has been filled for the object
35
36
    @param defaults: dictionnary of defaults values for the object
36
 
    @return: dictionary of line updated with the value returned by the onchange
 
37
    @return: dictionary of lines updated with the values returned by the onchange
37
38
    """
38
 
    if not defaults:
39
 
        defaults={}
 
39
    if defaults is None:
 
40
        defaults = {}
40
41
    vals_with_default = defaults.copy()
41
42
    vals_with_default.update(vals)
42
43
    try :
43
 
        kwargs2 = eval("self._get_kwargs_%s"%onchange_name)(cr, uid, vals_with_default, **kwargs)
 
44
        args2, kwargs2 = getattr(self, "_get_params_%s" % onchange_name)(cr, uid, vals_with_default, **kwargs)
44
45
    except Exception, e:
45
46
        if config['debug_mode']: raise
46
 
        raise osv.except_osv(_('On Change Player'), _("Error when trying to get the kwargs for the onchange %s on \
47
 
                                                    the object %s. Error message : %s" %(onchange_name, self._name, e)))
 
47
        raise except_osv(_('On Change Player'),
 
48
                         _("Error when trying to get the params for the onchange %s on "
 
49
                           "the object %s. Error message : %s") % (onchange_name, self._name, e))
48
50
    try :
49
 
        res = eval("self.%s"%onchange_name)(cr, uid, **kwargs2)
 
51
        res = getattr(self, onchange_name)(cr, uid, *args2, **kwargs2)
50
52
        for key in res['value']:
51
53
            if not key in vals:
52
 
                # If the value is false and the field is not a boolean we don't pass it as it useless
53
 
                # If it's a problem for you please contact me sebastien.beau@akretion.com, 
54
 
                # because pass empty value will provoque some conflict with magentoerpconnect. Thanks
 
54
                # If the value is false and the field is not a boolean, we don't pass it as it is useless
 
55
                # If it's a problem for you, please contact me sebastien.beau@akretion.com,
 
56
                # because passing empty value will trigger a conflict with magentoerpconnect. Thanks.
55
57
                if res['value'][key] or self._columns[key]._type == 'bool':
56
58
                    vals[key] = res['value'][key]
57
59
    except Exception, e:
58
60
        if config['debug_mode']: raise
59
 
        raise osv.except_osv(_('On Change Player'), _("Error when trying to playing the onchange %s on the object %s. \
60
 
                                                                Error message : %s" %(onchange_name, self._name, e)))
 
61
        raise except_osv(_('On Change Player'),
 
62
                         _("Error when trying to play the onchange %s on the object %s. "
 
63
                           "Error message : %s") % (onchange_name, self._name, e))
61
64
    return vals
62
65
 
63
 
osv.osv.call_onchange = call_onchange
 
66
Model.call_onchange = call_onchange