mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
fix: move enable stock returns to inventory
This commit is contained in:
parent
1cd03aed34
commit
8f95e9098c
@ -15,7 +15,6 @@ export class AccountingSettings extends Doc {
|
||||
enableDiscounting?: boolean;
|
||||
enableInventory?: boolean;
|
||||
enablePriceList?: boolean;
|
||||
enableStockReturns?: boolean;
|
||||
|
||||
static filters: FiltersMap = {
|
||||
writeOffAccount: () => ({
|
||||
@ -47,9 +46,6 @@ export class AccountingSettings extends Doc {
|
||||
enableInventory: () => {
|
||||
return !!this.enableInventory;
|
||||
},
|
||||
enableStockReturns: () => {
|
||||
return !!this.enableStockReturns;
|
||||
},
|
||||
};
|
||||
|
||||
override hidden: HiddenMap = {
|
||||
|
@ -166,9 +166,8 @@ export function getMakeReturnDocAction(fyo: Fyo): Action {
|
||||
label: fyo.t`Return`,
|
||||
group: fyo.t`Create`,
|
||||
condition: (doc: Doc) =>
|
||||
!!fyo.singles.AccountingSettings?.enableStockReturns &&
|
||||
!!fyo.singles.InventorySettings?.enableStockReturns &&
|
||||
doc.isSubmitted &&
|
||||
!doc.isCancelled &&
|
||||
!doc.isReturn,
|
||||
action: async (doc: Doc) => {
|
||||
const returnDoc = await (doc as StockTransfer).getReturnDoc();
|
||||
@ -212,8 +211,8 @@ export const statusColor: Record<
|
||||
NotSaved: 'gray',
|
||||
Submitted: 'green',
|
||||
Cancelled: 'red',
|
||||
Return: 'orange',
|
||||
ReturnIssued: 'gray',
|
||||
Return: 'green',
|
||||
ReturnIssued: 'green',
|
||||
};
|
||||
|
||||
export function getStatusText(status: DocStatus | InvoiceStatus): string {
|
||||
@ -274,14 +273,14 @@ function getSubmittableDocStatus(doc: RenderData | Doc) {
|
||||
|
||||
if (
|
||||
[ModelNameEnum.Shipment, ModelNameEnum.PurchaseReceipt].includes(
|
||||
doc.schema.name as ModelNameEnum
|
||||
doc.schemaName as ModelNameEnum
|
||||
)
|
||||
) {
|
||||
if (doc.isReturn && doc.submitted && !doc.cancelled) {
|
||||
if (doc.isReturn && doc.isSubmitted) {
|
||||
return 'Return';
|
||||
}
|
||||
|
||||
if (doc.isItemsReturned && doc.submitted && !doc.cancelled) {
|
||||
if (doc.isItemsReturned && doc.isSubmitted) {
|
||||
return 'ReturnIssued';
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ export class InventorySettings extends Doc {
|
||||
enableBatches?: boolean;
|
||||
enableSerialNumber?: boolean;
|
||||
enableUomConversions?: boolean;
|
||||
enableStockReturns?: boolean;
|
||||
|
||||
static filters: FiltersMap = {
|
||||
stockInHand: () => ({
|
||||
@ -42,5 +43,8 @@ export class InventorySettings extends Doc {
|
||||
enableUomConversions: () => {
|
||||
return !!this.enableUomConversions;
|
||||
},
|
||||
enableStockReturns: () => {
|
||||
return !!this.enableStockReturns;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ export class StockManager {
|
||||
|
||||
const batchMessage = !!batch ? t` in Batch ${batch}` : '';
|
||||
|
||||
if (quantityBefore < details.quantity) {
|
||||
if (!details.isReturn && quantityBefore < details.quantity) {
|
||||
throw new ValidationError(
|
||||
[
|
||||
t`Insufficient Quantity.`,
|
||||
|
@ -38,7 +38,7 @@ export class StockTransferItem extends TransferItem {
|
||||
return this.schemaName === ModelNameEnum.ShipmentItem;
|
||||
}
|
||||
|
||||
get isReturn() {
|
||||
get isReturn(): boolean {
|
||||
return !!this.parentdoc?.isReturn;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ async function validateItemRowSerialNumber(
|
||||
|
||||
const serialNumbers = getSerialNumbers(serialNumber);
|
||||
|
||||
const quantity = row.quantity ?? 0;
|
||||
const quantity = Math.abs(row.quantity ?? 0);
|
||||
if (serialNumbers.length !== quantity) {
|
||||
throw new ValidationError(
|
||||
t`Additional ${
|
||||
@ -147,14 +147,26 @@ async function validateItemRowSerialNumber(
|
||||
|
||||
const status = snDoc.status ?? 'Inactive';
|
||||
const schemaName = row.parentSchemaName;
|
||||
const isReturn = !!row.parentdoc?.returnAgainst;
|
||||
const isSubmitted = !!row.parentdoc?.submitted;
|
||||
|
||||
if (schemaName === 'PurchaseReceipt' && status !== 'Inactive') {
|
||||
if (
|
||||
schemaName === 'PurchaseReceipt' &&
|
||||
status !== 'Inactive' &&
|
||||
!isSubmitted &&
|
||||
!isReturn
|
||||
) {
|
||||
throw new ValidationError(
|
||||
t`Serial Number ${serialNumber} is not Inactive`
|
||||
);
|
||||
}
|
||||
|
||||
if (schemaName === 'Shipment' && status !== 'Active') {
|
||||
if (
|
||||
schemaName === 'Shipment' &&
|
||||
status !== 'Active' &&
|
||||
!isSubmitted &&
|
||||
!isReturn
|
||||
) {
|
||||
throw new ValidationError(
|
||||
t`Serial Number ${serialNumber} is not Active.`
|
||||
);
|
||||
@ -244,14 +256,15 @@ export async function canValidateSerialNumber(
|
||||
|
||||
export async function updateSerialNumbers(
|
||||
doc: StockTransfer | StockMovement,
|
||||
isCancel: boolean
|
||||
isCancel: boolean,
|
||||
isReturn = false
|
||||
) {
|
||||
for (const row of doc.items ?? []) {
|
||||
if (!row.serialNumber) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const status = getSerialNumberStatus(doc, row, isCancel);
|
||||
const status = getSerialNumberStatus(doc, row, isCancel, isReturn);
|
||||
await updateSerialNumberStatus(status, row.serialNumber, doc.fyo);
|
||||
}
|
||||
}
|
||||
@ -270,13 +283,20 @@ async function updateSerialNumberStatus(
|
||||
function getSerialNumberStatus(
|
||||
doc: StockTransfer | StockMovement,
|
||||
item: StockTransferItem | StockMovementItem,
|
||||
isCancel: boolean
|
||||
isCancel: boolean,
|
||||
isReturn: boolean
|
||||
): SerialNumberStatus {
|
||||
if (doc.schemaName === ModelNameEnum.Shipment) {
|
||||
if (isReturn) {
|
||||
return isCancel ? 'Delivered' : 'Active';
|
||||
}
|
||||
return isCancel ? 'Active' : 'Delivered';
|
||||
}
|
||||
|
||||
if (doc.schemaName === ModelNameEnum.PurchaseReceipt) {
|
||||
if (isReturn) {
|
||||
return isCancel ? 'Active' : 'Delivered';
|
||||
}
|
||||
return isCancel ? 'Inactive' : 'Active';
|
||||
}
|
||||
|
||||
|
@ -86,13 +86,6 @@
|
||||
"default": false,
|
||||
"section": "Features"
|
||||
},
|
||||
{
|
||||
"fieldname": "enableStockReturns",
|
||||
"label": "Enable Stock Returns",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"section": "Features"
|
||||
},
|
||||
{
|
||||
"fieldname": "fiscalYearStart",
|
||||
"label": "Fiscal Year Start Date",
|
||||
|
@ -74,6 +74,13 @@
|
||||
"label": "Enable UOM Conversion",
|
||||
"fieldtype": "Check",
|
||||
"section": "Features"
|
||||
},
|
||||
{
|
||||
"fieldname": "enableStockReturns",
|
||||
"label": "Enable Stock Returns",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"section": "Features"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
"fieldtype": "Link",
|
||||
"target": "PurchaseReceipt",
|
||||
"label": "Return Against",
|
||||
"section": "Return"
|
||||
"section": "References"
|
||||
}
|
||||
],
|
||||
"keywordFields": ["name", "party"]
|
||||
|
@ -36,7 +36,7 @@
|
||||
"fieldtype": "Link",
|
||||
"target": "Shipment",
|
||||
"label": "Return Against",
|
||||
"section": "Return"
|
||||
"section": "References"
|
||||
}
|
||||
],
|
||||
"keywordFields": ["name", "party"]
|
||||
|
@ -61,29 +61,21 @@
|
||||
"fieldtype": "Attachment",
|
||||
"section": "References"
|
||||
},
|
||||
{
|
||||
"fieldname": "isReturned",
|
||||
"fieldtype": "Check",
|
||||
"hidden": true,
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"abstract": true,
|
||||
"fieldname": "backReference",
|
||||
"section": "References"
|
||||
},
|
||||
{
|
||||
"fieldname": "isReturn",
|
||||
"label": "Is Return",
|
||||
"placeholder": "Is Return",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"section": "Return"
|
||||
},
|
||||
{
|
||||
"abstract": true,
|
||||
"fieldname": "returnAgainst",
|
||||
"section": "Return"
|
||||
},
|
||||
{
|
||||
"fieldname": "isItemsReturned",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"hidden": true
|
||||
"section": "References"
|
||||
}
|
||||
],
|
||||
"keywordFields": ["name", "party"]
|
||||
|
@ -113,11 +113,11 @@ function getSubmittableStatus(doc: Doc) {
|
||||
return 'Paid';
|
||||
}
|
||||
|
||||
if (doc.isReturn && doc.isSubmitted && !doc.isCancelled) {
|
||||
if (doc.returnAgainst && doc.isSubmitted) {
|
||||
return 'Return';
|
||||
}
|
||||
|
||||
if (doc.isItemsReturned && doc.isSubmitted && !doc.isCancelled) {
|
||||
if (doc.isReturned && doc.isSubmitted) {
|
||||
return 'ReturnIssued';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user