57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from sqlalchemy import func
|
|
|
|
from calculators import Calculator, Helper
|
|
from commons.models.asphalt_modifier import AsphaltModifier
|
|
|
|
from commons.models.price_result import PriceResult
|
|
|
|
|
|
class AsphaltImportedModifierCalculator(Calculator):
|
|
name = "进口改性沥青"
|
|
material_id = "06.12.60.00"
|
|
unit = "t"
|
|
spec = ""
|
|
|
|
def __init__(self, year, month):
|
|
self.year = year
|
|
self.month = month
|
|
|
|
def _get_recommend_price(self):
|
|
query = PriceResult.get_query(self.year, self.month, name='进口沥青')
|
|
asphalt = query.first()
|
|
fluctuating_1 = asphalt.fluctuating_recommend if asphalt else 0
|
|
if not asphalt.price_recommend:
|
|
return 0, 0
|
|
|
|
query = AsphaltModifier.get_query(self.year, self.month)
|
|
modifier_current = query.first()
|
|
query = AsphaltModifier.get_query(*Helper.get_last_month(self.year, self.month))
|
|
modifier_previous = query.first()
|
|
if modifier_current and modifier_previous:
|
|
fluctuating_2 = int((modifier_current.price - modifier_previous.price) * 5 / 100)
|
|
else:
|
|
fluctuating_2 = 0
|
|
|
|
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
|
if not previous_price:
|
|
previous_price = asphalt.price_recommend + modifier_current.price * 5 / 100
|
|
|
|
price = previous_price + fluctuating_1 + fluctuating_2
|
|
price = round(price / 10) * 10
|
|
|
|
return price, fluctuating_1 + fluctuating_2
|
|
|
|
def save(self):
|
|
result = self.result()
|
|
PriceResult(**result).upsert()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from core.factory import ClientApp
|
|
|
|
with ClientApp().app_context():
|
|
calculator = AsphaltImportedModifierCalculator(year=2023, month=9)
|
|
_result = calculator.run()
|
|
calculator.save()
|
|
print(_result)
|