From 6626b147983082e6e801f60e1fa8946f96b440f4 2021-10-07 11:32:11 From: Lance Edgar Date: 2021-10-07 11:32:11 Subject: [PATCH] Add `contact_name` for custorder and batch so that we have something handy to easily sort/filter by etc. --- diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index a226f68114e100d3e478aed051e0618442b931fc..ab14123361c9dfa2c1db30018988ba36aa3c2cee 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -116,6 +116,9 @@ class CustomerOrderBatchHandler(BatchHandler): batch.customer = customer batch.person = person + # cache contact name + batch.contact_name = self.get_contact_display(batch) + # update phone/email per new contact batch.phone_number = None batch.email_address = None @@ -159,7 +162,12 @@ class CustomerOrderBatchHandler(BatchHandler): i.e. customer name. """ contact = self.get_contact(batch) - return six.text_type(contact) + if contact: + return six.text_type(contact) + + pending = batch.pending_customer + if pending: + return six.text_type(pending) def get_contact_phones(self, batch): """ @@ -245,6 +253,7 @@ class CustomerOrderBatchHandler(BatchHandler): """ batch.customer = None batch.person = None + batch.contact_name = None batch.phone_number = None batch.email_address = None diff --git a/rattail/db/alembic/versions/c10adeff4117_add_custorder_contact_name.py b/rattail/db/alembic/versions/c10adeff4117_add_custorder_contact_name.py new file mode 100644 index 0000000000000000000000000000000000000000..c01ec4f8638153ff156b2c2cf37ae714d33da8f1 --- /dev/null +++ b/rattail/db/alembic/versions/c10adeff4117_add_custorder_contact_name.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8; -*- +"""add custorder.contact_name + +Revision ID: c10adeff4117 +Revises: 5a256a77e6d0 +Create Date: 2021-10-07 11:05:10.561894 + +""" + +from __future__ import unicode_literals, absolute_import + +# revision identifiers, used by Alembic. +revision = 'c10adeff4117' +down_revision = u'5a256a77e6d0' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa +import rattail.db.types + + + +def upgrade(): + + # batch_custorder + op.add_column('batch_custorder', sa.Column('contact_name', sa.String(length=100), nullable=True)) + + # custorder + op.add_column('custorder', sa.Column('contact_name', sa.String(length=100), nullable=True)) + + +def downgrade(): + + # custorder + op.drop_column('custorder', 'contact_name') + + # batch_custorder + op.drop_column('batch_custorder', 'contact_name') diff --git a/rattail/db/model/custorders.py b/rattail/db/model/custorders.py index be137cbffbab3d2fbf92a2ed724363e3b1689397..fc9cbb647be446229afdc7a4f4a903c89dd75cec 100644 --- a/rattail/db/model/custorders.py +++ b/rattail/db/model/custorders.py @@ -103,6 +103,10 @@ class CustomerOrderBase(object): if applicable. """) + contact_name = sa.Column(sa.String(length=100), nullable=True, doc=""" + Cached display name for the contact (customer). + """) + phone_number = sa.Column(sa.String(length=20), nullable=True, doc=""" Customer contact phone number for sake of this order. """)