Skip to content

Commit

Permalink
Merge pull request #55 from yukihiko-shinoda/support-transfer-from-pa…
Browse files Browse the repository at this point in the history
…ypay-card-to-paypay

Support transfer from paypay card to paypay
  • Loading branch information
yukihiko-shinoda authored Jan 18, 2024
2 parents b42870f + 0466d26 commit 2018c7d
Show file tree
Hide file tree
Showing 17 changed files with 753 additions and 878 deletions.
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ pylint = "*"
pytest = "*"
pytest-resource-path = "*"
pyvelocity = {version = "*", markers="python_version >= '3.9'"}
radon = "*"
# - Radon can't run when use pytest log fornat: `$()d` · Issue #251 · rubik/radon
# https://github.com/rubik/radon/issues/251
radon = "<6.0.0"
returns = "*"
ruff = {version = "*", markers="python_version >= '3.7'"}
semgrep = {version = "*", markers="python_version >= '3.6'"}
Expand Down
1,556 changes: 709 additions & 847 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions tests/customdatatypes/test_string_with_comma_to_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def test(self, value: str, expected: int) -> None:
"1.0",
"1,000.0",
"1,000,000.0",
"1,000,000.0",
"1,000,000 1,000,000",
"1,000,000 1,000,000",
# "1000000",
"1,000,000円",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def test(self, value: str, expected: int) -> None:
"1.0",
"1,000.0",
"1,000,000.0",
"1,000,000.0",
"1,000,000 1,000,000",
"1,000,000 1,000,000",
# "1000000",
"1,000,000円",
Expand Down
1 change: 0 additions & 1 deletion tests/customdatatypes/test_symbol_yen_string_to_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test(self, value: str, expected: int) -> None:
r"\1.0",
r"\1,000.0",
r"\1,000,000.0",
r"\1,000,000.0",
# r"\1,000,000 \1,000,000",
# r"\1000000",
# r"\1,000,000円",
Expand Down
7 changes: 0 additions & 7 deletions tests/inputtooutput/converters/recordtozaim/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ class TestZaimRowConverterFactory:
InstanceResource.ROW_DATA_WAON_AUTO_CHARGE_ITABASHIMAENOCHO,
WaonZaimTransferRowConverter,
),
# Case when WAON charge by bank account
(
[InstanceResource.FIXTURE_RECORD_STORE_WAON_ITABASHIMAENOCHO],
Account.WAON,
InstanceResource.ROW_DATA_WAON_CHARGE_BANK_ACCOUNT_ITABASHIMAENOCHO,
WaonZaimTransferRowConverter,
),
# Case when WAON charge by cash
(
[InstanceResource.FIXTURE_RECORD_STORE_WAON_ITABASHIMAENOCHO],
Expand Down
8 changes: 7 additions & 1 deletion tests/testlibraries/integration_test_expected_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,18 @@ def create_zaim_row_data_sbi_sumishin_net_bank_202201() -> list[ZaimRowData]:
def create_zaim_row_data_pay_pay_card_202208() -> list[ZaimRowData]:
"""Creates expected zaim row data for PayPay Card 202208."""
zaim_row_data_01 = ZaimRowData(
# fmt: off
"2022-07-29", "transfer", "-", "-", "PayPay カード", "PayPay", "", "",
"", "", "0", "0", "3000", "", "", "",
# fmt: on
)
zaim_row_data_02 = ZaimRowData(
# fmt: off
"2022-07-03", "payment", "食費", "食料品", "PayPay カード", "", "", "",
"ビッグ・エー", "", "0", "292", "0", "", "", "",
# fmt: on
)
return [zaim_row_data_01]
return [zaim_row_data_01, zaim_row_data_02]


def create_zaim_row_data_mobile_suica_202210() -> list[ZaimRowData]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PayPay チャージ,,,,,PayPay
ペイペイ ビッグエー,ビッグ・エー,食費,食料品
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"利用日/キャンセル日","利用店名・商品名","利用者","支払区分","利用金額","手数料","支払総額","当月支払金額","翌月以降繰越金額","調整額","当月お支払日"
"2022/7/29","PayPay チャージ","本人*","1回","3000","0","3000","3000","0","0","2022/8/29"
"2022/7/3","ペイペイ ビッグエー","本人*","1回","292","0","292","292","0","0","2022/8/29"
2 changes: 1 addition & 1 deletion zaimcsvconverter/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AccountContext(Generic[TypeVarInputRowData, TypeVarInputRow]):
],
partition=[
# fmt: off
r"\d{4}/\d{1,2}/\d{1,2}", r".*", "(注文全体)", "", "", "", "", r"\d*", "", "", r".*", r"\d*", "", "", # noqa: RUF001,E501 pylint: disable=line-too-long
r"\d{4}/\d{1,2}/\d{1,2}", r".*", "(注文全体)", "", "", "", "", r"\d*", "", "", r".*", r"\d*", "", "", # noqa: RUF001,RUF100,E501 pylint: disable=line-too-long
r".*", r".*", r".*", "",
# fmt: on
],
Expand Down
6 changes: 2 additions & 4 deletions zaimcsvconverter/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ class ContextManager(Generic[TypeVarCovariant_co], ABC):
"""Class which can be used as `contextmanager`."""

def __init__(self) -> None:
# Reason: There are no more typing ways.
self.__cm: Optional[contextlib._GeneratorContextManager[TypeVarCovariant_co]] = None # noqa: SLF001
self.__cm: Optional[contextlib._GeneratorContextManager[TypeVarCovariant_co]] = None

