Chore: Changed the Section Printer from Menu Categories to Sale Categories. This is more logical, in the older software, there as no concept of sale categories so menu categories was used.

This should make the whole thing much easier to update and read.
This commit is contained in:
Amritanshu Agrawal 2021-09-04 12:57:56 +05:30
parent 4a12ee0834
commit 63dfe05044
14 changed files with 124 additions and 63 deletions

View File

@ -0,0 +1,73 @@
"""section printer
Revision ID: 81d94c5223a7
Revises: c123dbf9c659
Create Date: 2021-08-17 12:10:01.082632
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy import column, table
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "81d94c5223a7"
down_revision = "c123dbf9c659"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
sp = table(
"section_printers",
column("id", postgresql.UUID(as_uuid=True)),
)
op.execute(sp.delete())
op.add_column("section_printers", sa.Column("sale_category_id", postgresql.UUID(as_uuid=True), nullable=True))
op.drop_constraint("uq_section_printers_menu_category_id", "section_printers", type_="unique")
op.create_unique_constraint(
op.f("uq_section_printers_sale_category_id"), "section_printers", ["sale_category_id", "section_id"]
)
op.drop_constraint("fk_section_printers_menu_category_id_menu_categories", "section_printers", type_="foreignkey")
op.create_foreign_key(
op.f("fk_section_printers_sale_category_id_sale_categories"),
"section_printers",
"sale_categories",
["sale_category_id"],
["id"],
)
op.drop_column("section_printers", "menu_category_id")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
sp = table(
"section_printers",
column("id", postgresql.UUID(as_uuid=True)),
)
op.execute(sp.delete())
op.add_column(
"section_printers", sa.Column("menu_category_id", postgresql.UUID(), autoincrement=False, nullable=True)
)
op.drop_constraint(
op.f("fk_section_printers_sale_category_id_sale_categories"), "section_printers", type_="foreignkey"
)
op.create_foreign_key(
"fk_section_printers_menu_category_id_menu_categories",
"section_printers",
"menu_categories",
["menu_category_id"],
["id"],
)
op.drop_constraint(op.f("uq_section_printers_sale_category_id"), "section_printers", type_="unique")
op.create_unique_constraint(
"uq_section_printers_menu_category_id", "section_printers", ["menu_category_id", "section_id"]
)
op.drop_column("section_printers", "sale_category_id")
# ### end Alembic commands ###

View File

@ -8,30 +8,30 @@ from sqlalchemy.orm import relationship
class SectionPrinter(Base):
__tablename__ = "section_printers"
__table_args__ = (UniqueConstraint("menu_category_id", "section_id"),)
__table_args__ = (UniqueConstraint("sale_category_id", "section_id"),)
id = Column(
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), default=uuid.uuid4
)
menu_category_id = Column("menu_category_id", UUID(as_uuid=True), ForeignKey("menu_categories.id"))
sale_category_id = Column("sale_category_id", UUID(as_uuid=True), ForeignKey("sale_categories.id"))
section_id = Column("section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False)
printer_id = Column("printer_id", UUID(as_uuid=True), ForeignKey("printers.id"), nullable=False)
copies = Column("copies", Integer, nullable=False)
menu_category = relationship("MenuCategory", backref="section_printers")
sale_category = relationship("SaleCategory", backref="section_printers")
section = relationship("Section", backref="section_printers")
printer = relationship("Printer", backref="section_printers")
def __init__(
self,
menu_category_id=None,
sale_category_id=None,
section_id=None,
printer_id=None,
copies=None,
id_=None,
):
self.id = id_
self.menu_category_id = menu_category_id
self.sale_category_id = sale_category_id
self.section_id = section_id
self.printer_id = printer_id
self.copies = copies

View File

@ -31,7 +31,7 @@ def print_bill(voucher_id: uuid.UUID, db: Session):
select(Printer)
.join(SectionPrinter.printer)
.where(SectionPrinter.section_id == voucher.food_table.section_id)
.where(SectionPrinter.menu_category_id == None) # noqa: E711
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
items_dict = {}

View File

@ -25,7 +25,7 @@ def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Sessio
select(Printer)
.join(SectionPrinter.printer)
.where(SectionPrinter.section_id == section_id)
.where(SectionPrinter.menu_category_id == None) # noqa: E711
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))

View File

@ -22,7 +22,7 @@ def print_discount_report(report: DiscountReport, device_id: uuid.UUID, db: Sess
select(Printer)
.join(SectionPrinter.printer)
.where(SectionPrinter.section_id == section_id)
.where(SectionPrinter.menu_category_id == None) # noqa: E711
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))

View File

@ -94,11 +94,11 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
.where(SectionPrinter.section_id == voucher.food_table.section_id)
.where(
or_(
SectionPrinter.menu_category_id == product.menu_category_id,
SectionPrinter.menu_category_id == None, # noqa: E711
SectionPrinter.sale_category_id == product.sale_category_id,
SectionPrinter.sale_category_id == None, # noqa: E711
)
)
.order_by(SectionPrinter.menu_category_id)
.order_by(SectionPrinter.sale_category_id)
).first()
key = (printer.id, copies)
if key not in my_hash:

View File

@ -23,7 +23,7 @@ def print_product_sale_report(report, device_id: uuid.UUID, db: Session):
select(Printer)
.join(SectionPrinter.printer)
.where(SectionPrinter.section_id == section_id)
.where(SectionPrinter.menu_category_id == None) # noqa: E711
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
@ -42,10 +42,10 @@ def design_product_sale_report(report):
s += "\n\r" + "-" * 42
s += "\n\rUnbilled Sale NC Staff Void"
for item in report["amounts"]:
s += f"\n\r{item['name']: ^42.42}" f"\n\r" + (f"{item['kot']: >7.2f} " if "kot" in item else " ") + (
f"{item['regularBill']: >7.2f} " if "regularBill" in item else " "
) + (f"{item['noCharge']: >7.2f} " if "noCharge" in item else " ") + (
f"{item['staff']: >7.2f} " if "staff" in item else " "
s += f"\n\r{item['name']: ^42.42}" f"\n\r" + (f"{item['kot']: >7.2f} " if "kot" in item else " ") + (
f"{item['regularBill']: >7.2f} " if "regularBill" in item else " "
) + (f"{item['noCharge']: >7.2f} " if "noCharge" in item else " ") + (
f"{item['staff']: >7.2f} " if "staff" in item else " "
) + (
f"{item['void']: >7.2f}" if "void" in item else " "
)

View File

@ -25,7 +25,7 @@ def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session):
select(Printer)
.join(SectionPrinter.printer)
.where(SectionPrinter.section_id == section_id)
.where(SectionPrinter.menu_category_id == None) # noqa: E711
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))

View File

@ -12,7 +12,7 @@ from sqlalchemy.orm import Session
from ..core.security import get_current_active_user as get_user
from ..db.session import SessionFuture
from ..models.menu_category import MenuCategory
from ..models.sale_category import SaleCategory
from ..models.section_printer import SectionPrinter
from ..schemas.user_token import UserToken
@ -30,39 +30,39 @@ def save(
with SessionFuture() as db:
current = []
default_id = uuid.uuid4()
for mcs in data:
if mcs.menu_category is None and mcs.printer is None:
for scs in data:
if scs.sale_category is None and scs.printer is None:
raise ValueError("Please choose a default printer")
if mcs.printer is None:
if scs.printer is None:
continue
stmt = (
pg_insert(SectionPrinter)
.values(
id=default_id if mcs.menu_category is None else uuid.uuid4(),
menu_category_id=mcs.menu_category.id_ if mcs.menu_category is not None else None,
id=default_id if scs.sale_category is None else uuid.uuid4(),
sale_category_id=scs.sale_category.id_ if scs.sale_category is not None else None,
section_id=id_,
printer_id=mcs.printer.id_,
copies=mcs.copies,
printer_id=scs.printer.id_,
copies=scs.copies,
)
.on_conflict_do_update(
index_elements=["menu_category_id", "section_id"],
set_=dict(printer_id=mcs.printer.id_, copies=mcs.copies),
index_elements=["sale_category_id", "section_id"],
set_=dict(printer_id=scs.printer.id_, copies=scs.copies),
)
)
db.execute(stmt)
current.append(None if mcs.menu_category is None else mcs.menu_category.id_)
current.append(None if scs.sale_category is None else scs.sale_category.id_)
db.execute(
delete(SectionPrinter).where(
or_(
and_(
SectionPrinter.section_id == id_,
SectionPrinter.menu_category_id == None, # noqa: E711
SectionPrinter.sale_category_id == None, # noqa: E711
SectionPrinter.id != default_id,
),
and_(
SectionPrinter.section_id == id_,
SectionPrinter.menu_category_id != None, # noqa: E711
~SectionPrinter.menu_category_id.in_([x for x in current if x is not None]),
SectionPrinter.sale_category_id != None, # noqa: E711
~SectionPrinter.sale_category_id.in_([x for x in current if x is not None]),
),
)
)
@ -112,18 +112,14 @@ def show_id(
def report(section_id: Optional[uuid.UUID], db: Session) -> List[schemas.SectionPrinter]:
menu_categories = db.execute(
select(MenuCategory.id, MenuCategory.name)
.where(MenuCategory.is_active == True) # noqa: E712
.order_by(MenuCategory.sort_order)
).all()
sale_categories = db.execute(select(SaleCategory.id, SaleCategory.name).order_by(SaleCategory.name)).all()
list_ = []
for mc_id, mc_name in [(None, None)] + menu_categories:
for sc_id, sc_name in [(None, None)] + sale_categories:
section_printer = (
db.execute(
select(SectionPrinter).where(
SectionPrinter.section_id == section_id,
SectionPrinter.menu_category_id == mc_id,
SectionPrinter.sale_category_id == sc_id,
)
)
.scalars()
@ -131,7 +127,7 @@ def report(section_id: Optional[uuid.UUID], db: Session) -> List[schemas.Section
)
list_.append(
schemas.SectionPrinter(
menuCategory=None if mc_id is None else schemas.MenuCategoryLink(id=mc_id, name=mc_name, products=[]),
saleCategory=None if sc_id is None else schemas.SaleCategoryLink(id=sc_id, name=sc_name),
printer=None if section_printer is None else schemas.PrinterLink(id=section_printer.printer_id),
copies=0 if section_printer is None else section_printer.copies,
)

View File

@ -3,12 +3,12 @@ from typing import Optional
from pydantic import BaseModel, Field
from . import to_camel
from .menu_category import MenuCategoryLink
from .printer import PrinterLink
from .sale_category import SaleCategoryLink
class SectionPrinter(BaseModel):
menu_category: Optional[MenuCategoryLink]
sale_category: Optional[SaleCategoryLink]
printer: Optional[PrinterLink]
copies: int = Field(ge=0)

View File

@ -1,13 +1,13 @@
import { MenuCategory } from './menu-category';
import { Printer } from './printer';
import { SaleCategory } from './sale-category';
export class SectionPrinter {
menuCategory: MenuCategory | null;
saleCategory: SaleCategory | null;
printer: Printer | null;
copies: number;
public constructor(init?: Partial<SectionPrinter>) {
this.menuCategory = null;
this.saleCategory = null;
this.printer = null;
this.copies = 0;
Object.assign(this, init);

View File

@ -26,11 +26,11 @@
</mat-form-field>
</div>
<mat-divider></mat-divider>
<mat-table #table [dataSource]="dataSource" formArrayName="menuCategories">
<!-- Menu Category Column -->
<ng-container matColumnDef="menuCategory">
<mat-header-cell *matHeaderCellDef>Menu Category</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.menuCategory?.name || 'Default' }}</mat-cell>
<mat-table #table [dataSource]="dataSource" formArrayName="saleCategories">
<!-- Sale Category Column -->
<ng-container matColumnDef="saleCategory">
<mat-header-cell *matHeaderCellDef>Sale Category</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.saleCategory?.name || 'Default' }}</mat-cell>
</ng-container>
<!-- Printer Column -->
@ -53,7 +53,7 @@
<ng-container matColumnDef="copies">
<mat-header-cell *matHeaderCellDef>Copies</mat-header-cell>
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
<mat-form-field *ngIf="!!$any(form.get('menuCategories')).at(i).value.printer">
<mat-form-field *ngIf="!!$any(form.get('saleCategories')).at(i).value.printer">
<mat-label>Copies</mat-label>
<input matInput type="number" placeholder="Copies" formControlName="copies" />
</mat-form-field>

View File

@ -29,7 +29,7 @@ export class SectionPrinterComponent implements OnInit {
sections: Section[] = [];
printers: Printer[] = [];
sectionId = '';
displayedColumns = ['menuCategory', 'printer', 'copies'];
displayedColumns = ['saleCategory', 'printer', 'copies'];
constructor(
private route: ActivatedRoute,
@ -42,7 +42,7 @@ export class SectionPrinterComponent implements OnInit {
// Create form
this.form = this.fb.group({
section: '',
menuCategories: this.fb.array([]),
saleCategories: this.fb.array([]),
});
route.params.pipe(map((p) => p.id)).subscribe((x) => {
this.sectionId = x;
@ -64,11 +64,11 @@ export class SectionPrinterComponent implements OnInit {
this.list = list;
(this.form.get('section') as AbstractControl).setValue(this.sectionId);
this.form.setControl(
'menuCategories',
'saleCategories',
this.fb.array(
this.list.map((x) =>
this.fb.group({
menuCategory: x.menuCategory?.name || 'Default',
saleCategory: x.saleCategory?.name || 'Default',
printer: x.printer?.id,
copies: `${x.copies}`,
}),
@ -119,7 +119,7 @@ export class SectionPrinterComponent implements OnInit {
getItem(): SectionPrinter[] {
const formModel = this.form.value;
this.sectionId = formModel.section;
const array = this.form.get('menuCategories') as FormArray;
const array = this.form.get('saleCategories') as FormArray;
this.list.forEach((item, index) => {
const cont = array.controls[index].value;
if (cont.printer === null || cont.printer === undefined) {

View File

@ -27,14 +27,6 @@ export class SectionPrinterService {
>;
}
// item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
// const options = {params: new HttpParams().set('m', menuCategoryId)};
// return this.http.get<SectionPrinterItem>(`${url}/${id}`, options)
// .pipe(
// catchError(this.log.handleError(serviceName, 'list'))
// ) as Observable<SectionPrinterItem>;
// }
save(sectionId: string, list: SectionPrinter[]): Observable<SectionPrinter[]> {
return this.http
.post<SectionPrinter[]>(`${url}/${sectionId}`, list, httpOptions)