diff --git a/brewman/routers/reports/raw_material_cost.py b/brewman/routers/reports/raw_material_cost.py
index 9e869622..ae25d09c 100644
--- a/brewman/routers/reports/raw_material_cost.py
+++ b/brewman/routers/reports/raw_material_cost.py
@@ -1,4 +1,4 @@
-import datetime
+from datetime import datetime, date
import uuid
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 brewman.models.master import AccountBase, CostCentre, Product, ProductGroup
from brewman.models.voucher import Voucher, Journal, Inventory
+import brewman.schemas.reports as schemas
from ...core.session import (
set_period,
get_start_date,
@@ -28,7 +29,7 @@ def get_db() -> Session:
db.close()
-@router.get("")
+@router.get("", response_model=schemas.RawMaterialCost)
def report_blank(
request: Request,
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
@@ -37,11 +38,11 @@ def report_blank(
"startDate": get_start_date(request.session),
"finishDate": get_finish_date(request.session),
"body": [],
- "footer": {},
+ "footer": None,
}
-@router.get("/data")
+@router.get("/data", response_model=schemas.RawMaterialCost)
def report_data(
request: Request,
s: str = None,
@@ -49,7 +50,7 @@ def report_data(
db: Session = Depends(get_db),
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)
return {
"startDate": s,
@@ -59,7 +60,7 @@ def report_data(
}
-@router.get("/{id_}")
+@router.get("/{id_}", response_model=schemas.RawMaterialCost)
def report_id(
id_: uuid.UUID,
request: Request,
@@ -68,7 +69,7 @@ def report_id(
db: Session = Depends(get_db),
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)
return {
"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 = []
sum_issue = func.sum(
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(Journal.voucher)
.join(Journal.account)
- .filter(Voucher.date >= datetime.datetime.strptime(start_date, "%d-%b-%Y"))
- .filter(Voucher.date <= datetime.datetime.strptime(finish_date, "%d-%b-%Y"))
+ .filter(Voucher.date >= start_date)
+ .filter(Voucher.date <= finish_date)
.filter(Journal.cost_centre_id != CostCentre.cost_centre_purchase())
.filter(AccountBase.type.in_([2, 3]))
.group_by(CostCentre)
@@ -113,7 +114,7 @@ def build_report(start_date, finish_date, db):
"issue": issue,
"sale": sale,
"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}
-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_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
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(Voucher.journals)
.join(Product.product_group)
- .filter(Voucher.date >= datetime.datetime.strptime(start_date, "%d-%b-%Y"))
- .filter(Voucher.date <= datetime.datetime.strptime(finish_date, "%d-%b-%Y"))
+ .filter(Voucher.date >= start_date)
+ .filter(Voucher.date <= finish_date)
.filter(Voucher.type == 3)
.filter(Journal.cost_centre_id == cost_centre_id)
.group_by(Product)
@@ -166,7 +167,6 @@ def build_report_id(cost_centre_id, start_date, finish_date, db):
list_.append(
{
"name": product.full_name,
- "group": product.product_group.name,
"quantity": quantity,
"net": net,
"gross": gross,
diff --git a/brewman/schemas/reports.py b/brewman/schemas/reports.py
index 40a78542..9eba41bc 100644
--- a/brewman/schemas/reports.py
+++ b/brewman/schemas/reports.py
@@ -25,17 +25,12 @@ class LedgerItem(BaseModel):
@validator("date_", pre=True)
def parse_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
class Ledger(BaseModel):
@@ -47,28 +42,20 @@ class Ledger(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class BalanceSheetItem(BaseModel):
name: Optional[str]
- group: Optional[str]
+ group: Optional[str]
amount: Optional[Decimal]
sub_amount: Optional[Decimal]
order: int
@@ -86,21 +73,16 @@ class BalanceSheet(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("date_", pre=True)
def parse_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class CashFlowItem(BaseModel):
name: str
- url: Optional[List[str]]
+ url: Optional[List[str]]
amount: Decimal = Field(multiple_of=0.01)
class Config:
@@ -128,28 +110,20 @@ class CashFlow(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class ClosingStockItem(BaseModel):
product: str
- group: str
+ group: str
quantity: Decimal
amount: Decimal
@@ -165,16 +139,11 @@ class ClosingStock(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("date_", pre=True)
def parse_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class DaybookItem(BaseModel):
@@ -191,17 +160,12 @@ class DaybookItem(BaseModel):
@validator("date_", pre=True)
def parse_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
class Daybook(BaseModel):
@@ -212,23 +176,15 @@ class Daybook(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class NetTransactionsItem(BaseModel):
@@ -240,9 +196,7 @@ class NetTransactionsItem(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
class NetTransactions(BaseModel):
@@ -253,23 +207,15 @@ class NetTransactions(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class ProductLedgerItem(BaseModel):
@@ -289,17 +235,12 @@ class ProductLedgerItem(BaseModel):
@validator("date_", pre=True)
def parse_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
class ProductLedger(BaseModel):
@@ -311,23 +252,15 @@ class ProductLedger(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class ProfitLossItem(BaseModel):
@@ -340,9 +273,7 @@ class ProfitLossItem(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
class ProfitLoss(BaseModel):
@@ -354,23 +285,15 @@ class ProfitLoss(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class PurchaseEntriesItem(BaseModel):
@@ -386,10 +309,7 @@ class PurchaseEntriesItem(BaseModel):
@validator("date_", pre=True)
def parse_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class Config:
anystr_strip_whitespace = True
@@ -404,23 +324,15 @@ class PurchaseEntries(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
@validator("start_date", pre=True)
def parse_start_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
@validator("finish_date", pre=True)
def parse_finish_date(cls, value):
- return datetime.strptime(
- value,
- "%d-%b-%Y"
- ).date()
+ return datetime.strptime(value, "%d-%b-%Y").date()
class PurchasesItem(BaseModel):
@@ -444,24 +356,60 @@ class Purchases(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
- json_encoders = {
- date: lambda v: v.strftime("%d-%b-%Y")
- }
+ 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()
+ 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()
+ return datetime.strptime(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()
diff --git a/overlord/src/app/raw-material-cost/raw-material-cost.component.html b/overlord/src/app/raw-material-cost/raw-material-cost.component.html
index a685763a..2afcb870 100644
--- a/overlord/src/app/raw-material-cost/raw-material-cost.component.html
+++ b/overlord/src/app/raw-material-cost/raw-material-cost.component.html
@@ -30,45 +30,45 @@
Name
-
+
{{row.name}}
{{row.name}}
- {{info.footer.name}}
+ {{info.footer?.name}}
Issue
{{row.issue | currency:'INR'}}
- {{info.footer.issue | currency:'INR'}}
+ {{info.footer?.issue | currency:'INR'}}
Sale
{{row.sale | currency:'INR'}}
- {{info.footer.sale | currency:'INR'}}
+ {{info.footer?.sale | currency:'INR'}}
RMC
{{row.rmc | percent:'1.2-2'}}
- {{info.footer.rmc | percent:'1.2-2'}}
+ {{info.footer?.rmc | percent:'1.2-2'}}
Group
- {{row.group}}
+ {{row.group}}
- Quantity Quantity
+ Quantity
{{row.quantity | number:'1.2-2'}}
diff --git a/overlord/src/app/raw-material-cost/raw-material-cost.service.ts b/overlord/src/app/raw-material-cost/raw-material-cost.service.ts
index e82d3ad2..f8ba111f 100644
--- a/overlord/src/app/raw-material-cost/raw-material-cost.service.ts
+++ b/overlord/src/app/raw-material-cost/raw-material-cost.service.ts
@@ -21,7 +21,6 @@ export class RawMaterialCostService {
}
list(id: string, startDate: string, finishDate): Observable {
- const listUrl = (id === null) ? url : `${url}/${id}`;
const options = {params: new HttpParams()};
if (startDate !== null) {
options.params = options.params.set('s', startDate);
@@ -29,6 +28,7 @@ export class RawMaterialCostService {
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
+ const listUrl = (id === null) ? ( (startDate || finishDate) ? `${url}/data` : url) : `${url}/${id}`;
return >this.http.get(listUrl, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))