feat(JavaScript): Updated architecture for TableBasePage object with static row ID attribute attached for adding ID against each row added to DOM
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -17,7 +17,7 @@ from business_objects.region import Region
|
||||
from extensions import db
|
||||
# external
|
||||
from typing import ClassVar
|
||||
|
||||
from flask import jsonify
|
||||
|
||||
class Address(db.Model, Base):
|
||||
FLAG_ADDRESS_LINE_1: ClassVar[str] = 'address_line_1'
|
||||
@@ -59,6 +59,12 @@ class Address(db.Model, Base):
|
||||
address.id_address = query_row[6]
|
||||
address.id_region = query_row[7]
|
||||
return address
|
||||
@classmethod
|
||||
def from_DB_supplier(cls, query_row):
|
||||
address = cls()
|
||||
address.id_address = query_row[1]
|
||||
address.postcode = query_row[2]
|
||||
return address
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_ADDRESS}: {self.id_address}
|
||||
@@ -82,6 +88,8 @@ class Address(db.Model, Base):
|
||||
self.FLAG_COUNTY: self.county,
|
||||
self.FLAG_ACTIVE: 1 if av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') else 0
|
||||
}
|
||||
def to_json_str(self):
|
||||
return jsonify(self.to_json())
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
@@ -94,4 +102,4 @@ class Address(db.Model, Base):
|
||||
address.city = json[cls.FLAG_CITY],
|
||||
address.county = json[cls.FLAG_COUNTY],
|
||||
address.active = json[cls.FLAG_ACTIVE]
|
||||
return address
|
||||
return address
|
||||
@@ -27,14 +27,22 @@ class Base():
|
||||
FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = 'access_level_required'
|
||||
FLAG_ACTIVE: ClassVar[str] = 'active'
|
||||
FLAG_ADDRESS: ClassVar[str] = 'address'
|
||||
FLAG_ADDRESS_LINE_1: ClassVar[str] = 'address_line_1'
|
||||
FLAG_ADDRESS_LINE_2: ClassVar[str] = 'address_line_2'
|
||||
FLAG_CAN_ADMIN: ClassVar[str] = 'can_admin'
|
||||
FLAG_CAN_EDIT: ClassVar[str] = 'can_edit'
|
||||
FLAG_CAN_VIEW: ClassVar[str] = 'can_view'
|
||||
FLAG_CITY: ClassVar[str] = 'city'
|
||||
FLAG_CODE: ClassVar[str] = 'code'
|
||||
FLAG_COUNTY: ClassVar[str] = 'county'
|
||||
FLAG_CREATED_ON: ClassVar[str] = 'created_on'
|
||||
FLAG_CURRENCY: ClassVar[str] = 'currency'
|
||||
FLAG_CURRENCY_COST: ClassVar[str] = 'currency_cost'
|
||||
FLAG_DATE_FROM: ClassVar[str] = 'date_from'
|
||||
FLAG_DATE_TO: ClassVar[str] = 'date_to'
|
||||
FLAG_DESCRIPTION: ClassVar[str] = 'description'
|
||||
FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order'
|
||||
FLAG_EDIT: ClassVar[str] = 'edit'
|
||||
FLAG_EMAIL: ClassVar[str] = 'email'
|
||||
FLAG_FAX: ClassVar[str] = 'fax'
|
||||
FLAG_GUID: ClassVar[str] = 'guid'
|
||||
|
||||
@@ -90,6 +90,15 @@ class Currency(db.Model, Store_Base):
|
||||
currency.code = query_row[13]
|
||||
currency.symbol = query_row[14]
|
||||
return currency
|
||||
@classmethod
|
||||
def from_DB_supplier(cls, query_row):
|
||||
_m = 'Currency.from_DB_supplier'
|
||||
v_arg_type = 'class attribute'
|
||||
currency = cls()
|
||||
currency.id_currency = query_row[1]
|
||||
currency.symbol = query_row[2]
|
||||
currency.code = query_row[3]
|
||||
return currency
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id: {self.id_currency}
|
||||
|
||||
@@ -32,13 +32,18 @@ class Region(db.Model, Base):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Base.__init__(self)
|
||||
self.region = None
|
||||
|
||||
@classmethod
|
||||
def from_DB_stock_item(cls, query_row):
|
||||
plant = cls()
|
||||
plant.id_region = query_row[7]
|
||||
return plant
|
||||
region = cls()
|
||||
region.id_region = query_row[7]
|
||||
return region
|
||||
@classmethod
|
||||
def from_DB_supplier(cls, query_row):
|
||||
region = cls()
|
||||
region.id_region = query_row[2]
|
||||
region.name = query_row[3]
|
||||
return region
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_REGION}: {self.id_region}
|
||||
@@ -78,5 +83,4 @@ class Region(db.Model, Base):
|
||||
region.code = query_row[1]
|
||||
region.name = query_row[2]
|
||||
region.active = av.input_bool(query_row[3], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_region')
|
||||
region.display_order = query_row[4]
|
||||
return region
|
||||
|
||||
Binary file not shown.
Binary file not shown.
313
business_objects/store/manufacturing_purchase_order.py
Normal file
313
business_objects/store/manufacturing_purchase_order.py
Normal file
@@ -0,0 +1,313 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Manufacturing_Purchase_Order Business Object
|
||||
|
||||
Description:
|
||||
Business object for manufacturing_purchase_order
|
||||
"""
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.db_base import Get_Many_Parameters_Base
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from extensions import db
|
||||
# external
|
||||
from pydantic import BaseModel
|
||||
from typing import ClassVar, Optional
|
||||
from datetime import datetime
|
||||
|
||||
class Manufacturing_Purchase_Order(db.Model, Store_Base):
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_MANUFACTURING_PURCHASE_ORDER
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME
|
||||
# __tablename__ = 'Shop_Manufacturing_Purchase_Order_Temp'
|
||||
id_order = db.Column(db.Integer, primary_key=True)
|
||||
id_currency = db.Column(db.Integer)
|
||||
cost_total_local_VAT_excl = db.Column(db.Float)
|
||||
cost_total_local_VAT_incl = db.Column(db.Float)
|
||||
price_total_local_VAT_excl = db.Column(db.Float)
|
||||
price_total_local_VAT_incl = db.Column(db.Float)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by = db.Column(db.Integer)
|
||||
name = db.Column(db.String(255))
|
||||
# items: list = None
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
self.items = None
|
||||
@classmethod
|
||||
def from_DB_manufacturing_purchase_order(cls, query_row):
|
||||
manufacturing_purchase_order = cls()
|
||||
manufacturing_purchase_order.id_order = query_row[0]
|
||||
manufacturing_purchase_order.id_currency = query_row[1]
|
||||
manufacturing_purchase_order.cost_total_local_VAT_excl = query_row[2]
|
||||
manufacturing_purchase_order.cost_total_local_VAT_incl = query_row[3]
|
||||
manufacturing_purchase_order.price_total_local_VAT_excl = query_row[4]
|
||||
manufacturing_purchase_order.price_total_local_VAT_incl = query_row[5]
|
||||
manufacturing_purchase_order.active = av.input_bool(query_row[6], 'active', f'{cls.__name__}.from_DB_manufacturing_purchase_order')
|
||||
manufacturing_purchase_order.created_on = query_row[7]
|
||||
manufacturing_purchase_order.name = query_row[8]
|
||||
return manufacturing_purchase_order
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_MANUFACTURING_PURCHASE_ORDER}: {self.id_order},
|
||||
{self.ATTR_ID_CURRENCY}: {self.id_currency},
|
||||
{self.FLAG_COST_TOTAL_LOCAL_VAT_EXCL}: {self.cost_total_local_VAT_excl},
|
||||
{self.FLAG_COST_TOTAL_LOCAL_VAT_INCL}: {self.cost_total_local_VAT_incl},
|
||||
{self.FLAG_PRICE_TOTAL_LOCAL_VAT_EXCL}: {self.price_total_local_VAT_excl},
|
||||
{self.FLAG_PRICE_TOTAL_LOCAL_VAT_INCL}: {self.price_total_local_VAT_incl},
|
||||
{self.FLAG_ACTIVE}: {self.active},
|
||||
{self.FLAG_CREATED_ON}: {self.created_on},
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_MANUFACTURING_PURCHASE_ORDER: self.id_order,
|
||||
self.ATTR_ID_CURRENCY: self.id_currency,
|
||||
self.FLAG_COST_TOTAL_LOCAL_VAT_EXCL: self.cost_total_local_VAT_excl,
|
||||
self.FLAG_COST_TOTAL_LOCAL_VAT_INCL: self.cost_total_local_VAT_incl,
|
||||
self.FLAG_PRICE_TOTAL_LOCAL_VAT_EXCL: self.price_total_local_VAT_excl,
|
||||
self.FLAG_PRICE_TOTAL_LOCAL_VAT_INCL: self.price_total_local_VAT_incl,
|
||||
self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'),
|
||||
self.FLAG_CREATED_ON: self.created_on,
|
||||
self.FLAG_NAME: self.name,
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_order,
|
||||
'text': self.name,
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
manufacturing_purchase_order = cls()
|
||||
manufacturing_purchase_order.id_order = json[cls.ATTR_ID_MANUFACTURING_PURCHASE_ORDER]
|
||||
manufacturing_purchase_order.id_currency = json[cls.ATTR_ID_CURRENCY]
|
||||
manufacturing_purchase_order.cost_total_local_VAT_excl = json[cls.FLAG_COST_TOTAL_LOCAL_VAT_EXCL]
|
||||
manufacturing_purchase_order.cost_total_local_VAT_incl = json[cls.FLAG_COST_TOTAL_LOCAL_VAT_INCL]
|
||||
manufacturing_purchase_order.price_total_local_VAT_excl = json[cls.FLAG_PRICE_TOTAL_LOCAL_VAT_EXCL]
|
||||
manufacturing_purchase_order.price_total_local_VAT_incl = json[cls.FLAG_PRICE_TOTAL_LOCAL_VAT_INCL]
|
||||
manufacturing_purchase_order.active = json[cls.FLAG_ACTIVE]
|
||||
manufacturing_purchase_order.created_on = json[cls.FLAG_CREATED_ON]
|
||||
manufacturing_purchase_order.name = json[cls.FLAG_NAME]
|
||||
return manufacturing_purchase_order
|
||||
def get_items_preview_str(self):
|
||||
preview = ''
|
||||
if self.items is not None:
|
||||
for item in self.items:
|
||||
if preview != '':
|
||||
preview += '\n'
|
||||
preview += f'{item.name_permutation}{f" -(x{item.quantity_used})" if item.quantity_used > 0 else ""}{f" +(x{item.quantity_produced})" if item.quantity_produced > 0 else ""}'
|
||||
return preview
|
||||
|
||||
class Manufacturing_Purchase_Order_Product_Link(db.Model, Store_Base):
|
||||
FLAG_LATENCY_MANUFACTURE_DAYS: ClassVar[str] = 'latency_manufacture_days'
|
||||
FLAG_QUANTITY_PRODUCED: ClassVar[str] = 'quantity_produced'
|
||||
FLAG_QUANTITY_USED: ClassVar[str] = 'quantity_used'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME
|
||||
# __tablename__ = 'Shop_Manufacturing_Purchase_Order_Temp'
|
||||
id_link = db.Column(db.Integer, primary_key=True)
|
||||
id_order = db.Column(db.Integer)
|
||||
id_permutation = db.Column(db.Integer)
|
||||
id_unit_quantity = db.Column(db.Integer)
|
||||
name_permutation = db.Column(db.String(255))
|
||||
quantity_used = db.Column(db.Float)
|
||||
quantity_produced = db.Column(db.Float)
|
||||
latency_manufacture_days = db.Column(db.Integer)
|
||||
display_order = db.Column(db.Integer)
|
||||
cost_unit_local_VAT_excl = db.Column(db.Float)
|
||||
cost_unit_local_VAT_incl = db.Column(db.Float)
|
||||
price_unit_local_VAT_excl = db.Column(db.Float)
|
||||
price_unit_local_VAT_incl = db.Column(db.Float)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by = db.Column(db.Integer)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
@classmethod
|
||||
def from_DB_manufacturing_purchase_order(cls, query_row):
|
||||
link = cls()
|
||||
link.id_link = query_row[0]
|
||||
link.id_order = query_row[1]
|
||||
link.id_permutation = query_row[2]
|
||||
link.name_permutation = query_row[3]
|
||||
link.id_unit_quantity = query_row[4]
|
||||
link.quantity_used = query_row[5]
|
||||
link.quantity_produced = query_row[6]
|
||||
link.latency_manufacture_days = query_row[7]
|
||||
link.display_order = query_row[8]
|
||||
link.cost_unit_local_VAT_excl = query_row[9]
|
||||
link.cost_unit_local_VAT_incl = query_row[10]
|
||||
link.price_unit_local_VAT_excl = query_row[11]
|
||||
link.price_unit_local_VAT_incl = query_row[12]
|
||||
link.active = query_row[13]
|
||||
return link
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK}: {self.id_link},
|
||||
{self.ATTR_ID_MANUFACTURING_PURCHASE_ORDER}: {self.id_order},
|
||||
{self.ATTR_ID_PRODUCT_PERMUTATION}: {self.id_permutation},
|
||||
{self.FLAG_NAME}: {self.name_permutation},
|
||||
{self.ATTR_ID_UNIT_MEASUREMENT_QUANTITY}: {self.id_unit_quantity},
|
||||
{self.FLAG_QUANTITY_USED}: {self.quantity_used},
|
||||
{self.FLAG_QUANTITY_PRODUCED}: {self.quantity_produced},
|
||||
{self.FLAG_LATENCY_MANUFACTURE_DAYS}: {self.latency_manufacture_days},
|
||||
{self.FLAG_DISPLAY_ORDER}: {self.display_order},
|
||||
{self.FLAG_COST_UNIT_LOCAL_VAT_EXCL}: {self.cost_unit_local_VAT_excl},
|
||||
{self.FLAG_COST_UNIT_LOCAL_VAT_INCL}: {self.cost_unit_local_VAT_incl},
|
||||
{self.FLAG_PRICE_UNIT_LOCAL_VAT_EXCL}: {self.price_unit_local_VAT_excl},
|
||||
{self.FLAG_PRICE_UNIT_LOCAL_VAT_INCL}: {self.price_unit_local_VAT_incl},
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK: self.id_link,
|
||||
self.ATTR_ID_MANUFACTURING_PURCHASE_ORDER: self.id_order,
|
||||
self.ATTR_ID_PRODUCT_PERMUTATION: self.id_permutation,
|
||||
self.FLAG_NAME: self.name_permutation,
|
||||
self.ATTR_ID_UNIT_MEASUREMENT_QUANTITY: self.id_unit_quantity,
|
||||
self.FLAG_QUANTITY_USED: self.quantity_used,
|
||||
self.FLAG_QUANTITY_PRODUCED: self.quantity_produced,
|
||||
self.FLAG_LATENCY_MANUFACTURE_DAYS: self.latency_manufacture_days,
|
||||
self.FLAG_DISPLAY_ORDER: self.display_order,
|
||||
self.FLAG_COST_UNIT_LOCAL_VAT_EXCL: self.cost_unit_local_VAT_excl,
|
||||
self.FLAG_COST_UNIT_LOCAL_VAT_INCL: self.cost_unit_local_VAT_incl,
|
||||
self.FLAG_PRICE_UNIT_LOCAL_VAT_EXCL: self.price_unit_local_VAT_excl,
|
||||
self.FLAG_PRICE_UNIT_LOCAL_VAT_INCL: self.price_unit_local_VAT_incl,
|
||||
self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'),
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_order,
|
||||
'text': self.name_permutation,
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
link = cls()
|
||||
link.id_link = json[cls.ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK]
|
||||
link.id_order = json[cls.ATTR_ID_MANUFACTURING_PURCHASE_ORDER]
|
||||
link.id_permutation = json[cls.ATTR_ID_PRODUCT_PERMUTATION]
|
||||
link.name_permutation = json[cls.FLAG_NAME]
|
||||
link.id_unit_quantity = json[cls.ATTR_ID_UNIT_MEASUREMENT_QUANTITY]
|
||||
link.quantity_used = json[cls.FLAG_QUANTITY_USED]
|
||||
link.quantity_produced = json[cls.FLAG_QUANTITY_PRODUCED]
|
||||
link.latency_manufacture_days = json[cls.FLAG_LATENCY_MANUFACTURE_DAYS]
|
||||
link.display_order = json[cls.FLAG_DISPLAY_ORDER]
|
||||
link.cost_unit_local_VAT_excl = json[cls.FLAG_COST_UNIT_LOCAL_VAT_EXCL]
|
||||
link.cost_unit_local_VAT_incl = json[cls.FLAG_COST_UNIT_LOCAL_VAT_INCL]
|
||||
link.active = json[cls.FLAG_ACTIVE]
|
||||
return link
|
||||
|
||||
class Parameters_Manufacturing_Purchase_Order(Get_Many_Parameters_Base):
|
||||
a_get_all_order: bool
|
||||
a_get_inactive_order: bool
|
||||
a_ids_order: str
|
||||
a_ids_permutation: str
|
||||
a_date_from: Optional[datetime]
|
||||
a_date_to: Optional[datetime]
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
a_get_all_order = True,
|
||||
a_get_inactive_order = False,
|
||||
a_ids_order = '',
|
||||
a_ids_permutation = '',
|
||||
a_date_from = None,
|
||||
a_date_to = None
|
||||
)
|
||||
@classmethod
|
||||
def from_filters_manufacturing_purchase_order(cls, form):
|
||||
parameters = cls.get_default()
|
||||
parameters.a_get_inactive_order = form.active.data
|
||||
parameters.a_date_from = form.date_from.data
|
||||
parameters.a_date_to = form.date_to.data
|
||||
return parameters
|
||||
|
||||
class Manufacturing_Purchase_Order_Temp(db.Model, Store_Base):
|
||||
__tablename__: ClassVar[str] = 'Shop_Manufacturing_Purchase_Order_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_order: int = db.Column(db.Integer, primary_key=True)
|
||||
id_manufacturing: int = db.Column(db.Integer)
|
||||
id_currency: int = db.Column(db.Integer)
|
||||
active: bool = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@classmethod
|
||||
def from_manufacturing_purchase_order(cls, manufacturing_purchase_order):
|
||||
row = cls()
|
||||
row.id_order = manufacturing_purchase_order.id_order
|
||||
row.id_manufacturing = manufacturing_purchase_order.id_manufacturing
|
||||
row.id_currency = manufacturing_purchase_order.id_currency
|
||||
row.active = 1 if manufacturing_purchase_order.active else 0
|
||||
return row
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_order: {self.id_order}
|
||||
id_manufacturing: {self.id_manufacturing}
|
||||
id_currency: {self.id_currency}
|
||||
active: {self.active}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
|
||||
class Manufacturing_Purchase_Order_Product_Link_Temp(db.Model, Store_Base):
|
||||
__tablename__: ClassVar[str] = 'Shop_Manufacturing_Purchase_Order_Product_Link_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_link: int = db.Column(db.Integer, primary_key=True)
|
||||
id_order: int = db.Column(db.Integer)
|
||||
id_permutation: int = db.Column(db.Integer)
|
||||
id_unit_quantity: int = db.Column(db.Integer)
|
||||
quantity_used: float = db.Column(db.Float)
|
||||
quantity_produced: float = db.Column(db.Float)
|
||||
latency_manufacture_days: int = db.Column(db.Integer)
|
||||
display_order: int = db.Column(db.Integer)
|
||||
cost_unit_local_VAT_excl: float = db.Column(db.Float)
|
||||
cost_unit_local_VAT_incl: float = db.Column(db.Float)
|
||||
price_unit_local_VAT_excl: float = db.Column(db.Float)
|
||||
price_unit_local_VAT_incl: float = db.Column(db.Float)
|
||||
active: bool = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@classmethod
|
||||
def from_manufacturing_purchase_order_product_link(cls, manufacturing_purchase_order_product_link):
|
||||
row = cls()
|
||||
row.id_link = manufacturing_purchase_order_product_link.id_link
|
||||
row.id_order = manufacturing_purchase_order_product_link.id_order
|
||||
row.id_permutation = manufacturing_purchase_order_product_link.id_permutation
|
||||
row.id_unit_quantity = manufacturing_purchase_order_product_link.id_unit_quantity
|
||||
row.quantity_used = manufacturing_purchase_order_product_link.quantity_used
|
||||
row.quantity_produced = manufacturing_purchase_order_product_link.quantity_produced
|
||||
row.latency_manufacture_days = manufacturing_purchase_order_product_link.latency_manufacture_days
|
||||
row.display_order = manufacturing_purchase_order_product_link.display_order
|
||||
row.cost_unit_local_VAT_excl = manufacturing_purchase_order_product_link.cost_unit_local_VAT_excl
|
||||
row.cost_unit_local_VAT_incl = manufacturing_purchase_order_product_link.cost_unit_local_VAT_incl
|
||||
row.price_unit_local_VAT_excl = manufacturing_purchase_order_product_link.price_unit_local_VAT_excl
|
||||
row.price_unit_local_VAT_incl = manufacturing_purchase_order_product_link.price_unit_local_VAT_incl
|
||||
row.active = 1 if manufacturing_purchase_order_product_link.active else 0
|
||||
return row
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_link: {self.id_link}
|
||||
id_order: {self.id_order}
|
||||
id_permutation: {self.id_permutation}
|
||||
id_unit_quantity: {self.id_unit_quantity}
|
||||
quantity_used: {self.quantity_used}
|
||||
quantity_produced: {self.quantity_produced}
|
||||
latency_manufacture_days: {self.latency_manufacture_days}
|
||||
display_order: {self.display_order}
|
||||
cost_unit_local_VAT_excl: {self.cost_unit_local_VAT_excl}
|
||||
cost_unit_local_VAT_incl: {self.cost_unit_local_VAT_incl}
|
||||
price_unit_local_VAT_excl: {self.price_unit_local_VAT_excl}
|
||||
price_unit_local_VAT_incl: {self.price_unit_local_VAT_incl}
|
||||
active: {self.active}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
@@ -112,8 +112,8 @@ class Stock_Item(db.Model, Store_Base):
|
||||
stock_item.date_received = json[cls.FLAG_DATE_RECEIVED]
|
||||
stock_item.id_location_storage = json[cls.ATTR_ID_STORAGE_LOCATION]
|
||||
stock_item.id_currency_cost = json[cls.ATTR_ID_CURRENCY_COST]
|
||||
stock_item.cost_local_VAT_excl = json[cls.FLAG_COST_LOCAL_VAT_EXCL]
|
||||
stock_item.cost_local_VAT_incl = json[cls.FLAG_COST_LOCAL_VAT_INCL]
|
||||
stock_item.cost_local_VAT_excl = json[cls.FLAG_COST_UNIT_LOCAL_VAT_EXCL]
|
||||
stock_item.cost_local_VAT_incl = json[cls.FLAG_COST_UNIT_LOCAL_VAT_INCL]
|
||||
stock_item.is_sealed = json[cls.FLAG_IS_SEALED]
|
||||
stock_item.date_unsealed = json[cls.FLAG_DATE_UNSEALED]
|
||||
stock_item.date_expiration = json[cls.FLAG_DATE_EXPIRATION]
|
||||
@@ -150,8 +150,8 @@ class Stock_Item(db.Model, Store_Base):
|
||||
self.ATTR_ID_PRODUCT_CATEGORY: self.id_category,
|
||||
self.FLAG_STORAGE_LOCATION: self.storage_location.to_json(),
|
||||
self.FLAG_CURRENCY_COST: self.currency_cost.to_json(),
|
||||
self.FLAG_COST_LOCAL_VAT_EXCL: self.cost_local_VAT_excl,
|
||||
self.FLAG_COST_LOCAL_VAT_INCL: self.cost_local_VAT_incl,
|
||||
self.FLAG_COST_UNIT_LOCAL_VAT_EXCL: self.cost_local_VAT_excl,
|
||||
self.FLAG_COST_UNIT_LOCAL_VAT_INCL: self.cost_local_VAT_incl,
|
||||
}
|
||||
def has_permutations(self):
|
||||
return len(self.permutations) > 0
|
||||
|
||||
@@ -59,11 +59,13 @@ class I_Store_Base():
|
||||
class Store_Base(Base):
|
||||
# ATTR_ID_CURRENCY_COST: ClassVar[str] = 'id_currency_cost'
|
||||
ATTR_ID_CUSTOMER: ClassVar[str] = 'id_customer'
|
||||
ATTR_ID_CUSTOMER_ADDRESS: ClassVar[str] = 'id_address'
|
||||
ATTR_ID_CUSTOMER_SALES_ORDER: ClassVar[str] = 'id_customer_sales_order'
|
||||
ATTR_ID_DELIVERY_OPTION: ClassVar[str] = 'id_delivery_option'
|
||||
ATTR_ID_DISCOUNT: ClassVar[str] = 'id_discount'
|
||||
ATTR_ID_IMAGE: ClassVar[str] = 'id_image'
|
||||
ATTR_ID_MANUFACTURING_PURCHASE_ORDER: ClassVar[str] = 'id_manufacturing_purchase_order'
|
||||
ATTR_ID_MANUFACTURING_PURCHASE_ORDER: ClassVar[str] = 'id_order'
|
||||
ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK: ClassVar[str] = 'id_link'
|
||||
ATTR_ID_PLANT: ClassVar[str] = 'id_plant'
|
||||
ATTR_ID_PRODUCT: ClassVar[str] = 'id_product'
|
||||
ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = 'id_category'
|
||||
@@ -75,18 +77,29 @@ class Store_Base(Base):
|
||||
ATTR_ID_STOCK_ITEM: ClassVar[str] = 'id_stock_item'
|
||||
ATTR_ID_STORAGE_LOCATION: ClassVar[str] = 'id_location'
|
||||
ATTR_ID_SUPPLIER: ClassVar[str] = 'id_supplier'
|
||||
ATTR_ID_SUPPLIER_PURCHASE_ORDER: ClassVar[str] = 'id_supplier_purchase_order'
|
||||
FLAG_COST_LOCAL: ClassVar[str] = 'cost_local'
|
||||
FLAG_COST_LOCAL_VAT_EXCL: ClassVar[str] = FLAG_COST_LOCAL + '_vat_excl'
|
||||
FLAG_COST_LOCAL_VAT_INCL: ClassVar[str] = FLAG_COST_LOCAL + '_vat_incl'
|
||||
ATTR_ID_SUPPLIER_ADDRESS: ClassVar[str] = 'id_address'
|
||||
ATTR_ID_SUPPLIER_PURCHASE_ORDER: ClassVar[str] = 'id_order'
|
||||
ATTR_ID_SUPPLIER_PURCHASE_ORDER_PRODUCT_LINK: ClassVar[str] = 'id_link'
|
||||
ATTR_ID_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = 'id_unit_quantity'
|
||||
# FLAG_COST_LOCAL: ClassVar[str] = 'cost_local'
|
||||
FLAG_COST_TOTAL_LOCAL_VAT_EXCL: ClassVar[str] = 'cost_total_local_vat_excl'
|
||||
FLAG_COST_TOTAL_LOCAL_VAT_INCL: ClassVar[str] = 'cost_total_local_vat_incl'
|
||||
FLAG_COST_UNIT_LOCAL_VAT_EXCL: ClassVar[str] = 'cost_unit_local_vat_excl'
|
||||
FLAG_COST_UNIT_LOCAL_VAT_INCL: ClassVar[str] = 'cost_unit_local_vat_incl'
|
||||
FLAG_CUSTOMER: ClassVar[str] = 'customer'
|
||||
FLAG_CUSTOMER_ADDRESS: ClassVar[str] = 'customer_address'
|
||||
FLAG_CUSTOMER_SALES_ORDER: ClassVar[str] = 'customer_sales_order'
|
||||
FLAG_DELIVERY_OPTION: ClassVar[str] = 'delivery_option'
|
||||
FLAG_DISCOUNT: ClassVar[str] = 'discount'
|
||||
FLAG_HAS_VARIATIONS: ClassVar[str] = 'has_variations'
|
||||
FLAG_IS_OUT_OF_STOCK: ClassVar[str] = 'is_out_of_stock'
|
||||
FLAG_DISCOUNT: ClassVar[str] = 'discount'
|
||||
FLAG_LATENCY_DELIVERY_DAYS: ClassVar[str] = 'latency_delivery_days'
|
||||
FLAG_MANUFACTURING_PURCHASE_ORDER: ClassVar[str] = 'manufacturing_purchase_order'
|
||||
FLAG_PLANT: ClassVar[str] = 'plant'
|
||||
FLAG_PRICE_TOTAL_LOCAL_VAT_EXCL: ClassVar[str] = 'price_total_local_vat_excl'
|
||||
FLAG_PRICE_TOTAL_LOCAL_VAT_INCL: ClassVar[str] = 'price_total_local_vat_incl'
|
||||
FLAG_PRICE_UNIT_LOCAL_VAT_EXCL: ClassVar[str] = 'price_unit_local_vat_excl'
|
||||
FLAG_PRICE_UNIT_LOCAL_VAT_INCL: ClassVar[str] = 'price_unit_local_vat_incl'
|
||||
FLAG_PRODUCT: ClassVar[str] = 'product'
|
||||
FLAG_PRODUCT_CATEGORY: ClassVar[str] = 'product_category'
|
||||
FLAG_PRODUCT_IMAGE: ClassVar[str] = 'product_image'
|
||||
@@ -97,9 +110,12 @@ class Store_Base(Base):
|
||||
FLAG_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'product_variation_type'
|
||||
FLAG_QUANTITY_MIN: ClassVar[str] = 'quantity_min'
|
||||
FLAG_QUANTITY_MAX: ClassVar[str] = 'quantity_max'
|
||||
FLAG_QUANTITY_ORDERED: ClassVar[str] = 'quantity_ordered'
|
||||
FLAG_QUANTITY_RECEIVED: ClassVar[str] = 'quantity_received'
|
||||
FLAG_STOCK_ITEM: ClassVar[str] = 'stock_item'
|
||||
FLAG_STORAGE_LOCATION: ClassVar[str] = 'storage_location'
|
||||
FLAG_SUPPLIER: ClassVar[str] = 'supplier'
|
||||
FLAG_SUPPLIER_ADDRESS: ClassVar[str] = 'supplier_address'
|
||||
FLAG_SUPPLIER_PURCHASE_ORDER: ClassVar[str] = 'supplier_purchase_order'
|
||||
FLAG_TEXT: ClassVar[str] = 'text'
|
||||
FLAG_VALUE_TEXT: ClassVar[str] = 'value_text'
|
||||
|
||||
@@ -12,6 +12,9 @@ Business object for supplier
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.store.supplier_address import Supplier_Address
|
||||
from business_objects.currency import Currency
|
||||
from business_objects.db_base import Get_Many_Parameters_Base
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from extensions import db
|
||||
# external
|
||||
@@ -27,12 +30,11 @@ class Supplier(db.Model, Store_Base):
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME
|
||||
__tablename__ = 'Shop_Supplier_Temp'
|
||||
id_supplier = db.Column(db.Integer, primary_key=True)
|
||||
id_address = db.Column(db.Integer)
|
||||
# id_address = db.Column(db.Integer)
|
||||
id_currency = db.Column(db.Integer)
|
||||
name_company = db.Column(db.String(255))
|
||||
name_contact = db.Column(db.String(255))
|
||||
department_contact = db.Column(db.String(255))
|
||||
# address
|
||||
phone_number = db.Column(db.String(50))
|
||||
fax = db.Column(db.String(50))
|
||||
email = db.Column(db.String(255))
|
||||
@@ -43,26 +45,29 @@ class Supplier(db.Model, Store_Base):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
self.addresses = []
|
||||
self.currency = None
|
||||
@classmethod
|
||||
def from_DB_supplier(cls, query_row):
|
||||
supplier = cls()
|
||||
supplier.id_supplier = query_row[0]
|
||||
supplier.id_address = query_row[1]
|
||||
supplier.id_currency = query_row[2]
|
||||
supplier.name_company = query_row[3]
|
||||
supplier.name_contact = query_row[4]
|
||||
supplier.department_contact = query_row[5]
|
||||
supplier.phone_number = query_row[6]
|
||||
supplier.fax = query_row[7]
|
||||
supplier.email = query_row[8]
|
||||
supplier.website = query_row[9]
|
||||
supplier.active = query_row[10]
|
||||
# supplier.id_address = query_row[1]
|
||||
# supplier.address = Supplier_Address.from_DB_supplier(query_row)
|
||||
supplier.id_currency = query_row[1]
|
||||
supplier.currency = Currency.from_DB_supplier(query_row)
|
||||
supplier.name_company = query_row[4]
|
||||
supplier.name_contact = query_row[5]
|
||||
supplier.department_contact = query_row[6]
|
||||
supplier.phone_number = query_row[7]
|
||||
supplier.fax = query_row[8]
|
||||
supplier.email = query_row[9]
|
||||
supplier.website = query_row[10]
|
||||
supplier.active = av.input_bool(query_row[11], 'active', f'{cls.__name__}.from_DB_supplier')
|
||||
return supplier
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id: {self.id_supplier},
|
||||
id_address: {self.id_address},
|
||||
id_currency: {self.id_currency},
|
||||
name_company: {self.name_company},
|
||||
name_contact: {self.name_contact},
|
||||
@@ -72,12 +77,13 @@ fax: {self.fax},
|
||||
email: {self.email},
|
||||
website: {self.website},
|
||||
active: {self.active},
|
||||
addresses: {self.addresses}
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_SUPPLIER: self.id_supplier,
|
||||
self.ATTR_ID_ADDRESS: self.id_address,
|
||||
# self.ATTR_ID_ADDRESS: self.id_address,
|
||||
self.ATTR_ID_CURRENCY: self.id_currency,
|
||||
self.FLAG_NAME_COMPANY: self.name_company,
|
||||
self.FLAG_NAME_CONTACT: self.name_contact,
|
||||
@@ -98,7 +104,6 @@ active: {self.active},
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
supplier = cls()
|
||||
supplier.id_supplier = json[cls.ATTR_ID_SUPPLIER]
|
||||
supplier.id_address = json[cls.ATTR_ID_ADDRESS]
|
||||
supplier.id_currency = json[cls.ATTR_ID_CURRENCY]
|
||||
supplier.name_company = json[cls.FLAG_NAME_COMPANY]
|
||||
supplier.name_contact = json[cls.FLAG_NAME_CONTACT]
|
||||
@@ -108,4 +113,78 @@ active: {self.active},
|
||||
supplier.email = json[cls.FLAG_EMAIL]
|
||||
supplier.website = json[cls.FLAG_WEBSITE]
|
||||
supplier.active = json[cls.FLAG_ACTIVE]
|
||||
addresses = json.get(cls.FLAG_SUPPLIER_ADDRESS, [])
|
||||
supplier.addresses = [Supplier_Address.from_json(address) for address in addresses]
|
||||
return supplier
|
||||
def get_address_active(self):
|
||||
for address in self.addresses:
|
||||
if address.active:
|
||||
return address
|
||||
return Supplier_Address()
|
||||
address = Supplier_Address()
|
||||
address.postcode = ''
|
||||
return address
|
||||
|
||||
class Parameters_Supplier(Get_Many_Parameters_Base):
|
||||
a_get_all_supplier: bool
|
||||
a_get_inactive_supplier: bool
|
||||
a_ids_supplier: str
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
a_get_all_supplier = True,
|
||||
a_get_inactive_supplier = False,
|
||||
a_ids_supplier = '',
|
||||
)
|
||||
@classmethod
|
||||
def from_filters_supplier(cls, form):
|
||||
parameters = cls.get_default()
|
||||
parameters.a_get_inactive_supplier = form.active.data
|
||||
return parameters
|
||||
|
||||
class Supplier_Temp(db.Model, Store_Base):
|
||||
__tablename__: ClassVar[str] = 'Shop_Supplier_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_supplier: int = db.Column(db.Integer, primary_key=True)
|
||||
id_currency: int = db.Column(db.Integer)
|
||||
# id_address: int = db.Column(db.Integer)
|
||||
name_company: str = db.Column(db.String(255))
|
||||
name_contact: str = db.Column(db.String(255))
|
||||
department_contact: str = db.Column(db.String(255))
|
||||
phone_number: str = db.Column(db.String(50))
|
||||
fax: str = db.Column(db.String(50))
|
||||
email: str = db.Column(db.String(255))
|
||||
website: str = db.Column(db.String(255))
|
||||
active: bool = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@classmethod
|
||||
def from_supplier(cls, supplier):
|
||||
row = cls()
|
||||
row.id_supplier = supplier.id_supplier
|
||||
row.id_currency = supplier.id_currency
|
||||
# row.id_address = supplier.id_address
|
||||
row.name_company = supplier.name_company
|
||||
row.name_contact = supplier.name_contact
|
||||
row.department_contact = supplier.department_contact
|
||||
row.phone_number = supplier.phone_number
|
||||
row.fax = supplier.fax
|
||||
row.email = supplier.email
|
||||
row.website = supplier.website
|
||||
row.active = 1 if supplier.active else 0
|
||||
return row
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_supplier: {self.id_supplier}
|
||||
id_currency: {self.id_currency}
|
||||
name_company: {self.name_company}
|
||||
name_contact: {self.name_contact}
|
||||
department_contact: {self.department_contact}
|
||||
phone_number: {self.phone_number}
|
||||
fax: {self.fax}
|
||||
email: {self.email}
|
||||
website: {self.website}
|
||||
active: {self.active}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
145
business_objects/store/supplier_address.py
Normal file
145
business_objects/store/supplier_address.py
Normal file
@@ -0,0 +1,145 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Supplier Address Business Object
|
||||
|
||||
Description:
|
||||
Business object for supplier address
|
||||
"""
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from business_objects.region import Region
|
||||
from extensions import db
|
||||
# external
|
||||
from typing import ClassVar
|
||||
from flask import jsonify
|
||||
|
||||
class Supplier_Address(db.Model, Store_Base):
|
||||
FLAG_ADDRESS_LINE_1: ClassVar[str] = 'address_line_1'
|
||||
FLAG_ADDRESS_LINE_2: ClassVar[str] = 'address_line_2'
|
||||
FLAG_CITY: ClassVar[str] = 'city'
|
||||
FLAG_COUNTY: ClassVar[str] = 'county'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_ADDRESS
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_POSTCODE
|
||||
__tablename__ = 'Shop_Supplier_Address'
|
||||
id_address = db.Column(db.Integer, primary_key=True)
|
||||
id_supplier = db.Column(db.Integer)
|
||||
id_region = db.Column(db.Integer)
|
||||
postcode = db.Column(db.String(20))
|
||||
address_line_1 = db.Column(db.String(256))
|
||||
address_line_2 = db.Column(db.String(256))
|
||||
city = db.Column(db.String(256))
|
||||
county = db.Column(db.String(256))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
# region = None
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
self.region = Region()
|
||||
@classmethod
|
||||
def from_DB_supplier(cls, query_row):
|
||||
address = cls()
|
||||
address.id_supplier = query_row[0]
|
||||
address.id_address = query_row[1]
|
||||
address.id_region = query_row[2]
|
||||
address.region = Region.from_DB_supplier(query_row)
|
||||
address.postcode = query_row[4]
|
||||
address.address_line_1 = query_row[5]
|
||||
address.address_line_2 = query_row[6]
|
||||
address.city = query_row[7]
|
||||
address.county = query_row[8]
|
||||
address.active = av.input_bool(query_row[9], 'active', f'{cls.__name__}.from_DB_supplier')
|
||||
|
||||
return address
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_ADDRESS}: {self.id_address}
|
||||
{self.ATTR_ID_SUPPLIER}: {self.id_supplier}
|
||||
{self.FLAG_REGION}: {self.region}
|
||||
{self.FLAG_POSTCODE}: {self.postcode}
|
||||
{self.FLAG_ADDRESS_LINE_1}: {self.address_line_1}
|
||||
{self.FLAG_ADDRESS_LINE_2}: {self.address_line_2}
|
||||
{self.FLAG_CITY}: {self.city}
|
||||
{self.FLAG_COUNTY}: {self.county}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
'''
|
||||
def to_json(self):
|
||||
print(f'{self.__class__.__name__}.to_json\n{self.__dict__}\n{self}')
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_ADDRESS: self.id_address,
|
||||
self.ATTR_ID_SUPPLIER: self.id_supplier,
|
||||
self.FLAG_REGION: self.region.to_json(),
|
||||
self.FLAG_POSTCODE: self.postcode,
|
||||
self.FLAG_ADDRESS_LINE_1: self.address_line_1,
|
||||
self.FLAG_ADDRESS_LINE_2: self.address_line_2,
|
||||
self.FLAG_CITY: self.city,
|
||||
self.FLAG_COUNTY: self.county,
|
||||
self.FLAG_ACTIVE: 1 if av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') else 0
|
||||
}
|
||||
def to_json_str(self):
|
||||
return jsonify(self.to_json())
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
address = cls()
|
||||
address.id_address = json[cls.ATTR_ID_ADDRESS]
|
||||
address.id_supplier = json[cls.ATTR_ID_SUPPLIER]
|
||||
address.id_region = json[cls.ATTR_ID_REGION]
|
||||
address.region = Region()
|
||||
address.region.id_region = json[cls.ATTR_ID_REGION]
|
||||
address.postcode = json[cls.FLAG_POSTCODE]
|
||||
address.address_line_1 = json[cls.FLAG_ADDRESS_LINE_1]
|
||||
address.address_line_2 = json.get(cls.FLAG_ADDRESS_LINE_2, '')
|
||||
address.city = json[cls.FLAG_CITY]
|
||||
address.county = json[cls.FLAG_COUNTY]
|
||||
address.active = json[cls.FLAG_ACTIVE]
|
||||
return address
|
||||
|
||||
|
||||
class Supplier_Address_Temp(db.Model, Store_Base):
|
||||
__tablename__: ClassVar[str] = 'Shop_Supplier_Address_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_address: int = db.Column(db.Integer, primary_key=True)
|
||||
id_supplier: int = db.Column(db.Integer)
|
||||
id_region: int = db.Column(db.Integer)
|
||||
postcode: str = db.Column(db.String(20))
|
||||
address_line_1: str = db.Column(db.String(256))
|
||||
address_line_2: str = db.Column(db.String(256))
|
||||
city: str = db.Column(db.String(256))
|
||||
county: str = db.Column(db.String(256))
|
||||
active: bool = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@classmethod
|
||||
def from_supplier_address(cls, address):
|
||||
row = cls()
|
||||
row.id_address = address.id_address
|
||||
row.id_supplier = address.id_supplier
|
||||
row.id_region = address.id_region
|
||||
row.postcode = address.postcode
|
||||
row.address_line_1 = address.address_line_1
|
||||
row.address_line_2 = address.address_line_2
|
||||
row.city = address.city
|
||||
row.county = address.county
|
||||
row.active = 1 if address.active else 0
|
||||
return row
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_address: {self.id_address}
|
||||
id_supplier: {self.id_supplier}
|
||||
id_region: {self.id_region}
|
||||
postcode: {self.postcode}
|
||||
address_line_1: {self.address_line_1}
|
||||
address_line_2: {self.address_line_2}
|
||||
city: {self.city}
|
||||
county: {self.county}
|
||||
active: {self.active}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
289
business_objects/store/supplier_purchase_order.py
Normal file
289
business_objects/store/supplier_purchase_order.py
Normal file
@@ -0,0 +1,289 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Supplier_Purchase_Order Business Object
|
||||
|
||||
Description:
|
||||
Business object for supplier_purchase_order
|
||||
"""
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.db_base import Get_Many_Parameters_Base
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from extensions import db
|
||||
# external
|
||||
from pydantic import BaseModel
|
||||
from typing import ClassVar, Optional
|
||||
from datetime import datetime
|
||||
|
||||
class Supplier_Purchase_Order(db.Model, Store_Base):
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_SUPPLIER_PURCHASE_ORDER
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME
|
||||
# __tablename__ = 'Shop_Supplier_Purchase_Order_Temp'
|
||||
id_order = db.Column(db.Integer, primary_key=True)
|
||||
id_supplier = db.Column(db.Integer)
|
||||
id_currency = db.Column(db.Integer)
|
||||
cost_total_local_VAT_excl = db.Column(db.Float)
|
||||
cost_total_local_VAT_incl = db.Column(db.Float)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by = db.Column(db.Integer)
|
||||
name = db.Column(db.String(255))
|
||||
# items: list = None
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
self.items = None
|
||||
@classmethod
|
||||
def from_DB_supplier_purchase_order(cls, query_row):
|
||||
supplier_purchase_order = cls()
|
||||
supplier_purchase_order.id_order = query_row[0]
|
||||
supplier_purchase_order.id_supplier = query_row[1]
|
||||
supplier_purchase_order.id_currency = query_row[2]
|
||||
supplier_purchase_order.cost_total_local_VAT_excl = query_row[3]
|
||||
supplier_purchase_order.cost_total_local_VAT_incl = query_row[4]
|
||||
supplier_purchase_order.active = av.input_bool(query_row[5], 'active', f'{cls.__name__}.from_DB_supplier_purchase_order')
|
||||
supplier_purchase_order.created_on = query_row[6]
|
||||
supplier_purchase_order.name = query_row[7]
|
||||
return supplier_purchase_order
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_SUPPLIER_PURCHASE_ORDER}: {self.id_order},
|
||||
{self.ATTR_ID_SUPPLIER}: {self.id_supplier},
|
||||
{self.ATTR_ID_CURRENCY}: {self.id_currency},
|
||||
{self.FLAG_COST_TOTAL_LOCAL_VAT_EXCL}: {self.cost_total_local_VAT_excl},
|
||||
{self.FLAG_COST_TOTAL_LOCAL_VAT_INCL}: {self.cost_total_local_VAT_incl},
|
||||
{self.FLAG_ACTIVE}: {self.active},
|
||||
{self.FLAG_CREATED_ON}: {self.created_on},
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_SUPPLIER_PURCHASE_ORDER: self.id_order,
|
||||
self.ATTR_ID_SUPPLIER: self.id_supplier,
|
||||
self.ATTR_ID_CURRENCY: self.id_currency,
|
||||
self.FLAG_COST_TOTAL_LOCAL_VAT_EXCL: self.cost_total_local_VAT_excl,
|
||||
self.FLAG_COST_TOTAL_LOCAL_VAT_INCL: self.cost_total_local_VAT_incl,
|
||||
self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'),
|
||||
self.FLAG_CREATED_ON: self.created_on,
|
||||
self.FLAG_NAME: self.name,
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_order,
|
||||
'text': self.name,
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
supplier_purchase_order = cls()
|
||||
supplier_purchase_order.id_order = json[cls.ATTR_ID_SUPPLIER_PURCHASE_ORDER]
|
||||
supplier_purchase_order.id_supplier = json[cls.ATTR_ID_SUPPLIER]
|
||||
supplier_purchase_order.id_currency = json[cls.ATTR_ID_CURRENCY]
|
||||
supplier_purchase_order.cost_total_local_VAT_excl = json[cls.FLAG_COST_TOTAL_LOCAL_VAT_EXCL]
|
||||
supplier_purchase_order.cost_total_local_VAT_incl = json[cls.FLAG_COST_TOTAL_LOCAL_VAT_INCL]
|
||||
supplier_purchase_order.active = json[cls.FLAG_ACTIVE]
|
||||
supplier_purchase_order.created_on = json[cls.FLAG_CREATED_ON]
|
||||
supplier_purchase_order.name = json[cls.FLAG_NAME]
|
||||
return supplier_purchase_order
|
||||
|
||||
class Supplier_Purchase_Order_Product_Link(db.Model, Store_Base):
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_SUPPLIER_PURCHASE_ORDER_PRODUCT_LINK
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME
|
||||
__tablename__ = 'Shop_Supplier_Purchase_Order_Temp'
|
||||
id_link = db.Column(db.Integer, primary_key=True)
|
||||
id_order = db.Column(db.Integer)
|
||||
id_permutation = db.Column(db.Integer)
|
||||
id_unit_quantity = db.Column(db.Integer)
|
||||
name_permutation = db.Column(db.String(255))
|
||||
quantity_ordered = db.Column(db.Float)
|
||||
quantity_received = db.Column(db.Float)
|
||||
latency_delivery_days = db.Column(db.Integer)
|
||||
display_order = db.Column(db.Integer)
|
||||
cost_total_local_VAT_excl = db.Column(db.Float)
|
||||
cost_total_local_VAT_incl = db.Column(db.Float)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by = db.Column(db.Integer)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
@classmethod
|
||||
def from_DB_supplier_purchase_order(cls, query_row):
|
||||
link = cls()
|
||||
link.id_link = query_row[0]
|
||||
link.id_order = query_row[1]
|
||||
link.id_permutation = query_row[2]
|
||||
link.name_permutation = query_row[3]
|
||||
link.id_unit_quantity = query_row[4]
|
||||
link.quantity_ordered = query_row[5]
|
||||
link.quantity_received = query_row[6]
|
||||
link.latency_delivery_days = query_row[7]
|
||||
link.display_order = query_row[8]
|
||||
link.cost_total_local_VAT_excl = query_row[9]
|
||||
link.cost_total_local_VAT_incl = query_row[10]
|
||||
link.active = query_row[11]
|
||||
return link
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.ATTR_ID_SUPPLIER_PURCHASE_ORDER_PRODUCT_LINK}: {self.id_link},
|
||||
{self.ATTR_ID_SUPPLIER_PURCHASE_ORDER}: {self.id_order},
|
||||
{self.ATTR_ID_PRODUCT_PERMUTATION}: {self.id_permutation},
|
||||
{self.FLAG_NAME}: {self.name_permutation},
|
||||
{self.ATTR_ID_UNIT_MEASUREMENT_QUANTITY}: {self.id_unit_quantity},
|
||||
{self.FLAG_QUANTITY_ORDERED}: {self.quantity_ordered},
|
||||
{self.FLAG_QUANTITY_RECEIVED}: {self.quantity_received},
|
||||
{self.FLAG_LATENCY_DELIVERY_DAYS}: {self.latency_delivery_days},
|
||||
{self.FLAG_DISPLAY_ORDER}: {self.display_order},
|
||||
{self.FLAG_COST_TOTAL_LOCAL_VAT_EXCL}: {self.cost_total_local_VAT_excl},
|
||||
{self.FLAG_COST_TOTAL_LOCAL_VAT_INCL}: {self.cost_total_local_VAT_incl},
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_SUPPLIER_PURCHASE_ORDER_PRODUCT_LINK: self.id_link,
|
||||
self.ATTR_ID_SUPPLIER_PURCHASE_ORDER: self.id_order,
|
||||
self.ATTR_ID_PRODUCT_PERMUTATION: self.id_permutation,
|
||||
self.FLAG_NAME: self.name_permutation,
|
||||
self.ATTR_ID_UNIT_MEASUREMENT_QUANTITY: self.id_unit_quantity,
|
||||
self.FLAG_QUANTITY_ORDERED: self.quantity_ordered,
|
||||
self.FLAG_QUANTITY_RECEIVED: self.quantity_received,
|
||||
self.FLAG_LATENCY_DELIVERY_DAYS: self.latency_delivery_days,
|
||||
self.FLAG_DISPLAY_ORDER: self.display_order,
|
||||
self.FLAG_COST_TOTAL_LOCAL_VAT_EXCL: self.cost_total_local_VAT_excl,
|
||||
self.FLAG_COST_TOTAL_LOCAL_VAT_INCL: self.cost_total_local_VAT_incl,
|
||||
self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'),
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_order,
|
||||
'text': self.name_permutation,
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
link = cls()
|
||||
link.id_link = json[cls.ATTR_ID_SUPPLIER_PURCHASE_ORDER_PRODUCT_LINK]
|
||||
link.id_order = json[cls.ATTR_ID_SUPPLIER_PURCHASE_ORDER]
|
||||
link.id_permutation = json[cls.ATTR_ID_PRODUCT_PERMUTATION]
|
||||
link.name_permutation = json[cls.FLAG_NAME]
|
||||
link.id_unit_quantity = json[cls.ATTR_ID_UNIT_MEASUREMENT_QUANTITY]
|
||||
link.quantity_ordered = json[cls.FLAG_QUANTITY_ORDERED]
|
||||
link.quantity_received = json[cls.FLAG_QUANTITY_RECEIVED]
|
||||
link.latency_delivery_days = json[cls.FLAG_LATENCY_DELIVERY_DAYS]
|
||||
link.display_order = json[cls.FLAG_DISPLAY_ORDER]
|
||||
link.cost_total_local_VAT_excl = json[cls.FLAG_COST_TOTAL_LOCAL_VAT_EXCL]
|
||||
link.cost_total_local_VAT_incl = json[cls.FLAG_COST_TOTAL_LOCAL_VAT_INCL]
|
||||
link.active = json[cls.FLAG_ACTIVE]
|
||||
return link
|
||||
|
||||
class Parameters_Supplier_Purchase_Order(Get_Many_Parameters_Base):
|
||||
a_get_all_supplier: bool
|
||||
a_get_inactive_supplier: bool
|
||||
a_ids_supplier: str
|
||||
a_get_all_order: bool
|
||||
a_get_inactive_order: bool
|
||||
a_ids_order: str
|
||||
a_ids_permutation: str
|
||||
a_date_from: Optional[datetime]
|
||||
a_date_to: Optional[datetime]
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
a_get_all_supplier = True,
|
||||
a_get_inactive_supplier = False,
|
||||
a_ids_supplier = '',
|
||||
a_get_all_order = True,
|
||||
a_get_inactive_order = False,
|
||||
a_ids_order = '',
|
||||
a_ids_permutation = '',
|
||||
a_date_from = None,
|
||||
a_date_to = None
|
||||
)
|
||||
@classmethod
|
||||
def from_filters_supplier_purchase_order(cls, form):
|
||||
parameters = cls.get_default()
|
||||
parameters.a_get_inactive_order = form.active.data
|
||||
parameters.a_date_from = form.date_from.data
|
||||
parameters.a_date_to = form.date_to.data
|
||||
return parameters
|
||||
|
||||
class Supplier_Purchase_Order_Temp(db.Model, Store_Base):
|
||||
__tablename__: ClassVar[str] = 'Shop_Supplier_Purchase_Order_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_order: int = db.Column(db.Integer, primary_key=True)
|
||||
id_supplier: int = db.Column(db.Integer)
|
||||
id_currency: int = db.Column(db.Integer)
|
||||
active: bool = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@classmethod
|
||||
def from_supplier_purchase_order(cls, supplier_purchase_order):
|
||||
row = cls()
|
||||
row.id_order = supplier_purchase_order.id_order
|
||||
row.id_supplier = supplier_purchase_order.id_supplier
|
||||
row.id_currency = supplier_purchase_order.id_currency
|
||||
row.active = 1 if supplier_purchase_order.active else 0
|
||||
return row
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_order: {self.id_order}
|
||||
id_supplier: {self.id_supplier}
|
||||
id_currency: {self.id_currency}
|
||||
active: {self.active}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
|
||||
class Supplier_Purchase_Order_Product_Link_Temp(db.Model, Store_Base):
|
||||
__tablename__: ClassVar[str] = 'Shop_Supplier_Purchase_Order_Product_Link_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_link: int = db.Column(db.Integer, primary_key=True)
|
||||
id_order: int = db.Column(db.Integer)
|
||||
id_permutation: int = db.Column(db.Integer)
|
||||
id_unit_quantity: int = db.Column(db.Integer)
|
||||
quantity_ordered: float = db.Column(db.Float)
|
||||
quantity_received: float = db.Column(db.Float)
|
||||
latency_delivery_days: int = db.Column(db.Integer)
|
||||
display_order: int = db.Column(db.Integer)
|
||||
cost_total_local_VAT_excl: float = db.Column(db.Float)
|
||||
cost_total_local_VAT_incl: float = db.Column(db.Float)
|
||||
active: bool = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@classmethod
|
||||
def from_supplier_purchase_order_product_link(cls, supplier_purchase_order_product_link):
|
||||
row = cls()
|
||||
row.id_link = supplier_purchase_order_product_link.id_link
|
||||
row.id_order = supplier_purchase_order_product_link.id_order
|
||||
row.id_permutation = supplier_purchase_order_product_link.id_permutation
|
||||
row.id_unit_quantity = supplier_purchase_order_product_link.id_unit_quantity
|
||||
row.quantity_ordered = supplier_purchase_order_product_link.quantity_ordered
|
||||
row.quantity_received = supplier_purchase_order_product_link.quantity_received
|
||||
row.latency_delivery_days = supplier_purchase_order_product_link.latency_delivery_days
|
||||
row.display_order = supplier_purchase_order_product_link.display_order
|
||||
row.cost_total_local_VAT_excl = supplier_purchase_order_product_link.cost_total_local_VAT_excl
|
||||
row.cost_total_local_VAT_incl = supplier_purchase_order_product_link.cost_total_local_VAT_incl
|
||||
row.active = 1 if supplier_purchase_order_product_link.active else 0
|
||||
return row
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_link: {self.id_link}
|
||||
id_order: {self.id_order}
|
||||
id_permutation: {self.id_permutation}
|
||||
id_unit_quantity: {self.id_unit_quantity}
|
||||
quantity_ordered: {self.quantity_ordered}
|
||||
quantity_received: {self.quantity_received}
|
||||
latency_delivery_days: {self.latency_delivery_days}
|
||||
display_order: {self.display_order}
|
||||
cost_total_local_VAT_excl: {self.cost_total_local_VAT_excl}
|
||||
cost_total_local_VAT_incl: {self.cost_total_local_VAT_incl}
|
||||
active: {self.active}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
Reference in New Issue
Block a user