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

« back to all changes in this revision

Viewing changes to msf_profile/msf_profile.py

  • Committer: chloups208
  • Date: 2011-09-07 12:58:12 UTC
  • mto: (307.2.1 unifield-wm)
  • mto: This revision was merged to the branch mainline in revision 311.
  • Revision ID: chloups208@chloups208-laptop-20110907125812-dsb1jt93ae6bgfe2
[UF-390]pro forma invoice + shipment object refactoring + pack family object refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from tools.translate import _
24
24
import base64
25
25
from os.path import join as opj
26
 
from os.path import exists
27
26
import tools
28
27
 
29
28
class ir_model_data(osv.osv):
40
39
        ctx['update_mode'] = mode
41
40
        return super(ir_model_data, self)._update(cr, uid, model, module, values, xml_id, store, noupdate, mode, res_id, ctx)
42
41
 
43
 
    def patch13_install_export_import_lang(self, cr, uid, *a, **b):
44
 
        mod_obj = self.pool.get('ir.module.module')
45
 
        mod_ids = mod_obj.search(cr, uid, [('name', '=', 'export_import_lang')])
46
 
        if mod_ids and mod_obj.read(cr, uid, mod_ids, ['state'])[0]['state'] == 'uninstalled':
47
 
            mod_obj.write(cr, uid, mod_ids[0], {'state': 'to install'})
48
 
 
49
42
ir_model_data()
50
43
 
51
44
class account_installer(osv.osv_memory):
55
48
    _defaults = {
56
49
        'charts': 'msf_chart_of_account',
57
50
    }
58
 
    
59
 
    # Fix for UF-768: correcting fiscal year and name
60
 
    def execute(self, cr, uid, ids, context=None):
61
 
        super(account_installer, self).execute(cr, uid, ids, context=context)
62
 
        # Retrieve created fiscal year
63
 
        fy_obj = self.pool.get('account.fiscalyear')
64
 
        for res in self.read(cr, uid, ids, context=context):
65
 
            if 'date_start' in res and 'date_stop' in res:
66
 
                f_ids = fy_obj.search(cr, uid, [('date_start', '<=', res['date_start']), ('date_stop', '>=', res['date_stop']), ('company_id', '=', res['company_id'])], context=context)
67
 
                if len(f_ids) > 0:
68
 
                    # we have one
69
 
                    new_name = "FY " + res['date_start'][:4]
70
 
                    new_code = "FY" + res['date_start'][:4]
71
 
                    if int(res['date_start'][:4]) != int(res['date_stop'][:4]):
72
 
                        new_name = "FY " + res['date_start'][:4] +'-'+ res['date_stop'][:4]
73
 
                        new_code = "FY" + res['date_start'][2:4] +'-'+ res['date_stop'][2:4]
74
 
                    vals = {
75
 
                        'name': new_name,
76
 
                        'code': new_code,
77
 
                    }
78
 
                    fy_obj.write(cr, uid, f_ids, vals, context=context)
79
 
        return
80
51
 
81
52
account_installer()
82
53
 
96
67
        ret = super(base_setup_company, self).default_get(cr, uid, fields_list, context)
97
68
        if not ret.get('name'):
98
69
            ret.update({'name': 'MSF', 'street': 'Rue de Lausanne 78', 'street2': 'CP 116', 'city': 'Geneva', 'zip': '1211', 'phone': '+41 (22) 849.84.00'})
99
 
            company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
100
 
            ret['name'] = company.name
101
 
            addresses = self.pool.get('res.partner').address_get(cr, uid, company.id, ['default'])
102
 
            default_id = addresses.get('default', False)
103
 
            # Default address
104
 
            if default_id:
105
 
                address = self.pool.get('res.partner.address').browse(cr, uid, default_id, context=context)
106
 
                for field in ['street','street2','zip','city','email','phone']:
107
 
                    ret[field] = address[field]
108
 
                for field in ['country_id','state_id']:
109
 
                    if address[field]:
110
 
                        ret[field] = address[field].id
111
 
            # Currency
112
70
            cur = self.pool.get('res.currency').search(cr, uid, [('name','=','EUR')])
113
 
            if company.currency_id:
114
 
                ret['currency'] = company.currency_id.id
115
 
            elif cur:
 
71
            if cur:
116
72
                ret['currency'] = cur[0]
117
 
                
118
 
            fp = tools.file_open(opj('msf_profile', 'data', 'msf.jpg'), 'rb')
 
73
            country = self.pool.get('res.country').search(cr, uid, [('name','=','Switzerland')])
 
74
            if country:
 
75
                ret['country_id'] = country[0]
 
76
            fp = tools.file_open(opj('msf_profile', 'data', 'msf.jpg'))
119
77
            ret['logo'] = base64.encodestring(fp.read())
120
78
            fp.close()
121
79
        return ret
122
80
 
123
81
base_setup_company()
124
 
 
125
 
class res_users(osv.osv):
126
 
    _inherit = 'res.users'
127
 
    _name = 'res.users'
128
 
 
129
 
    def _get_default_ctx_lang(self, cr, uid, context=None):
130
 
        config_lang = self.pool.get('unifield.setup.configuration').get_config(cr, uid).lang_id
131
 
        if config_lang:
132
 
            return config_lang
133
 
        if self.pool.get('res.lang').search(cr, uid, [('translatable','=',True), ('code', '=', 'en_MF')]):
134
 
            return 'en_MF'
135
 
        return 'en_US'
136
 
 
137
 
    _defaults = {
138
 
        'context_lang': _get_default_ctx_lang,
139
 
    }
140
 
res_users()