1
0
forked from erp-dev/erp

feat: support pre_sales_order convert to sales_order api

This commit is contained in:
2026-02-02 15:58:29 +08:00
parent 2572c5aab4
commit fb93582b06
13 changed files with 379 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ from decimal import Decimal
from typing import Iterable, List
from django.db import transaction
from django.utils import timezone
from stock import models as stock_models
from . import models
@@ -133,8 +134,28 @@ def create_allocation_record(
def cancel_allocation_record(*, record: models.AllocationRecord) -> models.AllocationRecord:
if record.status == models.AllocationRecordStatusEnum.CANCELLED:
return record
record.status = models.AllocationRecordStatusEnum.CANCELLED
record.save(update_fields=['status', 'updated_at'])
return cancel_allocation_record_with_unfreeze(record=record)
def cancel_allocation_record_with_unfreeze(
*,
record: models.AllocationRecord,
cancelled_by=None,
reason: str | None = None,
) -> models.AllocationRecord:
with transaction.atomic():
if record.status != models.AllocationRecordStatusEnum.CANCELLED:
record.status = models.AllocationRecordStatusEnum.CANCELLED
record.save(update_fields=['status', 'updated_at'])
stock_models.StockFreeze.objects.filter(
frozen_with=record.id,
status=stock_models.StockFreezeStatusEnum.FROZEN,
).update(
status=stock_models.StockFreezeStatusEnum.CANCELLED,
cancelled_by=cancelled_by,
cancelled_at=timezone.now(),
reason=reason,
)
return record