Initial commit

This commit is contained in:
Cédric Krier committed 2008-02-19 14:58:52 +01:00
commit 9879e89353
4 files changed
+246

No files matched your search

+26
View File
@@ -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 *
+9
View File
@@ -0,0 +1,9 @@
{
'name': 'Company',
'version': '0.1',
'author': 'B2CK',
'category': 'Generic Modules',
'description': 'Define company',
'depends': ['ir', 'res', 'partner'],
'xml': ['company.xml'],
}
+91
View File
@@ -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()
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0"?>
<tryton>
<data>
<record model="ir.ui.view" id="company_view_form">
<field name="model">company.company</field>
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="Company">
<label name="name"/>
<field name="name" colspan="3"/>
<label name="partner"/>
<field name="partner"/>
<label name="parent"/>
<field name="parent"/>
<separator name="childs" colspan="4"/>
<field name="childs" colspan="4"/>
</form>
]]>
</field>
</record>
<record model="ir.ui.view" id="company_view_tree">
<field name="model">company.company</field>
<field name="type">tree</field>
<field name="field_childs">childs</field>
<field name="arch" type="xml">
<![CDATA[
<tree string="Companies">
<field name="name" select="1"/>
<field name="partner" select="1"/>
</tree>
]]>
</field>
</record>
<record model="ir.action.act_window" id="act_company_tree">
<field name="name">Companies</field>
<field name="type">ir.action.act_window</field>
<field name="res_model">company.company</field>
<field name="view_type">tree</field>
<field name="domain">[('parent', '=', False)]</field>
</record>
<record model="ir.action.act_window.view"
id="act_company_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="company_view_tree"/>
<field name="act_window" ref="act_company_tree"/>
</record>
<menuitem parent="partner.menu_partner" action="act_company_tree"
id="menu_company_tree"/>
<record model="ir.action.act_window" id="act_company_form">
<field name="name">Companies</field>
<field name="type">ir.action.act_window</field>
<field name="res_model">company.company</field>
<field name="view_type">form</field>
</record>
<record model="ir.action.act_window.view"
id="act_company_form_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="company_view_tree"/>
<field name="act_window" ref="act_company_form"/>
</record>
<record model="ir.action.act_window.view"
id="act_company_form_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="company_view_form"/>
<field name="act_window" ref="act_company_form"/>
</record>
<menuitem parent="menu_company_tree" action="act_company_form"
id="menu_company_form" name="Edit Companies"/>
<record model="ir.ui.view" id="user_view_form">
<field name="model">res.user</field>
<field name="inherit" ref="res.user_view_form"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/form/notebook/page/separator[@name=&quot;signature&quot;]"
position="before">
<label name="main_company"/>
<field name="main_company"/>
<label name="company"/>
<field name="company"/>
</xpath>
</data>
]]>
</field>
</record>
<record model="ir.ui.view" id="property_view_form">
<field name="model">ir.property</field>
<field name="inherit" ref="ir.property_view_form"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/form/field[@name=&quot;name&quot;]"
position="after">
<label name="company"/>
<field name="company" colspan="3"/>
</xpath>
</data>
]]>
</field>
</record>
<record model="ir.ui.view" id="property_view_tree">
<field name="model">ir.property</field>
<field name="inherit" ref="ir.property_view_tree"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/tree/field[@name=&quot;name&quot;]"
position="after">
<field name="company" select="1"/>
</xpath>
</data>
]]>
</field>
</record>
</data>
</tryton>