diff --git a/barcodes/attributes/__init__.py b/barcodes/attributes/__init__.py index ee19563..b7bfd42 100644 --- a/barcodes/attributes/__init__.py +++ b/barcodes/attributes/__init__.py @@ -2,7 +2,9 @@ from .article_attribute_getter import ArticleAttributeGetter from .brand_attribute_getter import BrandAttributeGetter from .client_name_attribute_getter import ClientNameAttributeGetter from .color_attribute_getter import ColorAttributeGetter +from .company_name_attribute_getter import CompanyNameAttributeGetter from .composition_attribute_getter import CompositionAttributeGetter +from .inn_attribute_getter import InnAttributeGetter from .name_attribute_getter import NameAttributeGetter @@ -16,6 +18,10 @@ class AttributeWriterFactory: return ArticleAttributeGetter() case 'client.name': return ClientNameAttributeGetter() + case 'client.company_name': + return CompanyNameAttributeGetter() + case 'client.inn': + return InnAttributeGetter() case 'brand': return BrandAttributeGetter() case 'color': diff --git a/barcodes/attributes/company_name_attribute_getter.py b/barcodes/attributes/company_name_attribute_getter.py new file mode 100644 index 0000000..f9d038b --- /dev/null +++ b/barcodes/attributes/company_name_attribute_getter.py @@ -0,0 +1,11 @@ +from barcodes.attributes.base import BaseAttributeGetter +from models import Product, Client + + +class CompanyNameAttributeGetter(BaseAttributeGetter): + def get_value(self, product: Product): + client: Client = product.client + result = client.company_name + if not result: + result = '' + return result diff --git a/barcodes/attributes/inn_attribute_getter.py b/barcodes/attributes/inn_attribute_getter.py new file mode 100644 index 0000000..0e3cac2 --- /dev/null +++ b/barcodes/attributes/inn_attribute_getter.py @@ -0,0 +1,12 @@ +from barcodes.attributes.base import BaseAttributeGetter +from models import Product, Client, ClientDetails + + +class InnAttributeGetter(BaseAttributeGetter): + def get_value(self, product: Product): + client: Client = product.client + client_details: ClientDetails = client.details + result = client_details.inn + if not result: + result = '' + return result diff --git a/models/client.py b/models/client.py index cca67c5..34d3812 100644 --- a/models/client.py +++ b/models/client.py @@ -8,10 +8,18 @@ class Client(BaseModel): __tablename__ = 'clients' id = Column(Integer, autoincrement=True, primary_key=True, index=True) name = Column(String, nullable=False, unique=True, comment='Название клиента') + + # TODO replace with additional model + company_name = Column(String, + nullable=False, + server_default='', + comment='Название компании') + created_at = Column(DateTime, nullable=False, comment='Дата создания') products = relationship('Product', back_populates='client') - details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete') + details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete', + lazy='joined') barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True) barcode_template = relationship('BarcodeTemplate', lazy='selectin') diff --git a/schemas/client.py b/schemas/client.py index 10f319a..e40ffe2 100644 --- a/schemas/client.py +++ b/schemas/client.py @@ -21,6 +21,7 @@ class ClientDetailsSchema(CustomModelCamel): class ClientSchema(CustomModelCamel): id: int name: str + company_name: str barcode_template: BarcodeTemplateSchema | None = None details: ClientDetailsSchema | None = None