JavaScript
x
29
29
1
from Abstractions.Products import Products
2
from itertools import product
3
from Implementation.ProductsImplementation import ProductsImplementation
4
from Implementation.VendorImplementation import VendorImplementation
5
from Models.VendorSessionModel import VendorSessionModel
6
7
if __name__ == '__main__':
8
9
10
vendor = VendorImplementation()
11
username = input("Enter vendor name:")
12
password = input("Enter your password:")
13
login_res = vendor.login(username, password)
14
if login_res == False:
15
print("Not authorized Vendor")
16
else:
17
products = ProductsImplementation(username)
18
print("Enter Number of product you want to add:")
19
p = Products()
20
n= int(input())
21
22
for i in range(1, n+1):
23
product_name = input("Please Enter Product Name:")
24
product_type = input("Please Enter product type:")
25
available_quantity = input("Please enter avilable quantity:")
26
unit_price = input("please enter unit price:")
27
28
p.add_product()
29
Products Class code
JavaScript
1
6
1
class Products:
2
3
def add_product(self, product_name, product_type, available_quantity, unit_price):
4
"""This abstract method will be used to add products"""
5
pass
6
ProductsImplementation class code
JavaScript
1
14
14
1
class ProductsImplementation(Products):
2
def __init__(self, username):
3
self.product_model = ProductModel()
4
self.vendor_session = VendorSessionModel()
5
self._username = username
6
7
def add_product(self, product_name, product_type, available_quantity, unit_price):
8
if not self.vendor_session.check_login(self._username):
9
print("please login first")
10
return False
11
self.product_model.add_product(product_name,product_type,available_quantity,unit_price)
12
print(product_name + "added sucessfully")
13
14
Below is the error I get when I try to run this
JavaScript
1
5
1
Traceback (most recent call last):
2
File "e:psython_projectM01-W01-02-Ecommerce_vendor_managementDriver.py", line 28, in <module>
3
p.add_product()
4
TypeError: Products.add_product() missing 4 required positional arguments: 'product_name', 'product_type', 'available_quantity', and 'unit_price'**
5
Advertisement
Answer
You forgot to provide the arguments to the add_product
method. Change the last line to:
JavaScript
1
2
1
p.add_product(product_name, product_type, available_quantity, unit_price)
2