def migrate_projects_to_multiple_clients(): """ move project's client to the manytomany relationship """ from autonomie.models.client import Client for proj in DBSESSION().query(Project): try: client = Client.get(proj.client_id) if client is not None: proj.clients.append(client) DBSESSION().merge(proj) except: continue
def upgrade(): from autonomie.models.client import Client for table in ("estimation", "invoice", "cancelinvoice"): op.add_column(table, sa.Column("address", sa.Text, default="")) op.add_column( table, sa.Column("client_id", sa.Integer, sa.ForeignKey("customer.id"))) for obj in (Invoice, CancelInvoice, Estimation): for doc in obj.query(): if doc.project is not None and doc.project.client_id is not None: client = Client.get(doc.project.client_id) if client is not None: doc.address = client.full_address doc.client_id = client.id if len(doc._number) > 10: doc._number = doc._number[10:] DBSESSION.merge(doc)
def upgrade(): from autonomie.models.client import Client for table in ("estimation", "invoice", "cancelinvoice"): op.add_column(table, sa.Column("address", sa.Text, default="")) op.add_column(table, sa.Column("client_id", sa.Integer, sa.ForeignKey("customer.id"))) for obj in (Invoice, CancelInvoice, Estimation): for doc in obj.query(): if doc.project is not None and doc.project.client_id is not None: client = Client.get(doc.project.client_id) if client is not None: doc.address = client.full_address doc.client_id = client.id if len(doc._number) > 10: doc._number = doc._number[10:] DBSESSION.merge(doc)