forked from erp-dev/erp
fix: order_quantity
This commit is contained in:
@@ -349,6 +349,7 @@ def create_sales_order(
|
||||
num_of_rolls=item_data['num_of_rolls'],
|
||||
consume_detail_ids=item_data.get('consume_detail_ids'),
|
||||
batch_number=item_data.get('batch_number'),
|
||||
order_quantity=item_data.get('order_quantity'),
|
||||
remarks=item_data.get('remarks'),
|
||||
printing_job=item_data.get('printing_job'),
|
||||
)
|
||||
@@ -418,6 +419,7 @@ def update_sales_order(
|
||||
num_of_rolls=item_data['num_of_rolls'],
|
||||
consume_detail_ids=item_data.get('consume_detail_ids'),
|
||||
batch_number=item_data.get('batch_number'),
|
||||
order_quantity=item_data.get('order_quantity'),
|
||||
remarks=item_data.get('remarks'),
|
||||
printing_job=item_data.get('printing_job'),
|
||||
)
|
||||
@@ -1059,6 +1061,10 @@ def _normalize_order_items(
|
||||
batch_number = raw_item.get('batch_number')
|
||||
remarks = raw_item.get('remarks')
|
||||
spec = raw_item.get('spec')
|
||||
order_quantity = _to_non_negative_int_or_none(
|
||||
raw_item.get('order_quantity'),
|
||||
f'items[{index}].order_quantity',
|
||||
)
|
||||
unit = raw_item.get('unit') or product.get_unit_display() or '米'
|
||||
printing_job = None
|
||||
raw_printing_job_id = raw_item.get('printing_job') or raw_item.get('printing_job_id')
|
||||
@@ -1154,6 +1160,7 @@ def _normalize_order_items(
|
||||
'batch_number': batch_number,
|
||||
'remarks': remarks,
|
||||
'spec': spec,
|
||||
'order_quantity': order_quantity,
|
||||
'consume_detail_ids': consume_detail_ids_str,
|
||||
'printing_job': printing_job,
|
||||
})
|
||||
@@ -1755,6 +1762,17 @@ def _to_positive_int(value, field_name: str) -> int:
|
||||
return int(decimal_value)
|
||||
|
||||
|
||||
def _to_non_negative_int_or_none(value, field_name: str) -> int | None:
|
||||
if value in (None, ''):
|
||||
return None
|
||||
decimal_value = _to_decimal(value, field_name)
|
||||
if decimal_value < 0:
|
||||
raise ValueError(f'{field_name} 不能小于 0')
|
||||
if decimal_value != decimal_value.to_integral_value():
|
||||
raise ValueError(f'{field_name} 必须为整数')
|
||||
return int(decimal_value)
|
||||
|
||||
|
||||
# ==================== Statement Builders ====================
|
||||
|
||||
_STATEMENT_TWO_PLACES = Decimal('0.01')
|
||||
|
||||
Reference in New Issue
Block a user