Skip to content

Commit

Permalink
Merge pull request #51 from LeComptoirDesPharmacies/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
GeryDuComptoirDesPharmacies authored Sep 18, 2023
2 parents edad9dd + 73f84ad commit 546b5c0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
6 changes: 3 additions & 3 deletions business/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
DrugstoreExcelLinesMapper

from business.services.excel import create_sale_offer_from_excel_lines, create_or_update_product_from_excel_lines, \
clean_laboratory_sale_offers
clean_sale_offers

detailed_actions = {
'CREATE_PHARMLAB_SALE_OFFER': {
'name': 'Créer/Modifier des annonces PharmLab',
'mapper': LaboratoryExcelLinesMapper,
'executor': create_sale_offer_from_excel_lines,
'cleaner': clean_laboratory_sale_offers,
'cleaner': clean_sale_offers,
'template': CREATE_LABORATORY_SALE_OFFER_TPL
},
'CREATE_UPDATE_PRODUCT': {
Expand All @@ -25,7 +25,7 @@
'name': 'Créer/Modifier des annonces PharmDestock',
'mapper': DrugstoreExcelLinesMapper,
'executor': create_sale_offer_from_excel_lines,
'cleaner': None,
'cleaner': clean_sale_offers,
'template': CREATE_UPDATE_DRUGSTORE_SALE_OFFER_TPL
}
}
Expand Down
2 changes: 1 addition & 1 deletion business/services/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __create_or_update_product_from_excel_line(excel_line):
}


def clean_laboratory_sale_offers(lines):
def clean_sale_offers(lines):
owner_id = next((line.sale_offer.owner_id for line in lines if line.sale_offer.owner_id), None)
if owner_id:
delete_deprecated_sale_offers(owner_id)
10 changes: 1 addition & 9 deletions business/services/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from api.consume.gen.laboratory.api_client_utils import create_search_laboratory_api, create_manage_laboratory_api
from api.consume.gen.product.api_client_utils import create_search_product_api, create_search_product_metadata_api, \
create_manage_product_api
from api.consume.gen.sale_offer.api_client_utils import create_manage_sale_offer_api, create_search_sale_offer_api, \
create_manage_sale_offer_status_api
from api.consume.gen.sale_offer.api_client_utils import create_manage_sale_offer_api, create_search_sale_offer_api
from api.consume.gen.user.api_client_utils import create_search_user_api
from settings import get_settings

Expand Down Expand Up @@ -109,13 +108,6 @@ def get_search_sale_offer_api():
return _search_sale_offer_api


def get_manage_sale_offer_status_api():
global _manage_sale_offer_status_api
if not _manage_sale_offer_status_api:
_manage_sale_offer_status_api = create_manage_sale_offer_status_api(configuration)
return _manage_sale_offer_status_api


def get_manage_product_insight_api():
global _manage_product_insight_api
if not _manage_product_insight_api:
Expand Down
13 changes: 7 additions & 6 deletions business/services/sale_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from api.consume.gen.sale_offer.model.sale_offer_creation_parameters import SaleOfferCreationParameters
from api.consume.gen.sale_offer.model.sale_offer_new_version_parameters import SaleOfferNewVersionParameters
from api.consume.gen.sale_offer.model.sale_offer_status import SaleOfferStatus
from api.consume.gen.sale_offer.model.sale_offer_update_parameters import SaleOfferUpdateParameters
from business.exceptions import CannotCreateSaleOffer, SaleOfferNotFoundByReference, CannotUpdateSaleOfferStatus
from business.mappers.sale_offer import distribution_to_dto, stock_to_dto, stock_to_patch_dto
from business.models.update_policy import UpdatePolicy
from business.services.providers import get_manage_sale_offer_api, get_search_sale_offer_api, \
get_manage_sale_offer_status_api
from business.services.providers import get_manage_sale_offer_api, get_search_sale_offer_api
from business.services.security import get_api_key
from business.utils import clean_none_from_dict

Expand Down Expand Up @@ -173,9 +173,10 @@ def change_sale_offer_status(sale_offer_status_excel, sale_offer_reference):

def __update_sale_offer_status(sale_offer_reference, status):
try:
api = get_manage_sale_offer_status_api()
body = SaleOfferStatus(status)
api.update_sale_offer_status(_request_auths=[api.api_client.create_auth_settings("apiKeyAuth", get_api_key())],
sale_offer_reference=sale_offer_reference, body=body)
api = get_manage_sale_offer_api()
status = SaleOfferStatus(status)
api.update_sale_offer(_request_auths=[api.api_client.create_auth_settings("apiKeyAuth", get_api_key())],
sale_offer_reference=sale_offer_reference,
sale_offer_update_parameters=SaleOfferUpdateParameters(status=status))
except Exception:
raise CannotUpdateSaleOfferStatus()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ openpyxl==3.0.9
envsubst==0.1.5
nose2==0.11.0
Pillow==9.1.1
lcdp-api==1.7.1
lcdp-api==1.7.2
python-openapi-generator-cli==1.3.1
python-rest-client-codegen==1.3.1
4 changes: 0 additions & 4 deletions tests/services/test_sale_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ class TestSaleOffer(unittest.TestCase):
def setUp(self):
self.search_sale_offer_patch = patch('business.services.sale_offer.get_search_sale_offer_api')
self.manage_sale_offer_patch = patch('business.services.sale_offer.get_manage_sale_offer_api')
self.manage_sale_offer_status_patch = patch('business.services.sale_offer.get_manage_sale_offer_status_api')
self.distribution_to_dto_patch = patch('business.services.sale_offer.distribution_to_dto')
self.stock_to_dto_patch = patch('business.services.sale_offer.stock_to_dto')
self.get_api_key_patch = patch('business.services.sale_offer.get_api_key')

search_sale_offer_mock = self.search_sale_offer_patch.start()
manage_sale_offer_mock = self.manage_sale_offer_patch.start()
manage_sale_offer_status_mock = self.manage_sale_offer_status_patch.start()
distribution_to_dto_mock = self.distribution_to_dto_patch.start()
stock_to_dto_mock = self.stock_to_dto_patch.start()
get_api_key_patch_mock = self.get_api_key_patch.start()
get_api_key_patch_mock.return_value = {}

self.search_sale_offer_api = search_sale_offer_mock.return_value
self.manage_sale_offer_api = manage_sale_offer_mock.return_value
self.manage_sale_offer_status_api = manage_sale_offer_status_mock.return_value

stock_to_dto_mock.return_value = Stock()
distribution_to_dto_mock.return_value = AnyDistributionMode(type='QUOTATION', minimal_quantity=1,
Expand All @@ -54,7 +51,6 @@ def tearDown(self):
self.stock_to_dto_patch.stop()
self.distribution_to_dto_patch.stop()
self.get_api_key_patch.stop()
self.manage_sale_offer_status_patch.stop()

@params(
(Mock(SaleOffer), None),
Expand Down

0 comments on commit 546b5c0

Please sign in to comment.