~ubuntu-branches/ubuntu/vivid/tryton-modules-company/vivid

« back to all changes in this revision

Viewing changes to company.py

  • Committer: Package Import Robot
  • Author(s): Mathias Behrle
  • Date: 2011-12-26 13:55:02 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20111226135502-8gvxed8jg0dy3bec
Tags: 2.2.1-1
* Merging upstream version 2.2.1.
* Bumping X-Python-Version to >=2.6.
* Updating versioned tryton depends to 2.2.
* Merging upstream version 2.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#This file is part of Tryton.  The COPYRIGHT file at the top level of
2
2
#this repository contains the full copyright notices and license terms.
3
 
from __future__ import with_statement
4
3
import copy
5
4
from trytond.model import ModelView, ModelSQL, fields
6
5
from trytond.wizard import Wizard
7
6
from trytond.report import Report
8
 
from trytond.pyson import Eval, If, In, Get
 
7
from trytond.pyson import Eval, If
9
8
from trytond.transaction import Transaction
 
9
from trytond.pool import Pool
10
10
 
11
11
 
12
12
class Company(ModelSQL, ModelView):
34
34
        })
35
35
 
36
36
    def copy(self, ids, default=None):
37
 
        party_obj = self.pool.get('party.party')
 
37
        party_obj = Pool().get('party.party')
38
38
 
39
39
        int_id = False
40
40
        if isinstance(ids, (int, long)):
56
56
    def write(self, ids, vals):
57
57
        res = super(Company, self).write(ids, vals)
58
58
        # Restart the cache on the domain_get method
59
 
        self.pool.get('ir.rule').domain_get.reset()
 
59
        Pool().get('ir.rule').domain_get.reset()
60
60
        return res
61
61
 
62
62
Company()
84
84
    companies = fields.Function(fields.One2Many('company.company', None,
85
85
        'Current Companies'), 'get_companies')
86
86
    employee = fields.Many2One('company.employee', 'Employee',
87
 
            domain=[('company', 'child_of', [Eval('main_company')], 'parent')])
 
87
        domain=[('company', 'child_of', [Eval('main_company')], 'parent')],
 
88
        depends=['main_company'])
88
89
 
89
90
    def __init__(self):
90
91
        super(User, self).__init__()
104
105
        return self.default_main_company()
105
106
 
106
107
    def get_companies(self, ids, name):
107
 
        company_obj = self.pool.get('company.company')
 
108
        company_obj = Pool().get('company.company')
108
109
        res = {}
109
110
        company_childs = {}
110
111
        for user in self.browse(ids):
130
131
        res = super(User, self).get_status_bar(ids, name)
131
132
        for user in self.browse(ids):
132
133
            if user.company:
133
 
                res[user.id] += ' ' + user.company.name
 
134
                res[user.id] += ' - %s [%s]' % (user.company.name,
 
135
                    user.company.currency.name)
134
136
        return res
135
137
 
136
138
    def on_change_main_company(self, vals):
137
139
        return {'company': vals.get('main_company', False)}
138
140
 
139
141
    def check_company(self, ids):
140
 
        company_obj = self.pool.get('company.company')
 
142
        company_obj = Pool().get('company.company')
141
143
        for user in self.browse(ids):
142
144
            if user.main_company:
143
145
                companies = company_obj.search([
159
161
        return res
160
162
 
161
163
    def get_preferences_fields_view(self):
162
 
        company_obj = self.pool.get('company.company')
 
164
        company_obj = Pool().get('company.company')
163
165
 
164
166
        user = self.browse(Transaction().user)
165
167
 
167
169
        res = copy.deepcopy(res)
168
170
        return res
169
171
 
 
172
    def read(self, ids, fields_names=None):
 
173
        company_obj = Pool().get('company.company')
 
174
        user_id = Transaction().user
 
175
        if user_id == 0 and 'user' in Transaction().context:
 
176
            user_id = Transaction().context['user']
 
177
        result = super(User, self).read(ids, fields_names=fields_names)
 
178
        if (fields_names
 
179
                and 'company' in fields_names
 
180
                and 'company' in Transaction().context):
 
181
            values = None
 
182
            if isinstance(ids, (int, long)):
 
183
                if int(user_id) == ids:
 
184
                    values = result
 
185
            else:
 
186
                if int(user_id) in ids:
 
187
                    for vals in result:
 
188
                        if vals['id'] == int(user_id):
 
189
                            values = vals
 
190
                            break
 
191
            if values:
 
192
                main_company_id = values.get('main_company')
 
193
                if not main_company_id:
 
194
                    main_company_id = self.read(user_id,
 
195
                        ['main_company'])['main_company']
 
196
                companies = company_obj.search([
 
197
                    ('parent', 'child_of', [main_company_id]),
 
198
                ])
 
199
                company_id = Transaction().context['company']
 
200
                if ((company_id and company_id in companies)
 
201
                        or not company_id):
 
202
                    values['company'] = company_id
 
203
        return result
 
204
 
170
205
User()
171
206
 
172
207
 
173
208
class Property(ModelSQL, ModelView):
174
209
    _name = 'ir.property'
175
210
    company = fields.Many2One('company.company', 'Company',
176
 
            domain=[
177
 
                ('id', If(In('company', Eval('context', {})), '=', '!='),
178
 
                    Get(Eval('context', {}), 'company', 0)),
 
211
        domain=[
 
212
            ('id', If(Eval('context', {}).contains('company'), '=', '!='),
 
213
                Eval('context', {}).get('company', 0)),
179
214
            ])
180
215
 
181
216
    def _set_values(self, name, model, res_id, val, field_id):
182
 
        user_obj = self.pool.get('res.user')
 
217
        user_obj = Pool().get('res.user')
183
218
        user_id = Transaction().user
184
219
        if user_id == 0:
185
220
            user_id = Transaction().context.get('user', user_id)
202
237
class Sequence(ModelSQL, ModelView):
203
238
    _name = 'ir.sequence'
204
239
    company = fields.Many2One('company.company', 'Company',
205
 
            domain=[
206
 
                ('id', If(In('company', Eval('context', {})), '=', '!='),
207
 
                    Get(Eval('context', {}), 'company', 0)),
 
240
        domain=[
 
241
            ('id', If(Eval('context', {}).contains('company'), '=', '!='),
 
242
                Eval('context', {}).get('company', 0)),
208
243
            ])
209
244
 
210
245
    def __init__(self):
265
300
    }
266
301
 
267
302
    def _add(self, data):
268
 
        company_obj = self.pool.get('company.company')
269
 
        user_obj = self.pool.get('res.user')
 
303
        company_obj = Pool().get('company.company')
 
304
        user_obj = Pool().get('res.user')
270
305
 
271
306
        company_id = company_obj.create(data['form'])
272
307
        user_ids = user_obj.search([
284
319
class CompanyReport(Report):
285
320
 
286
321
    def parse(self, report, objects, datas, localcontext=None):
287
 
        user = self.pool.get('res.user').browse(Transaction().user)
 
322
        user = Pool().get('res.user').browse(Transaction().user)
288
323
        if localcontext is None:
289
324
            localcontext = {}
290
325
        localcontext['company'] = user.company