refactor: derive VK description postfix from measure_name, drop global postfix setting
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -11,24 +11,15 @@
|
||||
{% endif %}
|
||||
|
||||
<article class="card">
|
||||
<h2 style="font-size:1.1rem; margin-bottom:1.25rem;">Настройки цены и описания</h2>
|
||||
<h2 style="font-size:1.1rem; margin-bottom:1.25rem;">Настройки цены</h2>
|
||||
<form method="post" action="/sync/settings">
|
||||
<div class="grid" style="grid-template-columns: 1fr 1fr; gap:1.5rem;">
|
||||
<label>
|
||||
<label style="max-width:320px;">
|
||||
Множитель цены
|
||||
<input type="number" name="price_multiplier" step="0.0001" min="0.0001"
|
||||
value="{{ config.price_multiplier if config else '1' }}"
|
||||
placeholder="1">
|
||||
<small class="text-muted">Цена из Эвотор умножается на это значение перед отправкой в ВК. По умолчанию: 1.</small>
|
||||
</label>
|
||||
<label>
|
||||
Постфикс описания
|
||||
<input type="text" name="description_postfix"
|
||||
value="{{ config.description_postfix if config and config.description_postfix else '' }}"
|
||||
placeholder="цена за 10г.">
|
||||
<small class="text-muted">Если заполнено, добавляется к описанию: «Название (постфикс)». Оставьте пустым, чтобы не добавлять.</small>
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" style="margin-top:1rem;">Сохранить</button>
|
||||
</form>
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user