diff --git a/tools.py b/tools.py index d691e41..560459d 100644 --- a/tools.py +++ b/tools.py @@ -4,6 +4,8 @@ from authentication import PasswordTools from views import View from sqlalchemy.orm import Session from sqlalchemy import select, update, insert, delete +from datetime import datetime, date + class Tools: @@ -159,7 +161,7 @@ class CustomerTools: self.view.display_results(result) return result - def create(self) -> None: + def create(self, user_id) -> None: """ Create a new customer with minimum information :return: None; creates object in DB @@ -170,6 +172,7 @@ class CustomerTools: email=customer['email'], phone=customer['phone'], company=customer['company'], + commercial_id=user_id, ) self.db.add(new_customer) self.db.commit() @@ -184,7 +187,7 @@ class CustomerTools: cust = self.db.get(Customer, my_id) item, value = self.view.prompt_for_customer_update() stmt = (update(Customer).where(Customer.id == my_id).values( - **{item: value})) + **{item: value}, last_update=datetime.now())) self.db.execute(stmt) self.db.commit() self.view.display_change(cust.name, item, value) @@ -253,15 +256,20 @@ class ContractTools: select(Contract).where(Contract.signed == 0)) self.view.display_results(result) - def create(self) -> None: + def create(self, + customer_options, + commercial_options) -> None: """ Create a new contracts with minimum information :return: None; creates object in DB """ - contract = self.view.prompt_for_contract() + contract = self.view.prompt_for_contract(customer_options, + commercial_options) + if not contract['amount']: + contract['amount'] = 0 new_contract = Contract( - customer=contract['customer'], - commercial=contract['commercial'], + customer_id=contract['customer'], + commercial_id=contract['commercial'], amount=contract['amount'], ) self.db.add(new_contract) diff --git a/views.py b/views.py index 4a714e1..7b19b5f 100644 --- a/views.py +++ b/views.py @@ -78,11 +78,13 @@ class View: } return self.prompt_for_update(options) - def prompt_for_contract(self) -> dict: + def prompt_for_contract(self, customer_options, commercial_options) -> dict: contract = {} print("** New contract **") - contract['customer'] = input("Customer (id) ? : ") - contract['commercial'] = input("Commercial (id) ") + print("Customer ? :") + contract['customer'] = return_menu(customer_options) + print("Commercial ? :") + contract['commercial'] = return_menu(commercial_options) contract['amount'] = input("Budget ? : ") return contract