From 02abddc58705c7b4db280c6aadbf593a9afbd979 Mon Sep 17 00:00:00 2001 From: mguschin Date: Tue, 12 May 2026 23:08:45 +0300 Subject: [PATCH] refactor: derive VK description postfix from measure_name, drop global postfix setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each product's description is now built as "Name (цена за M.)" using its own measure_name. The global description_postfix setting is removed — it couldn't handle per-product units. Co-Authored-By: Claude Sonnet 4.6 --- .../0008_sync_config_price_postfix.py | 4 +-- web/models/connections.py | 1 - web/routes/sync.py | 3 --- web/tasks/vk_sync.py | 4 +-- web/templates/sync.html | 25 ++++++------------- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/web/migrations/versions/0008_sync_config_price_postfix.py b/web/migrations/versions/0008_sync_config_price_postfix.py index 1165a51..d4323ab 100644 --- a/web/migrations/versions/0008_sync_config_price_postfix.py +++ b/web/migrations/versions/0008_sync_config_price_postfix.py @@ -1,4 +1,4 @@ -"""Add price_multiplier and description_postfix to sync_configs.""" +"""Add price_multiplier to sync_configs.""" revision = "0008" down_revision = "0007" branch_labels = None @@ -10,9 +10,7 @@ from alembic import op def upgrade(): op.add_column("sync_configs", sa.Column("price_multiplier", sa.Numeric(10, 4), nullable=False, server_default="1.0")) - op.add_column("sync_configs", sa.Column("description_postfix", sa.String(255), nullable=True)) def downgrade(): - op.drop_column("sync_configs", "description_postfix") op.drop_column("sync_configs", "price_multiplier") diff --git a/web/models/connections.py b/web/models/connections.py index 6f8a066..392ddc1 100644 --- a/web/models/connections.py +++ b/web/models/connections.py @@ -59,7 +59,6 @@ class SyncConfig(Base): is_enabled = Column(Boolean, nullable=False, default=False) confirmed_at = Column(DateTime, nullable=True) price_multiplier = Column(Numeric(10, 4), nullable=False, default=1.0) - description_postfix = Column(String(255), nullable=True) created_at = Column(DateTime, nullable=False, server_default=func.now()) updated_at = Column(DateTime, nullable=False, server_default=func.now(), onupdate=func.now()) diff --git a/web/routes/sync.py b/web/routes/sync.py index ff4d0fb..f344927 100644 --- a/web/routes/sync.py +++ b/web/routes/sync.py @@ -49,7 +49,6 @@ async def sync_settings_post(request: Request, db: Session = Depends(get_db)): form = await request.form() raw_multiplier = str(form.get("price_multiplier", "1")).strip() - postfix = str(form.get("description_postfix", "")).strip() or None try: multiplier = float(raw_multiplier) @@ -61,13 +60,11 @@ async def sync_settings_post(request: Request, db: Session = Depends(get_db)): config = db.query(SyncConfig).filter_by(user_id=user.id).first() if config: config.price_multiplier = multiplier - config.description_postfix = postfix else: config = SyncConfig( user_id=user.id, is_enabled=False, price_multiplier=multiplier, - description_postfix=postfix, ) db.add(config) diff --git a/web/tasks/vk_sync.py b/web/tasks/vk_sync.py index 6a71c97..def4558 100644 --- a/web/tasks/vk_sync.py +++ b/web/tasks/vk_sync.py @@ -153,8 +153,8 @@ def _sync_product( name = _name_for_vk(product.name) multiplier = float(sync_config.price_multiplier) if sync_config and sync_config.price_multiplier else 1.0 price_rubles = _calc_price(product.price) * multiplier - postfix = (sync_config.description_postfix or "").strip() if sync_config else "" - desc = f"{product.name} ({postfix})" if postfix else product.name + measure = (product.measure_name or "").strip() + desc = f"{product.name} (цена за {measure}.)" if measure else product.name stock = settings.VK_STOCK_AMOUNT if product.allow_to_sell else 0 owner_id = f"-{vk_group_id}" now = _now() diff --git a/web/templates/sync.html b/web/templates/sync.html index 1f2fab9..aac08a8 100644 --- a/web/templates/sync.html +++ b/web/templates/sync.html @@ -11,24 +11,15 @@ {% endif %}
-

Настройки цены и описания

+

Настройки цены

-
- - -
+