Add contact mechanism

This commit is contained in:
Cédric Krier committed 2008-10-23 13:41:06 +02:00
1 parent 789d87f9de
commit 5cefd14d55
8 files changed
+239 -7

No files matched your search

+3
View File
@@ -2,6 +2,9 @@ Copyright (C) 2004-2008 Tiny SPRL.
Copyright (C) 2008 Cédric Krier.
Copyright (C) 2008 Bertrand Chenal.
Copyright (C) 2008 B2CK SPRL.
Copyright (C) 2008 Udo Spallek.
Copyright (C) 2008 Korbinian Preisler.
Copyright (C) 2008 virtual things.
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
+1
View File
@@ -4,3 +4,4 @@
from category import *
from party import *
from address import *
from contact_mechanism import *
+1
View File
@@ -17,6 +17,7 @@
"party.xml",
"category.xml",
"address.xml",
"contact_mechanism.xml",
],
'translation': [
'fr_FR.csv',
+1 -1
View File
@@ -25,7 +25,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="field_childs">childs</field>
<field name="arch" type="xml">
<![CDATA[
<tree string="Categories">
<tree string="Categories" fill="1">
<field name="name" select="1"/>
<field name="active" select="2" tree_invisible="1"/>
</tree>
+137
View File
@@ -0,0 +1,137 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from trytond.osv import OSV, fields
STATES = {
'readonly': "active == False",
}
_TYPES = [
('phone', 'Phone'),
('mobile', 'Mobile'),
('fax', 'Fax'),
('email', 'E-Mail'),
('website', 'Website'),
('skype', 'Skype'),
('sip', 'SIP'),
('irc', 'IRC'),
('jabber', 'Jabber'),
('other', 'Other'),
]
class ContactMechanism(OSV):
"Contact Mechanism"
_name = "party.contact_mechanism"
_description = __doc__
_rec_name = 'value'
type = fields.Selection(_TYPES, 'Type', required=True, states=STATES,
sort=False)
value = fields.Char('Value', select=1,
states={
'invisible': "type in ('email', 'website')",
'required': "type not in ('email', 'website')",
'readonly': "active == False",
}, on_change=['value'])
comment = fields.Text('Comment', states=STATES)
party = fields.Many2One('party.party', 'Party', required=True,
ondelete='CASCADE', states=STATES, select=1)
active = fields.Boolean('Active', select=1)
sequence = fields.Integer('Sequence')
email = fields.Function('get_value', fnct_inv='set_value', type='char',
string="E-Mail", states={
'invisible': "type != 'email'",
'required': "type == 'email'",
'readonly': "active == False",
}, on_change=['email'])
website = fields.Function('get_value', fnct_inv='set_value', type='char',
string="Website", states={
'invisible': "type != 'website'",
'required': "type == 'website'",
'readonly': "active == False",
}, on_change=['website'])
skype = fields.Function('get_value', fnct_inv='set_value', type='char',
string="Skype", states={
'invisible': "type != 'skype'",
'required': "type == 'skype'",
'readonly': "active == False",
}, on_change=['skype'])
sip = fields.Function('get_value', fnct_inv='set_value', type='char',
string="SIP", states={
'invisible': "type != 'sip'",
'required': "type == 'sip'",
'readonly': "active == False",
}, on_change=['sip'])
def __init__(self):
super(ContactMechanism, self).__init__()
self._order.insert(0, ('party', 'ASC'))
self._order.insert(1, ('sequence', 'ASC'))
self._error_messages.update({
'write_party': 'You can not modify the party of ' \
'an contact mechanism!',
})
def default_type(self, cursor, user, context=None):
return 'phone'
def default_active(self, cursor, user, context=None):
return True
def get_value(self, cursor, user, ids, names, arg, context=None):
res = {}
for name in names:
res[name] = {}
for mechanism in self.browse(cursor, user, ids, context=context):
for name in names:
res[name][mechanism.id] = mechanism.value
return res
def set_value(self, cursor, user, obj_id, name, value, arg, context=None):
self.write(cursor, user, obj_id, {
'value': value,
}, context=context)
def _change_value(self, cursor, user, value, context=None):
return {
'value': value,
'website': value,
'email': value,
'skype': value,
'sip': value,
}
def on_change_value(self, cursor, user, ids, vals, context=None):
return self._change_value(cursor, user, vals.get('value'),
context=context)
def on_change_website(self, cursor, user, ids, vals, context=None):
return self._change_value(cursor, user, vals.get('website'),
context=context)
def on_change_email(self, cursor, user, ids, vals, context=None):
return self._change_value(cursor, user, vals.get('email'),
context=context)
def on_change_skype(self, cursor, user, ids, vals, context=None):
return self._change_value(cursor, user, vals.get('skype'),
context=context)
def on_change_sip(self, cursor, user, ids, vals, context=None):
return self._change_value(cursor, user, vals.get('sip'),
context=context)
def write(self, cursor, user, ids, vals, context=None):
if 'party' in vals:
if isinstance(ids, (int, long)):
ids = [ids]
for mechanism in self.browse(cursor, user, ids, context=context):
if mechanism.party.id != vals['party']:
self.raise_user_error(cursor, 'write_party',
context=context)
return super(ContactMechanism, self).write(cursor, user, ids, vals,
context=context)
ContactMechanism()
+54
View File
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="contact_mechanism_view_tree">
<field name="model">party.contact_mechanism</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<![CDATA[
<tree string="Contact Mechanisms">
<field name="party" select="1"/>
<field name="type" select="1"/>
<field name="value" select="1"/>
<field name="active" select="2" tree_invisible="1"/>
</tree>
]]>
</field>
</record>
<record model="ir.ui.view" id="contact_mechanism_view_form">
<field name="model">party.contact_mechanism</field>
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="Contact Mechanism">
<label name="party"/>
<field name="party"/>
<label name="active"/>
<field name="active"/>
<label name="type"/>
<field name="type"/>
<group col="2" colspan="2">
<label name="value"/>
<field name="value"/>
<label name="website"/>
<field name="website" widget="url"/>
<label name="email"/>
<field name="email" widget="email"/>
<label name="skype"/>
<field name="skype" widget="callto"/>
<label name="sip"/>
<field name="sip" widget="sip"/>
</group>
<separator name="comment" colspan="4"/>
<field name="comment" colspan="4"/>
</form>
]]>
</field>
</record>
</data>
</tryton>
+24 -1
View File
@@ -37,13 +37,25 @@ class Party(OSV):
help="Setting VAT country will enable verification of the VAT number.")
vat_code = fields.Function('get_vat_code', type='char', string="VAT Code")
addresses = fields.One2Many('party.address', 'party',
'Addresses',states=STATES)
'Addresses', states=STATES)
contact_mechanisms = fields.One2Many('party.contact_mechanism', 'party',
'Contact Mechanisms', states=STATES)
categories = fields.Many2Many(
'party.category', 'party_category_rel',
'party', 'category', 'Categories',
states=STATES)
active = fields.Boolean('Active', select=1)
full_name = fields.Function('get_full_name', type='char')
phone = fields.Function('get_mechanism', arg='phone', type='char',
string='Phone')
mobile = fields.Function('get_mechanism', arg='mobile', type='char',
string='Mobile')
fax = fields.Function('get_mechanism', arg='fax', type='char',
string='Fax')
email = fields.Function('get_mechanism', arg='email', type='char',
string='E-Mail')
website = fields.Function('get_mechanism', arg='website', type='char',
string='Website')
def __init__(self):
super(Party, self).__init__()
@@ -78,6 +90,17 @@ class Party(OSV):
res[party.id] = party.name
return res
def get_mechanism(self, cursor, user, ids, name, arg, context=None):
if not ids:
return []
res = {}
for party in self.browse(cursor, user, ids, context=context):
res[party.id] = ''
for mechanism in party.contact_mechanisms:
if mechanism.type == arg:
res[party.id] = mechanism.value
return res
def create(self, cursor, user, values, context=None):
values = values.copy()
if not values.get('code'):
+18 -5
View File
@@ -45,7 +45,8 @@ this repository contains the full copyright notices and license terms. -->
<notebook colspan="6">
<page string="General">
<field name="addresses" mode="form,tree" colspan="4">
<tree string="Addresses" sequence="sequence">
<tree string="Addresses" sequence="sequence"
fill="1">
<field name="sequence" tree_invisible="1"/>
<field name="name"/>
<field name="street"/>
@@ -56,10 +57,22 @@ this repository contains the full copyright notices and license terms. -->
<field name="subdivision"/>
</tree>
</field>
<label name="lang"/>
<field name="lang" widget="selection"/>
<separator string="Categories" colspan="4"/>
<field name="categories" colspan="4"/>
<group col="2" colspan="4">
<label name="lang"/>
<field name="lang" widget="selection"/>
</group>
<field name="contact_mechanisms" colspan="2">
<tree string="Contact Mechanisms" sequence="sequence"
fill="1">
<field name="sequence" tree_invisible="1"/>
<field name="type"/>
<field name="value"/>
</tree>
</field>
<group col="1" colspan="2">
<separator string="Categories"/>
<field name="categories"/>
</group>
</page>
<page string="Accounting">
<label name="vat_country"/>