Raw Material Cost Done!!
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import datetime
|
from datetime import datetime, date
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Security, Request
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
@ -10,6 +10,7 @@ from ...core.security import get_current_active_user as get_user
|
|||||||
from ...db.session import SessionLocal
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.master import AccountBase, CostCentre, Product, ProductGroup
|
from brewman.models.master import AccountBase, CostCentre, Product, ProductGroup
|
||||||
from brewman.models.voucher import Voucher, Journal, Inventory
|
from brewman.models.voucher import Voucher, Journal, Inventory
|
||||||
|
import brewman.schemas.reports as schemas
|
||||||
from ...core.session import (
|
from ...core.session import (
|
||||||
set_period,
|
set_period,
|
||||||
get_start_date,
|
get_start_date,
|
||||||
@ -28,7 +29,7 @@ def get_db() -> Session:
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("", response_model=schemas.RawMaterialCost)
|
||||||
def report_blank(
|
def report_blank(
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
||||||
@ -37,11 +38,11 @@ def report_blank(
|
|||||||
"startDate": get_start_date(request.session),
|
"startDate": get_start_date(request.session),
|
||||||
"finishDate": get_finish_date(request.session),
|
"finishDate": get_finish_date(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
"footer": {},
|
"footer": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/data")
|
@router.get("/data", response_model=schemas.RawMaterialCost)
|
||||||
def report_data(
|
def report_data(
|
||||||
request: Request,
|
request: Request,
|
||||||
s: str = None,
|
s: str = None,
|
||||||
@ -49,7 +50,7 @@ def report_data(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
||||||
):
|
):
|
||||||
body, footer = build_report(s, f, db)
|
body, footer = build_report(datetime.strptime(s, "%d-%b-%Y"), datetime.strptime(f, "%d-%b-%Y"), db)
|
||||||
set_period(s, f, request.session)
|
set_period(s, f, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": s,
|
"startDate": s,
|
||||||
@ -59,7 +60,7 @@ def report_data(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{id_}")
|
@router.get("/{id_}", response_model=schemas.RawMaterialCost)
|
||||||
def report_id(
|
def report_id(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
request: Request,
|
request: Request,
|
||||||
@ -68,7 +69,7 @@ def report_id(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
||||||
):
|
):
|
||||||
body = build_report_id(id_, s, f, db)
|
body = build_report_id(id_, datetime.strptime(s, "%d-%b-%Y"), datetime.strptime(f, "%d-%b-%Y"), db)
|
||||||
set_period(s, f, request.session)
|
set_period(s, f, request.session)
|
||||||
return {
|
return {
|
||||||
"id": id_,
|
"id": id_,
|
||||||
@ -78,7 +79,7 @@ def report_id(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, db):
|
def build_report(start_date: date, finish_date: date, db: Session):
|
||||||
body = []
|
body = []
|
||||||
sum_issue = func.sum(
|
sum_issue = func.sum(
|
||||||
case([(AccountBase.type == 2, Journal.signed_amount)], else_=0)
|
case([(AccountBase.type == 2, Journal.signed_amount)], else_=0)
|
||||||
@ -92,8 +93,8 @@ def build_report(start_date, finish_date, db):
|
|||||||
.join(CostCentre.journals)
|
.join(CostCentre.journals)
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.join(Journal.account)
|
.join(Journal.account)
|
||||||
.filter(Voucher.date >= datetime.datetime.strptime(start_date, "%d-%b-%Y"))
|
.filter(Voucher.date >= start_date)
|
||||||
.filter(Voucher.date <= datetime.datetime.strptime(finish_date, "%d-%b-%Y"))
|
.filter(Voucher.date <= finish_date)
|
||||||
.filter(Journal.cost_centre_id != CostCentre.cost_centre_purchase())
|
.filter(Journal.cost_centre_id != CostCentre.cost_centre_purchase())
|
||||||
.filter(AccountBase.type.in_([2, 3]))
|
.filter(AccountBase.type.in_([2, 3]))
|
||||||
.group_by(CostCentre)
|
.group_by(CostCentre)
|
||||||
@ -113,7 +114,7 @@ def build_report(start_date, finish_date, db):
|
|||||||
"issue": issue,
|
"issue": issue,
|
||||||
"sale": sale,
|
"sale": sale,
|
||||||
"rmc": rmc,
|
"rmc": rmc,
|
||||||
"url": "", # request.route_url("raw_material_cost_id",id=str(cost_centre.id),_query={"startDate": start_date, "finishDate": finish_date},),
|
"url": ['/', 'raw-material-cost', str(cost_centre.id)],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ def build_report(start_date, finish_date, db):
|
|||||||
return body, {"name": "Total", "issue": issues, "sale": sales, "rmc": rmc}
|
return body, {"name": "Total", "issue": issues, "sale": sales, "rmc": rmc}
|
||||||
|
|
||||||
|
|
||||||
def build_report_id(cost_centre_id, start_date, finish_date, db):
|
def build_report_id(cost_centre_id: uuid.UUID, start_date: date, finish_date: date, db: Session):
|
||||||
sum_quantity = func.sum(Inventory.quantity * Journal.debit).label("quantity")
|
sum_quantity = func.sum(Inventory.quantity * Journal.debit).label("quantity")
|
||||||
sum_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
|
sum_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
|
||||||
sum_gross = func.sum(Inventory.amount * Journal.debit).label("gross")
|
sum_gross = func.sum(Inventory.amount * Journal.debit).label("gross")
|
||||||
@ -132,8 +133,8 @@ def build_report_id(cost_centre_id, start_date, finish_date, db):
|
|||||||
.join(Inventory.voucher)
|
.join(Inventory.voucher)
|
||||||
.join(Voucher.journals)
|
.join(Voucher.journals)
|
||||||
.join(Product.product_group)
|
.join(Product.product_group)
|
||||||
.filter(Voucher.date >= datetime.datetime.strptime(start_date, "%d-%b-%Y"))
|
.filter(Voucher.date >= start_date)
|
||||||
.filter(Voucher.date <= datetime.datetime.strptime(finish_date, "%d-%b-%Y"))
|
.filter(Voucher.date <= finish_date)
|
||||||
.filter(Voucher.type == 3)
|
.filter(Voucher.type == 3)
|
||||||
.filter(Journal.cost_centre_id == cost_centre_id)
|
.filter(Journal.cost_centre_id == cost_centre_id)
|
||||||
.group_by(Product)
|
.group_by(Product)
|
||||||
@ -166,7 +167,6 @@ def build_report_id(cost_centre_id, start_date, finish_date, db):
|
|||||||
list_.append(
|
list_.append(
|
||||||
{
|
{
|
||||||
"name": product.full_name,
|
"name": product.full_name,
|
||||||
"group": product.product_group.name,
|
|
||||||
"quantity": quantity,
|
"quantity": quantity,
|
||||||
"net": net,
|
"net": net,
|
||||||
"gross": gross,
|
"gross": gross,
|
||||||
|
|||||||
@ -25,17 +25,12 @@ class LedgerItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Ledger(BaseModel):
|
class Ledger(BaseModel):
|
||||||
@ -47,28 +42,20 @@ class Ledger(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class BalanceSheetItem(BaseModel):
|
class BalanceSheetItem(BaseModel):
|
||||||
name: Optional[str]
|
name: Optional[str]
|
||||||
group: Optional[str]
|
group: Optional[str]
|
||||||
amount: Optional[Decimal]
|
amount: Optional[Decimal]
|
||||||
sub_amount: Optional[Decimal]
|
sub_amount: Optional[Decimal]
|
||||||
order: int
|
order: int
|
||||||
@ -86,21 +73,16 @@ class BalanceSheet(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class CashFlowItem(BaseModel):
|
class CashFlowItem(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
url: Optional[List[str]]
|
url: Optional[List[str]]
|
||||||
amount: Decimal = Field(multiple_of=0.01)
|
amount: Decimal = Field(multiple_of=0.01)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -128,28 +110,20 @@ class CashFlow(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class ClosingStockItem(BaseModel):
|
class ClosingStockItem(BaseModel):
|
||||||
product: str
|
product: str
|
||||||
group: str
|
group: str
|
||||||
quantity: Decimal
|
quantity: Decimal
|
||||||
amount: Decimal
|
amount: Decimal
|
||||||
|
|
||||||
@ -165,16 +139,11 @@ class ClosingStock(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class DaybookItem(BaseModel):
|
class DaybookItem(BaseModel):
|
||||||
@ -191,17 +160,12 @@ class DaybookItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Daybook(BaseModel):
|
class Daybook(BaseModel):
|
||||||
@ -212,23 +176,15 @@ class Daybook(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class NetTransactionsItem(BaseModel):
|
class NetTransactionsItem(BaseModel):
|
||||||
@ -240,9 +196,7 @@ class NetTransactionsItem(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class NetTransactions(BaseModel):
|
class NetTransactions(BaseModel):
|
||||||
@ -253,23 +207,15 @@ class NetTransactions(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class ProductLedgerItem(BaseModel):
|
class ProductLedgerItem(BaseModel):
|
||||||
@ -289,17 +235,12 @@ class ProductLedgerItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ProductLedger(BaseModel):
|
class ProductLedger(BaseModel):
|
||||||
@ -311,23 +252,15 @@ class ProductLedger(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class ProfitLossItem(BaseModel):
|
class ProfitLossItem(BaseModel):
|
||||||
@ -340,9 +273,7 @@ class ProfitLossItem(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ProfitLoss(BaseModel):
|
class ProfitLoss(BaseModel):
|
||||||
@ -354,23 +285,15 @@ class ProfitLoss(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class PurchaseEntriesItem(BaseModel):
|
class PurchaseEntriesItem(BaseModel):
|
||||||
@ -386,10 +309,7 @@ class PurchaseEntriesItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
@ -404,23 +324,15 @@ class PurchaseEntries(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
|
|
||||||
class PurchasesItem(BaseModel):
|
class PurchasesItem(BaseModel):
|
||||||
@ -444,24 +356,60 @@ class Purchases(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
date: lambda v: v.strftime("%d-%b-%Y")
|
|
||||||
}
|
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
value,
|
|
||||||
"%d-%b-%Y"
|
|
||||||
).date()
|
class RawMaterialCostItem(BaseModel):
|
||||||
|
name: Optional[str]
|
||||||
|
issue: Optional[Decimal]
|
||||||
|
sale: Optional[Decimal]
|
||||||
|
rmc: Optional[Decimal]
|
||||||
|
url: Optional[List[str]]
|
||||||
|
|
||||||
|
group: Optional[str]
|
||||||
|
quantity: Optional[Decimal]
|
||||||
|
net: Optional[Decimal]
|
||||||
|
gross: Optional[Decimal]
|
||||||
|
|
||||||
|
heading: Optional[bool]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
|
||||||
|
|
||||||
|
class RawMaterialCost(BaseModel):
|
||||||
|
id_: Optional[uuid.UUID]
|
||||||
|
start_date: date
|
||||||
|
finish_date: date
|
||||||
|
body: List[RawMaterialCostItem]
|
||||||
|
footer: Optional[RawMaterialCostItem]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
|
@validator("start_date", pre=True)
|
||||||
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
@validator("finish_date", pre=True)
|
||||||
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|||||||
@ -30,45 +30,45 @@
|
|||||||
<ng-container matColumnDef="name">
|
<ng-container matColumnDef="name">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">
|
<mat-cell *matCellDef="let row">
|
||||||
<a [href]="row.url" *ngIf="row.url">
|
<a *ngIf="row.url" [routerLink]="row.url" [queryParams]="{startDate: info.startDate, finishDate: info.finishDate}">
|
||||||
{{row.name}}
|
{{row.name}}
|
||||||
</a>
|
</a>
|
||||||
<span *ngIf="!row.url">{{row.name}}</span>
|
<span *ngIf="!row.url">{{row.name}}</span>
|
||||||
</mat-cell>
|
</mat-cell>
|
||||||
<mat-footer-cell *matFooterCellDef><span *ngIf="info.footer">{{info.footer.name}}</span></mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef>{{info.footer?.name}}</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Issue Column -->
|
<!-- Issue Column -->
|
||||||
<ng-container matColumnDef="issue">
|
<ng-container matColumnDef="issue">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Issue</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Issue</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row" class="right">{{row.issue | currency:'INR'}}</mat-cell>
|
<mat-cell *matCellDef="let row" class="right">{{row.issue | currency:'INR'}}</mat-cell>
|
||||||
<mat-footer-cell *matFooterCellDef class="right">{{info.footer.issue | currency:'INR'}}</mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef class="right">{{info.footer?.issue | currency:'INR'}}</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Sale Column -->
|
<!-- Sale Column -->
|
||||||
<ng-container matColumnDef="sale">
|
<ng-container matColumnDef="sale">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Sale</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Sale</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row" class="right">{{row.sale | currency:'INR'}}</mat-cell>
|
<mat-cell *matCellDef="let row" class="right">{{row.sale | currency:'INR'}}</mat-cell>
|
||||||
<mat-footer-cell *matFooterCellDef class="right">{{info.footer.sale | currency:'INR'}}</mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef class="right">{{info.footer?.sale | currency:'INR'}}</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Rmc Column -->
|
<!-- Rmc Column -->
|
||||||
<ng-container matColumnDef="rmc">
|
<ng-container matColumnDef="rmc">
|
||||||
<mat-header-cell *matHeaderCellDef class="right">RMC</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef class="right">RMC</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row" class="right">{{row.rmc | percent:'1.2-2'}}</mat-cell>
|
<mat-cell *matCellDef="let row" class="right">{{row.rmc | percent:'1.2-2'}}</mat-cell>
|
||||||
<mat-footer-cell *matFooterCellDef class="right">{{info.footer.rmc | percent:'1.2-2'}}</mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef class="right">{{info.footer?.rmc | percent:'1.2-2'}}</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Group Column -->
|
<!-- Group Column -->
|
||||||
<ng-container matColumnDef="group">
|
<ng-container matColumnDef="group">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Group</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header>Group</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row"><a [href]="row.url">{{row.group}}</a></mat-cell>
|
<mat-cell *matCellDef="let row">{{row.group}}</mat-cell>
|
||||||
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Quantity Column -->
|
<!-- Quantity Column -->
|
||||||
<ng-container matColumnDef="quantity">
|
<ng-container matColumnDef="quantity">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Quantity Quantity</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Quantity</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row" class="right">{{row.quantity | number:'1.2-2'}}</mat-cell>
|
<mat-cell *matCellDef="let row" class="right">{{row.quantity | number:'1.2-2'}}</mat-cell>
|
||||||
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|||||||
@ -21,7 +21,6 @@ export class RawMaterialCostService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list(id: string, startDate: string, finishDate): Observable<RawMaterialCost> {
|
list(id: string, startDate: string, finishDate): Observable<RawMaterialCost> {
|
||||||
const listUrl = (id === null) ? url : `${url}/${id}`;
|
|
||||||
const options = {params: new HttpParams()};
|
const options = {params: new HttpParams()};
|
||||||
if (startDate !== null) {
|
if (startDate !== null) {
|
||||||
options.params = options.params.set('s', startDate);
|
options.params = options.params.set('s', startDate);
|
||||||
@ -29,6 +28,7 @@ export class RawMaterialCostService {
|
|||||||
if (finishDate !== null) {
|
if (finishDate !== null) {
|
||||||
options.params = options.params.set('f', finishDate);
|
options.params = options.params.set('f', finishDate);
|
||||||
}
|
}
|
||||||
|
const listUrl = (id === null) ? ( (startDate || finishDate) ? `${url}/data` : url) : `${url}/${id}`;
|
||||||
return <Observable<RawMaterialCost>>this.http.get<RawMaterialCost>(listUrl, options)
|
return <Observable<RawMaterialCost>>this.http.get<RawMaterialCost>(listUrl, options)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
|
|||||||
Reference in New Issue
Block a user