Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKPORT] MPT-5146 support price list vendor external ID #44

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ cython_debug/

# ruff cache
.ruff_cache
.idea
3 changes: 3 additions & 0 deletions swo/mpt/cli/core/pricelists/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
GENERAL_NOTES = "Notes"
GENERAL_CREATED = "Created"
GENERAL_MODIFIED = "Modified"
EXTERNAL_ID = "External ID"

GENERAL_FIELDS = [
GENERAL_PRICELIST_ID,
GENERAL_CURRENCY,
Expand All @@ -28,6 +30,7 @@
GENERAL_NOTES,
GENERAL_CREATED,
GENERAL_MODIFIED,
EXTERNAL_ID
]

PRICELIST_ITEMS_ID = "ID"
Expand Down
15 changes: 13 additions & 2 deletions swo/mpt/cli/core/pricelists/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,26 @@ def to_operations_pricelist_json(values: list[SheetValue]) -> dict:


def to_vendor_pricelist_json(values: list[SheetValue]) -> dict:
return {

pricelist_json = {
"currency": find_value_for(constants.GENERAL_CURRENCY, values)[2],
"precision": find_value_for(constants.GENERAL_PRECISION, values)[2],
"notes": find_value_for(constants.GENERAL_NOTES, values)[2],
"product": {
"id": find_value_for(constants.GENERAL_PRODUCT_ID, values)[2],
},
}
}

external_id_value = find_value_for(constants.EXTERNAL_ID, values)
external_id = external_id_value[2] if external_id_value else None

if external_id:
pricelist_json["externalIds"] = {
"vendor": external_id,
}
return pricelist_json



def sync_pricelist(
mpt_client: MPTClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,54 @@ def test_sync_pricelist_items_operations(
"unitPP": 12.3,
},
)


def test_sync_pricelist_create_vendor_external_id(
mocker, mpt_client, pricelist, pricelist_new_file, active_vendor_account
):
stats = PricelistStatsCollector()
wb = load_workbook(str(pricelist_new_file))
wb[constants.TAB_GENERAL].cell(row=16, column=1).value = "External ID"
wb[constants.TAB_GENERAL].cell(row=16, column=2).value = "my_external_id"
create_mock = mocker.patch(
"swo.mpt.cli.core.pricelists.flows.create_pricelist",
return_value=pricelist,
)
sync_items_mock = mocker.patch(
"swo.mpt.cli.core.pricelists.flows.sync_pricelist_items",
return_value=stats,
)

returned_stats, returned_pricelist = sync_pricelist(
mpt_client,
wb,
PricelistAction.CREATE,
active_vendor_account,
stats,
console,
)

assert returned_stats.tabs[constants.TAB_GENERAL]["synced"] == 1
assert wb[constants.TAB_GENERAL]["B3"].value == pricelist.id
assert returned_pricelist == pricelist
create_mock.assert_called_once_with(
mpt_client,
{
"currency": "EUR",
'externalIds': {'vendor': 'my_external_id'},
"precision": 2,
"notes": "Note 1",
"product": {
"id": "PRD-0232-2541",
},
},
)
sync_items_mock.assert_called_once_with(
mpt_client,
wb[constants.TAB_PRICE_ITEMS],
pricelist.id,
active_vendor_account,
stats,
console,
)

Loading