Update reverse definition when defining a reverse type

This commit is contained in:
Sergi Almacellas Abellana 2013-10-31 09:37:09 +01:00
parent 4c029cd83a
commit 34fb1473b1

View file

@ -3,6 +3,7 @@ from sql import Union, As
from trytond.pool import Pool, PoolMeta
from trytond.model import ModelSQL, ModelView, fields
from trytond.pyson import Eval
from trytond.transaction import Transaction
__all__ = ['RelationType', 'PartyRelation', 'PartyRelationAll', 'Party']
__metaclass__ = PoolMeta
@ -24,6 +25,28 @@ class RelationType(ModelSQL, ModelView):
'Relation Type cannot be linked to itself.'),
]
@classmethod
def create(cls, vlist):
types = super(RelationType, cls).create(vlist)
for type_ in types:
reverse = type_.reverse
if reverse:
reverse.reverse = type_
reverse.save()
return types
@classmethod
def write(cls, types, values):
transaction = Transaction()
context = transaction.context
super(RelationType, cls).write(types, values)
if 'reverse' in values and not context.get('write_reverse', False):
with transaction.set_context(write_reverse=True):
reverse = cls(values['reverse'])
for type_ in types:
reverse.reverse = type_
reverse.save()
class PartyRelation(ModelSQL):
'Party Relation'