In this Chapter, I will walk you through what and why OOP is for building a P&L calculator. By the end of this Python Tutorial, you can master how to write Python coding scripts to build the calculator that fits your business model.
목차 : 프로파일 마진 계산기
- OOP- 객체 지향 프로그래밍
- 방법 : 교차 국경 전자 상거래 이익 마진 계산 알고리즘
- SKU 이익 마진 계산기의 Python OPP 코딩
- 플라스크 스크립트 – HTML, CSS 및 Python
- Full Python Script of eCommerce Profit & Loss Calculator
- 자주하는 질문
OOP 란 무엇인가-객체 지향 프로그래밍
객체 지향 프로그래밍 또는 OOP는 클래스와 객체의 개념에 의존하는 프로그래밍 패러다임입니다. 이를 사용하여 소프트웨어 프로그램을 간단하고 재사용 가능한 코드 청사진으로 구성 할 수 있으며, 이는 일반적으로 클래스라고합니다. 그리고 클래스에서는 개별 객체 인스턴스를 만들 수 있습니다.
OOP는 기본적으로 부모 클래스 (자식 수업을 가질 수 있음), 클래스 속성 및 방법 (기능이지만 OOP는 메소드라고합니다)으로 구성됩니다.
Take the eCommerce P&L calculator for an example. eCommerce has different types of business models or is selling different product categories. It has domestic, cross-border, dropshipping, B2B wholesale, etc. Each type of eCommerce business can be a specific instance of an object. It should need a different calculation algorithm and attribute value. It’s because the variable cost item would be slightly different. However, no matter which type of eCommerce, it should have some general attributes to impact the profit margin.
이익 마진 속성은 다음과 같습니다.
- 상륙 비용 (단가 당 제품 포함, 국경 간 전자 상거래 인 경우 국제 운송 및 관세 포함)
- 이행 비용
- 지불 처리 비용
- 환불 비용
- 판매 당 비용
- 할인 비용
- Sku 가격
In OOP, the concept of class is fundamental. Each class consists of attributes . and methods. Then, it can have different objects using this class. Each object in the e-commerce P&L calculator can represent your business model. In other words, all objects are using the same parent class, however, the local attribute value and methods are different.
For example, domestic eCommerce P&L might not have international shipping costs. So the landed cost value would be different with cross-border eCommerce.
전자 상거래 변수 비용에 대한 자세한 내용을 배우려면이 기사를 확인하십시오.
방법 : 교차 국경 전자 상거래 이익 마진 계산 알고리즘
계산 알고리즘은 계산기의 중요한 구성 요소입니다. 두 가지 이유 때문입니다. 첫 번째 이유는 당신이 참조에 적합한 SKU 이익 마진 계산을 절대적으로 좋아하기 때문입니다. 그런 다음 두 번째 이유는사용자가 계산기에 어떤 데이터와 데이터 형식을 입력 해야하는지 명확하게하는 것을 좋아하기 때문입니다. 계산기가 사용자가 더 복잡한 요인이있는 숫자를 찾는 데 도움을주는 경우 때로는 매우 복잡 할 수있습니다.
예를 들어, 일반적으로 이익 마진 공식은 (SKU 가격 – 판매 비용) / SKU 가격입니다. 또한 판매 비용을 착륙 비용, 이행 비용, 환불 비용, 지불 처리 비용, CPS 및 할인 비용으로 분류 할 수 있습니다. 예를 들어, 계산기의 객체에 따라 계산기의 객체에 따라 필요한 경우 더 중단 할 수 있습니다. 예를 들어, 사용자에게 이행 비용으로 무게, 크기 및 대상을 입력하도록 요청합니다. 또는 여기서는 알고리즘을 보여주기 위해 예를 들어 환불율 입력을 할 것입니다.
속성 값과 연결되는 객체 알고리즘은 다음과 같습니다.
(SKU price - landed cost - fulfillment cost - (refund rate * fulfillment cost * 2) - payment processing cost - discount rate * SKU price - CPS) / SKU price
SKU 이익 마진 계산기의 Python OOP 코딩
I take the cross-border eCommerce P&L calculator as the parent class in this Python OOP. Now the scope of attributes and calculation algorithm is ready. Below are the codings of the core engine of the calculator.
In Python OOP, the first thing is to create a parent class. In this class, there are three fundamental components. They are the _init__ attribute
, attribute association and a method definition.
_init__ 속성
This is the self-default object and method of the class. We need to def the default method by adding all attributes here in the positional arguments in the __init__( )
. As we are building a cross-border eCommerce P&L calculator, the attribute items are the price and variable costs related to this model.
def __init__(
self,
landedCost,
shippingCost,
paymentCost,
refundCost,
CPA,
discount,
price
):
Self-Becject에 할당하십시오
Self-Bobject가 준비되었으므로 위치 인수의 속성과 관련 될 수있는 변수를 만들 수 있습니다. 따라서이 객체의 모든 메소드에 대한 변수를 사용할 수 있습니다.
self.landedCost = landedCost
self.shippingCost = shippingCost
self.paymentCost = paymentCost
self.refundCost = refundCost
self.CPA = CPA
self.discount = discount
self.price = price
Define the P&L calculator algorithm method
OOP-Object는 SKU 속성 값을 입력 한 후 이익 마진을 계산하는 것입니다. 따라서이 클래스에 포함 된 알고리즘이 필요합니다. 이를 위해 DEF를 사용하여 메소드를 만들 수 있으며 위치 인수는 자기가될 수 있습니다.
def calculate_profitmargin(self):
return (self.price - self.landedCost - self.shippingCost - self.price * self.paymentCost - self.shippingCost * 2 * self.refundCost - self.CPA - self.discount * self.price) / self.price
언급했듯이 계산 알고리즘은 실제 요구에 따라 다릅니다. 따라서이 클래스에서 더 많은 알고리즘 방법을 정의 할 수 있습니다. 예를 들어 SKU 가격을 AOV로 대체하는 다른 방법을 설정할 수 있습니다.
플라스크 스크립트
Flask는 Python, HTML, CSS, PHP 등과 같은 프로그래밍 스크립트와 통합 할 수있는 친구이자 강력한 웹 애플리케이션 빌더입니다. 설치, 설정 및 사용 방법에 대한 자세한 내용을 배우려면 구축 및테스트를 수행합니다. Python Web Applications,이 기사를 확인하십시오
계산기 응용 프로그램의 플라스크 스크립트에는 돌봐야 할 두 가지 주요 사항이 있습니다. 파이썬 스크립트와 HTML 스크립트입니다.
플라스크 스크립트의 파이썬 스크립트
여기서 파이썬 스크립트는 속성 값을 수집하기위한 프론트 엔드 HTML 테이블을 연결해야합니다. 한편, HTML 페이지에. 서 수집 된 데이터를 공급하여 OOP 계산기 알고리즘에 연결해야합니다. 가장 중요한 것 중 하나는 위치 인수입니다. 계산에서 잘못된 결과를 피하기 위해 입력 데이터 변수와 위치 인수와 잘 일치하십시오.
자체 객체 :
profitMargin1 = item(landedCost1, shippingCost1, paymentCost1, refundCost1, CPA1, discount1, price1)
계산 알고리즘을 할당하십시오
result = "{:.2%}".format(round(profitMargin1.calculate_profitmargin(), 2))
You might notice, we convert the calculation into a percentage number. That’s because the outcome from calculate_profitmargin
is a floating number. That would create a better user experience
결과 페이지에서 입력 값을 유지하십시오
사용자는 결과를 생성하여 상자에 입력 한 번호를 다시 확인하려고합니다. 따라서 더 나은 사용자 경험을 만들려면 입력 값을 유지하는 것이 중요합니다. 따라서 반품시 HTML 페이지의 템플릿을 선택하는 것 외에이 매개 변수를 추가해야합니다.
return render_template("result.html", price1=price1, landedCost1=landedCost1, shippingCost1=shippingCost1, paymentCost1=paymentCost1, refundCost1=refundCost1, CPA1=CPA1, discount1=discount1, result=result)
HTML 템플릿 페이지
HTML 페이지는 계산기 레이아웃 및 디자인을 표시하는 프론트 엔드 및 사용자와의 상호 작용 블록입니다. HTML 및 CSS를 사용하여 웹 페이지를 구축하고 장식하는 방법에 관한 다른 기사를 발표하겠습니다. 그러나이 응용 프로그램에서 핵심은 수집 된 모든 데이터가 올바른 위치 인수와 관련 될 수 있는지 확인해야한다는 것입니다. 그렇지 않으면 계산 결과가 잘못 될 수 있습니다
따라서 볼 수 있듯이 각 입력 상자에는 이익 마진을 계산하는 데 사용하는 변수의 동일한 이름과 연결된 관련 이름 요소가 있습니다.
Full Python Script of eCommerce Profit & Loss Calculator
If you are interested in the full script of the eCommerce Profit & Loss Calculator, please subscribe to our newsletter by adding the message “Chapter 33”. We would send you the script immediately to your mailbox.
33 장 : OOP를 사용하여 전자 상거래 이익 마진 계산기를 만들 수 있기를 바랍니다. 당신이 그렇게했다면, 아래에 나열된 것들 중 하나를 수행하여 항상 우리의 채널을 도울 수 있기 때문에 우리를 지원하십시오.
- Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
- Follow and like my page Easy2Digital Facebook page
- 해시 태그 #easy2digital과 소셜 네트워크의 기사를 공유하십시오.
- Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
- Easy2Digital 최신 기사, 비디오 및 할인 코드를 받으려면 주간 뉴스 레터에 가입하십시오.
- Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)