# Reason: Maybe, there are no way to fix.
# error: Argument 1 to "contextmanager" has incompatible type
# "Callable[[ContextManager[T_co]], _GeneratorContextManager[T_co]]"; # noqa: ERA001
# expected "Callable[[ContextManager[T_co]], Iterator[<nothing>]]"
@abstractmethod # type: ignore[arg-type]
@contextlib.contextmanager
# Reason: There are no more typing ways.
def contextmanager(self) -> contextlib._GeneratorContextManager[TypeVarCovariant_co]: # noqa: SLF001
def contextmanager(self) -> contextlib._GeneratorContextManager[TypeVarCovariant_co]:
raise NotImplementedError

def __enter__(self) -> TypeVarCovariant_co:
Expand Down
2 changes: 1 addition & 1 deletion zaimcsvconverter/customdatatypes/abstract_string_to_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def string_to_int(cls, value: str) -> int:


# Reason: Followed pydantic specification.
def constringtoint( # noqa: PLR0913
def constringtoint( # noqa: PLR0913 pylint: disable=too-many-arguments
type_name: str,
type_class: type[ConstrainedStringToInt],
*,
Expand Down
6 changes: 2 additions & 4 deletions zaimcsvconverter/customdatatypes/string_to_optional_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def convert_to_optional_integer(cls, value: Any) -> Optional[int]:


# Reason: To follow pydantic constr interface.
def constringtooptionalint( # noqa: PLR0913
def constringtooptionalint( # noqa: PLR0913 pylint: disable=too-many-arguments
*,
strict: bool = False,
gt: Optional[int] = None, # pylint: disable=invalid-name
Expand All @@ -56,9 +56,7 @@ def constringtooptionalint( # noqa: PLR0913
return type("ConstrainedStringToOptionalIntValue", (StringToOptionalInt,), namespace)


# Reason: The mypy's bug:
# error: Unsupported left operand type for == (ConstrainedStringToOptionalInt?) [operator]
if TYPE_CHECKING: # noqa: SIM108
if TYPE_CHECKING:
ConstrainedStringToOptionalInt = Optional[int]
else:
ConstrainedStringToOptionalInt = constringtooptionalint()
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def convert_to_optional_integer(cls, value: Any) -> Optional[int]:


# Reason: Followed pydantic specification.
def constringwithcommatooptionalint( # noqa: PLR0913
def constringwithcommatooptionalint( # noqa: PLR0913 pylint: disable=too-many-arguments
*,
strict: bool = False,
gt: Optional[int] = None, # pylint: disable=invalid-name
Expand All @@ -32,9 +32,7 @@ def constringwithcommatooptionalint( # noqa: PLR0913
return type("ConstrainedStringWithCommaToIntValue", (StringWithCommaToOptionalInt,), namespace)


# Reason: The mypy's bug:
# error: Unsupported left operand type for == (ConstrainedStringToOptionalInt?) [operator]
if TYPE_CHECKING: # noqa: SIM108
if TYPE_CHECKING:
StrictStringWithCommaToOptionalInt = Optional[int]
else:
StrictStringWithCommaToOptionalInt = constringwithcommatooptionalint(strict=True)
2 changes: 1 addition & 1 deletion zaimcsvconverter/file_csv_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FileCsvConvertContext:
"""This class implements CSV file for convert table."""

# pylint:disable=invalid-name
id: FileCsvConvertId # noqa: A003
id: FileCsvConvertId
name: str
convert_table_type: ConvertTableType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,38 @@


from pathlib import Path
from typing import cast

from git import Optional
from returns.primitives.hkt import Kind1

from zaimcsvconverter import CONFIG
from zaimcsvconverter.inputtooutput.converters.recordtozaim import (
CsvRecordToZaimRowConverterFactory,
ZaimPaymentRowStoreConverter,
ZaimRowConverter,
ZaimTransferRowConverter,
)
from zaimcsvconverter.inputtooutput.datasources.csv.data.pay_pay_card import PayPayCardRowData
from zaimcsvconverter.inputtooutput.datasources.csv.records.pay_pay_card import PayPayCardRow


class PayPayCardZaimTransferRowConverter(ZaimTransferRowConverter[PayPayCardRow, PayPayCardRowData]):
"""This class implements convert steps from GOLD POINT CARD + input row to Zaim transfer row."""

@property
def cash_flow_source(self) -> str:
return CONFIG.pay_pay_card.account_name

@property
def cash_flow_target(self) -> Optional[str]:
return self.input_row.store.transfer_target

@property
def amount(self) -> int:
return self.input_row.used_amount


# Reason: Pylint's bug. pylint: disable=unsubscriptable-object
class PayPayCardZaimPaymentRowConverter(ZaimPaymentRowStoreConverter[PayPayCardRow, PayPayCardRowData]):
"""This class implements convert steps from PayPay Card input row to Zaim payment row."""
Expand All @@ -39,4 +58,7 @@ def create(
input_row: Kind1[PayPayCardRow, PayPayCardRowData], # type: ignore[override]
_path_csv_file: Path,
) -> ZaimRowConverter[PayPayCardRow, PayPayCardRowData]:
dekinded_input_row = cast(PayPayCardRow, input_row)
if dekinded_input_row.store.transfer_target:
return PayPayCardZaimTransferRowConverter(input_row)
return PayPayCardZaimPaymentRowConverter(input_row)
3 changes: 1 addition & 2 deletions zaimcsvconverter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def __tablename__(cls) -> str: # noqa: N805
class_name = cls.__name__
return str(Inflector().pluralize(class_name.lower()))

# Reason: For database table design.
id = Column(Integer, primary_key=True) # noqa: A003
id = Column(Integer, primary_key=True)
file_csv_convert_id = Column(Integer)
name = Column(String(255))
category_payment_large = Column(String(255))
Expand Down

0 comments on commit 2018c7d

Please sign in to comment.