45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from calculators import Calculator
|
|
|
|
from commons.models.price_result import PriceResult
|
|
|
|
|
|
class AsphaltImportedModifierCalculator(Calculator):
|
|
name = "进口改性沥青"
|
|
material_id = "3001002002"
|
|
unit = "t"
|
|
spec = ""
|
|
|
|
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 or not asphalt.price_recommend:
|
|
return 0, 0
|
|
|
|
query = PriceResult.get_query(self.year, self.month, name='改性剂')
|
|
modifier = query.first()
|
|
fluctuating_2 = int(modifier.fluctuating_recommend * 5 / 100) if modifier else 0
|
|
|
|
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
|
if not previous_price:
|
|
previous_price = asphalt.price_recommend + modifier.price_recommend * 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)
|