-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #605 from weni-ai/feature/calculate_by_area
Feature/calculate by area
- Loading branch information
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
marketplace/services/vtex/business/rules/calculate_by_area.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .interface import Rule | ||
from marketplace.services.vtex.utils.data_processor import FacebookProductDTO | ||
|
||
|
||
class CalculateByArea(Rule): | ||
def apply(self, product: FacebookProductDTO, **kwargs) -> bool: | ||
if self._calculate_by_area(product): | ||
unit_multiplier = self._get_multiplier(product) | ||
product.price *= unit_multiplier | ||
product.sale_price *= unit_multiplier | ||
return True | ||
|
||
def _calculate_by_area(self, product: FacebookProductDTO): | ||
measurementUnit = product.product_details.get("MeasurementUnit", "") | ||
if len(measurementUnit) > 0 and measurementUnit == 'm²': | ||
return True | ||
return False | ||
|
||
def _get_multiplier(self, product: FacebookProductDTO): | ||
return product.product_details.get("UnitMultiplier", 1.0) |
19 changes: 19 additions & 0 deletions
19
marketplace/services/vtex/business/rules/currency_pt_br_round_floor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from .interface import Rule | ||
from typing import Union | ||
from marketplace.services.vtex.utils.data_processor import FacebookProductDTO | ||
from decimal import Decimal, ROUND_FLOOR | ||
|
||
|
||
class CurrencyBRLRoudingFloor(Rule): | ||
|
||
def apply(self, product: FacebookProductDTO, **kwargs) -> bool: | ||
product.price = self.format_price(product.price) | ||
product.sale_price = self.format_price(product.sale_price) | ||
return True | ||
|
||
@staticmethod | ||
def format_price(price: Union[int, float]) -> str: | ||
final_price = Decimal(price / 100) | ||
final_price = final_price.quantize(Decimal('0.01'), rounding=ROUND_FLOOR) | ||
formatted_price = f"{final_price} BRL" | ||
return formatted_price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters