diff --git a/COPYRIGHT b/COPYRIGHT index 37fef2d645..d622f061f5 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -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 diff --git a/__init__.py b/__init__.py index 8ed349062f..e4fd59e2f9 100644 --- a/__init__.py +++ b/__init__.py @@ -4,3 +4,4 @@ from category import * from party import * from address import * +from contact_mechanism import * diff --git a/__tryton__.py b/__tryton__.py index 5499c0ff7e..a71e86bbf5 100644 --- a/__tryton__.py +++ b/__tryton__.py @@ -17,6 +17,7 @@ "party.xml", "category.xml", "address.xml", + "contact_mechanism.xml", ], 'translation': [ 'fr_FR.csv', diff --git a/category.xml b/category.xml index 1c82c00a0f..77e5c401bb 100644 --- a/category.xml +++ b/category.xml @@ -25,7 +25,7 @@ this repository contains the full copyright notices and license terms. --> childs + diff --git a/contact_mechanism.py b/contact_mechanism.py new file mode 100644 index 0000000000..0266539720 --- /dev/null +++ b/contact_mechanism.py @@ -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() diff --git a/contact_mechanism.xml b/contact_mechanism.xml new file mode 100644 index 0000000000..05e50bc731 --- /dev/null +++ b/contact_mechanism.xml @@ -0,0 +1,54 @@ + + + + + + + party.contact_mechanism + tree + + + + + + + + ]]> + + + + + party.contact_mechanism + form + + + + + + diff --git a/party.py b/party.py index 781976a44c..2c7f3f9abd 100644 --- a/party.py +++ b/party.py @@ -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'): diff --git a/party.xml b/party.xml index e9065ca724..a376572018 100644 --- a/party.xml +++ b/party.xml @@ -45,7 +45,8 @@ this repository contains the full copyright notices and license terms. --> - + @@ -56,10 +57,22 @@ this repository contains the full copyright notices and license terms. --> -