feat: price change 时计算加锁
This commit is contained in:
parent
4fdddec6d6
commit
beb9624548
|
@ -7,6 +7,7 @@ from server.settings import get_sysconfig
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from apps.fim.models import PriceSet, FeeSet
|
from apps.fim.models import PriceSet, FeeSet
|
||||||
from apps.mtm.models import Mgroup
|
from apps.mtm.models import Mgroup
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,9 +21,9 @@ def cal_enstat_when_priceset_change(pricesetId):
|
||||||
materialId = material.id
|
materialId = material.id
|
||||||
# 受影响的工段
|
# 受影响的工段
|
||||||
mgroups = Mgroup.objects.filter(input_materials__contains=material.id)
|
mgroups = Mgroup.objects.filter(input_materials__contains=material.id)
|
||||||
enstats = EnStat.objects.filter(mgroup__in=mgroups)
|
with transaction.atomic():
|
||||||
|
enstats = EnStat.objects.select_for_update().filter(mgroup__in=mgroups)
|
||||||
for enstat in enstats:
|
for enstat in enstats:
|
||||||
enstat = EnStat.objects.select_for_update().get(id=enstat.id) # 加锁一下
|
|
||||||
old_cost_unit = 0
|
old_cost_unit = 0
|
||||||
new_cost_unit = 0
|
new_cost_unit = 0
|
||||||
imaterial_data = enstat.imaterial_data
|
imaterial_data = enstat.imaterial_data
|
||||||
|
@ -60,9 +61,9 @@ def cal_enstat_when_feeset_change(feesetId):
|
||||||
fee = feeset.fee
|
fee = feeset.fee
|
||||||
feeId = fee.id
|
feeId = fee.id
|
||||||
# 受影响的工段
|
# 受影响的工段
|
||||||
enstats = EnStat.objects.filter(mgroup=mgroup)
|
with transaction.atomic():
|
||||||
|
enstats = EnStat.objects.select_for_update().filter(mgroup=mgroup)
|
||||||
for enstat in enstats:
|
for enstat in enstats:
|
||||||
enstat = EnStat.objects.select_for_update().get(id=enstat.id) # 加锁一下
|
|
||||||
old_cost_unit = 0
|
old_cost_unit = 0
|
||||||
new_cost_unit = 0
|
new_cost_unit = 0
|
||||||
other_cost_data = enstat.other_cost_data
|
other_cost_data = enstat.other_cost_data
|
||||||
|
@ -71,7 +72,6 @@ def cal_enstat_when_feeset_change(feesetId):
|
||||||
if idata['id'] == feeId:
|
if idata['id'] == feeId:
|
||||||
idata['cost_unit'] = cost_unit
|
idata['cost_unit'] = cost_unit
|
||||||
new_cost_unit = new_cost_unit + idata['cost_unit']
|
new_cost_unit = new_cost_unit + idata['cost_unit']
|
||||||
|
|
||||||
# 更新一些数据
|
# 更新一些数据
|
||||||
enstat.other_cost_data = other_cost_data
|
enstat.other_cost_data = other_cost_data
|
||||||
enstat.production_cost_unit = enstat.production_cost_unit - old_cost_unit + new_cost_unit
|
enstat.production_cost_unit = enstat.production_cost_unit - old_cost_unit + new_cost_unit
|
||||||
|
|
Loading…
Reference in New Issue