forked from erp-dev/erp
fix: quantity when converting to sales_order
This commit is contained in:
@@ -209,12 +209,12 @@ class PreSalesOrderAPITestCase(TestCase):
|
||||
product=self.product,
|
||||
unit=ProductUnitEnum.METER,
|
||||
stock_change_record=stock_record,
|
||||
quantity='10',
|
||||
quantity='12',
|
||||
)
|
||||
allocation_services.create_allocation_record(
|
||||
item=item,
|
||||
stock_ids=[stock_detail.id],
|
||||
quantity='10',
|
||||
quantity='12',
|
||||
unit='米',
|
||||
scanned_by=self.employee,
|
||||
)
|
||||
@@ -229,7 +229,8 @@ class PreSalesOrderAPITestCase(TestCase):
|
||||
self.assertEqual(convert_resp.data['status'], business_models.SalesOrderStatusEnum.PENDING)
|
||||
sales_order = business_models.SalesOrder.objects.get(id=convert_resp.data['id'])
|
||||
self.assertEqual(sales_order.from_pre_sales_order_id, order_id)
|
||||
self.assertEqual(sales_order.items.first().quantity_of_rolls, '10')
|
||||
self.assertEqual(sales_order.items.first().quantity_of_rolls, '12')
|
||||
self.assertEqual(str(sales_order.items.first().quantity), '12.00')
|
||||
|
||||
def test_detail_filters_cancelled_allocation_records(self):
|
||||
"""单体查询应过滤掉已撤销的配货记录"""
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.utils import timezone
|
||||
|
||||
from basic_info import models as basic_info_models
|
||||
from stock import models as stock_models
|
||||
|
||||
from . import models
|
||||
from . import services as business_services
|
||||
@@ -437,11 +438,23 @@ def convert_pre_sales_order_to_sales_order(
|
||||
if not consume_ids:
|
||||
raise ValueError(f'明细 {item.id} 缺少配货库存明细')
|
||||
|
||||
quantity_from_details: Decimal | None = None
|
||||
if consume_ids:
|
||||
details_by_id = stock_models.StockChangeDetail.objects.filter(
|
||||
id__in=consume_ids,
|
||||
merchant=merchant,
|
||||
).in_bulk()
|
||||
if details_by_id:
|
||||
total = Decimal('0')
|
||||
for detail in details_by_id.values():
|
||||
total += detail.quantity
|
||||
quantity_from_details = total
|
||||
|
||||
items_payload.append(
|
||||
{
|
||||
'product_id': item.product_id,
|
||||
'price': '0',
|
||||
'quantity': str(item.quantity),
|
||||
'quantity': str(quantity_from_details or item.quantity),
|
||||
'unit': item.unit or None,
|
||||
'color': item.color,
|
||||
'spec': item.spec,
|
||||
|
||||
@@ -166,13 +166,13 @@ class PreSalesOrderServiceTestCase(TestCase):
|
||||
product=self.product,
|
||||
unit=basic_models.ProductUnitEnum.METER,
|
||||
stock_change_record=stock_record,
|
||||
quantity='10',
|
||||
quantity='12',
|
||||
)
|
||||
|
||||
allocation_services.create_allocation_record(
|
||||
item=item,
|
||||
stock_ids=[stock_detail.id],
|
||||
quantity='10',
|
||||
quantity='12',
|
||||
unit='米',
|
||||
scanned_by=self.operator,
|
||||
)
|
||||
@@ -192,7 +192,8 @@ class PreSalesOrderServiceTestCase(TestCase):
|
||||
sales_item = sales_order.items.first()
|
||||
self.assertEqual(sales_item.product_id, self.product.id)
|
||||
self.assertEqual(sales_item.consume_detail_ids, str(stock_detail.id))
|
||||
self.assertEqual(sales_item.quantity_of_rolls, '10')
|
||||
self.assertEqual(sales_item.quantity_of_rolls, '12')
|
||||
self.assertEqual(str(sales_item.quantity), '12.00')
|
||||
|
||||
|
||||
class PreSalesOrderSignalTestCase(TransactionTestCase):
|
||||
|
||||
Reference in New Issue
Block a user