commit 9879e89353822a18cf54a899adcdc36479507d0d Author: Cédric Krier Date: Tue Feb 19 14:58:52 2008 +0100 Initial commit diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000000..bd5dd69dc2 --- /dev/null +++ b/__init__.py @@ -0,0 +1,26 @@ +# Copyright (c) 2007 Cedric Krier. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contact a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +from company import * diff --git a/__tryton__.py b/__tryton__.py new file mode 100644 index 0000000000..02e4e39d10 --- /dev/null +++ b/__tryton__.py @@ -0,0 +1,9 @@ +{ + 'name': 'Company', + 'version': '0.1', + 'author': 'B2CK', + 'category': 'Generic Modules', + 'description': 'Define company', + 'depends': ['ir', 'res', 'partner'], + 'xml': ['company.xml'], +} diff --git a/company.py b/company.py new file mode 100644 index 0000000000..b88b7f5e86 --- /dev/null +++ b/company.py @@ -0,0 +1,91 @@ +"Company" + +from trytond.osv import fields, OSV + + +class Company(OSV): + 'Company' + + _name = 'company.company' + _description = __doc__ + _columns = { + 'name': fields.Char('Name', size=128, required=True), + 'partner':fields.Many2One('partner.partner', 'Partner', required=True), + 'parent': fields.Many2One('company.company', 'Parent'), + 'childs': fields.One2Many('company.company', 'parent', 'Childs'), + } + _constraints = [ + ('check_recursion', + 'Error! You can not create recursive companies.', ['parent']), + ] + + def write(self, cursor, user, ids, vals, context=None): + res = super(Company, self).write(cursor, user, ids, vals, + context=context) + # Restart the cache on the domain_get method + self.pool.get('ir.rule').domain_get() + return res + +Company() + + +class User(OSV): + _name = 'res.user' + + def __init__(self, pool): + super(User, self).__init__(pool) + if pool: + self._columns['main_company'] = fields.Many2One('company.company', + 'Main Company') + self._columns['company'] = fields.Many2One('company.company', + 'Current Company', + domain="[('parent', 'child_of', [main_company])]") + self._context_fields = self._context_fields + ['company'] + self._constraints = self._constraints + [ + ('check_company', + 'Error! You can not set a company that is not ' \ + 'a child of your mani company.', ['company']), + ] + + def check_company(self, cursor, user, ids): + company_obj = self.pool.get('company.company') + for user in self.browse(cursor, user, ids): + companies = company_obj.search(cursor, user, [ + ('parent', 'child_of', [user.main_company]), + ], context=context) + if user.company.id not in companies: + return False + return True + + def get_preferences_fields_view(self, cursor, user, context=None): + res = super(User, self).get_preferences_fields_view(cursor, user, + context=context) + fields = self.fields_get(cursor, user, fields_names=['main_company'], + context=context) + res['fields'].update(fields) + return res + +User() + + +class Property(OSV): + _name = 'ir.property' + + def __init__(self, pool): + super(Property, self).__init__(pool) + if pool: + self._columns['company'] = fields.Many2One('company.company', + 'Company') + + def set(self, cursor, user, name, model, res_id, val, context=None): + res = super(Property, self).set(cursor, user, name, model, res_id, val, + context=context) + if res: + user_obj = self.pool.get('res.user') + company = user_obj.browse(cursor, user, user, context=context) + self.write(cursor, user, { + 'company': company.id, + }, context=context) + return res + +Property() diff --git a/company.xml b/company.xml new file mode 100644 index 0000000000..1b15034ff0 --- /dev/null +++ b/company.xml @@ -0,0 +1,120 @@ + + + + + company.company + form + + + + + company.company + tree + childs + + + + + + ]]> + + + + Companies + ir.action.act_window + company.company + tree + [('parent', '=', False)] + + + + + + + + + Companies + ir.action.act_window + company.company + form + + + + + + + + + + + + + + res.user + + + + + + + ]]> + + + + ir.property + + + + + + + ]]> + + + + ir.property + + + + + + + + ]]> + + + +