Skip to content

Commit

Permalink
Merge commit '8a2838e6c954d17e4b01fdaff44b5b33ad458dfe' into e2e_test…
Browse files Browse the repository at this point in the history
…_mika
  • Loading branch information
mika-robots committed Sep 12, 2023
2 parents fa9b507 + 8a2838e commit 0035b97
Show file tree
Hide file tree
Showing 90 changed files with 2,488 additions and 656 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export const up = async function (knex) {
await knex('farmExpenseType').where({ expense_name: 'Other', farm_id: null }).update({
expense_name: 'Miscellaneous',
expense_translation_key: 'MISCELLANEOUS',
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export const down = async function (knex) {
await knex('farmExpenseType').where({ expense_name: 'Miscellaneous', farm_id: null }).update({
expense_name: 'Other',
expense_translation_key: 'OTHER',
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2023 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

export const up = async function (knex) {
await knex.schema.createTable('revenue_type', (table) => {
table.increments('revenue_type_id').primary();
table.string('revenue_name').notNullable();
table.uuid('farm_id').references('farm_id').inTable('farm').defaultTo(null);
table.boolean('deleted').notNullable().defaultTo(false);
table.string('created_by_user_id').references('user_id').inTable('users');
table.string('updated_by_user_id').references('user_id').inTable('users');
table.dateTime('created_at').notNullable();
table.dateTime('updated_at').notNullable();
table.string('revenue_translation_key').notNullable();
});

await knex.schema.alterTable('sale', (table) => {
table.integer('revenue_type_id').references('revenue_type_id').inTable('revenue_type');
});

// Prepopulate with one revenue type (crop_sale)
await knex('revenue_type').insert({
revenue_type_id: 1,
revenue_name: 'Crop Sale',
farm_id: null,
deleted: false,
created_by_user_id: '1',
updated_by_user_id: '1',
created_at: new Date('2000/1/1').toISOString(),
updated_at: new Date('2000/1/1').toISOString(),
revenue_translation_key: 'CROP_SALE',
});

// Reference crop_sale type for all existing records
await knex('sale').update({ revenue_type_id: 1 });

// Add permissions
await knex('permissions').insert([
{ permission_id: 138, name: 'add:revenue_types', description: 'add revenue types' },
{ permission_id: 139, name: 'delete:revenue_types', description: 'delete revenue types' },
{ permission_id: 140, name: 'edit:revenue_types', description: 'edit revenue types' },
{ permission_id: 141, name: 'get:revenue_types', description: 'get revenue types' },
]);

await knex('rolePermissions').insert([
{ role_id: 1, permission_id: 138 },
{ role_id: 2, permission_id: 138 },
{ role_id: 5, permission_id: 138 },
{ role_id: 1, permission_id: 139 },
{ role_id: 2, permission_id: 139 },
{ role_id: 5, permission_id: 139 },
{ role_id: 1, permission_id: 140 },
{ role_id: 2, permission_id: 140 },
{ role_id: 5, permission_id: 140 },
{ role_id: 1, permission_id: 141 },
{ role_id: 2, permission_id: 141 },
{ role_id: 3, permission_id: 141 },
{ role_id: 5, permission_id: 141 },
]);
};

export const down = async function (knex) {
const permissions = [138, 139, 140, 141];

await knex('rolePermissions').whereIn('permission_id', permissions).del();
await knex('permissions').whereIn('permission_id', permissions).del();

await knex.schema.alterTable('sale', (table) => {
table.dropColumn('revenue_type_id');
});

await knex.schema.dropTable('revenue_type');
};
3 changes: 1 addition & 2 deletions packages/api/src/controllers/farmExpenseTypeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const farmExpenseTypeController = {
const farm_id = req.params.farm_id;
const result = await ExpenseTypeModel.query()
.where('farm_id', null)
.orWhere('farm_id', farm_id)
.whereNotDeleted();
.orWhere('farm_id', farm_id);
res.status(200).send(result);
} catch (error) {
res.status(400).json({
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/models/expenseTypeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class ExpenseType extends baseModel {
return 'expense_type_id';
}

static get hidden() {
return ['created_at', 'created_by_user_id', 'updated_by_user_id', 'updated_at'];
}

// Optional JSON schema. This is not the database schema! Nothing is generated
// based on this. This is only used for validation. Whenever a model instance
// is created it is checked against this schema. http://json-schema.org/.
Expand Down
52 changes: 52 additions & 0 deletions packages/api/src/models/revenueTypeModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import baseModel from './baseModel.js';

class RevenueType extends baseModel {
static get tableName() {
return 'revenue_type';
}

static get idColumn() {
return 'revenue_type_id';
}

// Overriding the baseModel hidden to return the 'deleted' field
static get hidden() {
return ['created_at', 'created_by_user_id', 'updated_by_user_id', 'updated_at'];
}

// Optional JSON schema. This is not the database schema! Nothing is generated
// based on this. This is only used for validation. Whenever a model instance
// is created it is checked against this schema. http://json-schema.org/.
static get jsonSchema() {
return {
type: 'object',
required: ['revenue_name', 'farm_id'],

properties: {
revenue_type_id: { type: 'integer' },
revenue_name: { type: 'string', minLength: 1, maxLength: 100 },
farm_id: { type: 'string' },
revenue_translation_key: { type: 'string' },
...this.baseProperties,
},
additionalProperties: false,
};
}
}

export default RevenueType;
3 changes: 2 additions & 1 deletion packages/api/src/models/saleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class Sale extends baseModel {
static get jsonSchema() {
return {
type: 'object',
required: ['customer_name', 'sale_date', 'farm_id'],
required: ['customer_name', 'sale_date', 'farm_id', 'revenue_type_id'],

properties: {
sale_id: { type: 'integer' },
customer_name: { type: 'string', minLength: 1, maxLength: 255 },
sale_date: { type: 'string', minLength: 1, maxLength: 255 },
farm_id: { type: 'string' },
revenue_type_id: { type: 'integer' },
...this.baseProperties,
},
additionalProperties: false,
Expand Down
1 change: 1 addition & 0 deletions packages/api/tests/sale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ describe('Sale Tests', () => {
crop_variety_id: cropVariety2.crop_variety_id,
},
],
revenue_type_id: 1,
};
});

Expand Down
2 changes: 2 additions & 0 deletions packages/webapp/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ABANDONED": "Abandoned",
"ACTIVE": "Active",
"ADD": "Add",
"ADD_ANOTHER_ITEM": "Add another item",
"ALL": "All",
"APPLY": "Apply",
"BACK": "Go Back",
Expand Down Expand Up @@ -46,6 +47,7 @@
"PLANNED": "Planned",
"PROCEED": "Proceed",
"REMOVE": "Remove",
"REMOVE_ITEM": "Remove item",
"REQUIRED": "Required",
"RETIRE": "Retire",
"SAVE": "Save",
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/public/locales/en/expense.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"FUEL": "Fuel",
"LAND": "Land",
"SEEDS": "Seeds",
"OTHER": "Other"
"MISCELLANEOUS": "Miscellaneous"
}
24 changes: 24 additions & 0 deletions packages/webapp/public/locales/en/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
"UPDATE": "Successfully updated expenses!"
}
},
"EXPENSE_TYPE": {
"ERROR": {
"ADD": "Failed to create custom expense",
"DELETE": "Failed to delete custom expense",
"UPDATE": "Failed to update custom expense"
},
"SUCCESS": {
"ADD": "Successfully created custom expense",
"DELETE": "Successfully deleted custom expense",
"UPDATE": "Successfully updated custom expense"
}
},
"FARM": {
"ERROR": {
"ADD": "Failed to add farm, please contact litefarm for assistance",
Expand Down Expand Up @@ -133,6 +145,18 @@
"EDIT": "Revenue successfully updated"
}
},
"REVENUE_TYPE": {
"ERROR": {
"ADD": "Failed to add revenue type",
"DELETE": "Failed to retire revenue type",
"UPDATE": "Failed to update revenue type"
},
"SUCCESS": {
"ADD": "Successfully added revenue type",
"DELETE": "Successfully retired revenue type",
"UPDATE": "Successfully updated revenue type"
}
},
"SALE": {
"ERROR": {
"ADD": "Failed to add sale",
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/public/locales/en/revenue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CROP_SALE": "Crop Sale"
}
36 changes: 28 additions & 8 deletions packages/webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,22 +496,27 @@
},
"EXPENSE": {
"ADD_EXPENSE": {
"ALL_FIELDS_REQUIRED": "All fields are required",
"MIN_ERROR": "Please enter a value greater than ",
"REQUIRED_ERROR": "Expense is required",
"TITLE_1": "New Expense (1 of 2)",
"TITLE_2": "New Expense (2 of 2)"
"ADD_CUSTOM_EXPENSE": "Add custom expense",
"CUSTOM_EXPENSE_NAME": "Custom expense name",
"CUSTOM_EXPENSE_TYPE": "Custom expense type",
"DUPLICATE_NAME": "An expense type with this name already exists. Please choose another.",
"FLOW": "expense creation",
"NEW_EXPENSE_ITEM": "New expense item",
"TITLE": "Add expense",
"WHICH_TYPES_TO_RECORD": "Which types of expenses would you like to record?"
},
"ADD_MORE_ITEMS": "Add more items",
"DETAILED_HISTORY": "Detailed History",
"EDIT_EXPENSE": {
"DATE_PLACEHOLDER": "Choose a Date",
"DESELECTING_CATEGORY": "Deselecting a category will remove existing expenses under this category for this expenses log.",
"REMOVE_ALL": "You removed all expenses, click Save to submit.",
"RETIRE_EXPENSE_MESSAGE": "Retiring this expense type will remove it as a possible choice for future expenses. You can still search and filter for historical instances of this expense type on the Finances tab.",
"RETIRE_EXPENSE_TYPE": "Retire expense type",
"TITLE_1": "Edit Expense(1 of 2)",
"TITLE_2": "Edit Expense (2 of 2)"
},
"ITEM": "Item",
"ITEM_NAME": "Item Name",
"NAME": "Name",
"NO_EXPENSE": "No expense found",
"NO_EXPENSE_YEAR": "You have no expense recorded for this year",
Expand Down Expand Up @@ -807,6 +812,7 @@
"ESTIMATED_PRICE_PER_UNIT": "Estimated price per unit",
"TITLE": "Estimated Revenue"
},
"MANAGE_CUSTOM_TYPE": "Manage custom type",
"REVENUE": "Revenue",
"VIEW_WITHIN_DATE_RANGE": "View revenue within this date range",
"WHOLE_FARM_REVENUE": "Whole farm revenue"
Expand Down Expand Up @@ -1421,6 +1427,18 @@
"DESCRIPTION": "Someone will be in touch within 48 hours.",
"TITLE": "Help request submitted"
},
"REVENUE": {
"ADD_REVENUE": {
"ADD_CUSTOM_REVENUE": "Add custom revenue",
"CUSTOM_REVENUE_NAME": "Custom revenue name",
"CUSTOM_REVENUE_TYPE": "Custom revenue type",
"DUPLICATE_NAME": "A revenue type with this name already exists. Please choose another."
},
"EDIT_REVENUE": {
"RETIRE_REVENUE_MESSAGE": "Retiring this revenue type will remove it as a possible choice for future expenses. You can still search and filter for historical instances of this expense type on the Finances tab.",
"RETIRE_REVENUE_TYPE": "Retire revenue type"
}
},
"ROLE_SELECTION": {
"FARM_EO": "Extension Officer",
"FARM_MANAGER": "Farm Manager",
Expand All @@ -1430,19 +1448,22 @@
},
"SALE": {
"ADD_SALE": {
"ADD_REVENUE": "Add revenue",
"CROP_PLACEHOLDER": "Select crop",
"CROP_REQUIRED": "Required",
"CROP_VARIETY": "Crop variety",
"CUSTOMER_NAME": "Customer name",
"CUSTOMER_NAME_REQUIRED": "Required",
"DATE": "Date",
"FLOW": "revenue creation",
"SALE_VALUE_ERROR": "Sale value must be a positive number less than 999,999,999",
"TABLE_HEADERS": {
"CROP_VARIETIES": "Crop variety",
"QUANTITY": "Quantity",
"TOTAL": "Total"
},
"TITLE": "Add new sale"
"TITLE": "Add new sale",
"WHICH_TYPE_TO_RECORD": "What type of revenue would you like to record?"
},
"DETAIL": {
"ACTION": "Action",
Expand Down Expand Up @@ -1483,7 +1504,6 @@
"EXPENSES": "Expenses",
"FINANCE_HELP": "Finance Help",
"LABOUR_LABEL": "Labour",
"MANAGE_CUSTOM_EXPENSE_TYPE": "Manage custom type",
"MANAGE_CUSTOM_EXPENSE_TYPES_SPOTLIGHT": {
"BODY": "Here you can add, modify, or retire expense types personalized to your farm.",
"TITLE": "Manage custom expense types"
Expand Down
2 changes: 2 additions & 0 deletions packages/webapp/public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ABANDONED": "Abandonado",
"ACTIVE": "Activo",
"ADD": "Agregar",
"ADD_ANOTHER_ITEM": "MISSING",
"ALL": "Todo",
"APPLY": "Aplicar",
"BACK": "Atrás",
Expand Down Expand Up @@ -46,6 +47,7 @@
"PLANNED": "Planificado",
"PROCEED": "Proceder",
"REMOVE": "Remover",
"REMOVE_ITEM": "MISSING",
"REQUIRED": "Requerido",
"RETIRE": "Retirar",
"SAVE": "Guardar",
Expand Down
Loading

0 comments on commit 0035b97

Please sign in to comment.