Skip to content

Commit

Permalink
fix(inventory): do not require sale_account
Browse files Browse the repository at this point in the history
This commit removes the requirement for each inventory to have a
sale_account.  The requirement is motivated by needing a sale_account
for any gain from sales.  Since some medicines will not be sold, we
  still need to have a asset account without a sale account.  Also, any
  physical inventory will not have a sale_account.
  • Loading branch information
Jonathan Niles committed Nov 29, 2016
1 parent 379be48 commit 8b0b859
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
</thead>

<tbody>
<tr ng-repeat="group in GroupsCtrl.groupList | orderBy: 'name'">
<tr ng-repeat="group in GroupsCtrl.groupList | orderBy:'name' track by group.code">
<td>{{ group.code }}</td>
<td>{{ group.name }}</td>
<td>{{ group.inventory_counted }} <small>{{ 'INVENTORY.ELEMENT' | translate | lowercase }}(s)</small></td>
<td class="text-center">{{ group.saleAccountNumber }}</td>
<td class="text-center">{{ group.stockAccountNumber }}</td>
<td class="text-center">{{ group.cogsAccountNumber }}</td>
<td>
<a style="cursor:pointer; text-decoration:none;"
<a href
ng-click="GroupsCtrl.editInventoryGroup(group.uuid)"
data-edit-group="{{ group.code }}">
<i class="fa fa-edit"></i> {{ 'FORM.LABELS.EDIT' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ angular.module('bhima.controllers')
.controller('InventoryGroupsActionsModalController', InventoryGroupsActionsModalController);

InventoryGroupsActionsModalController.$inject = [
'AccountService', 'InventoryGroupService', 'NotifyService', '$uibModalInstance', 'data'
'AccountService', 'InventoryGroupService', 'NotifyService', '$uibModalInstance', 'data', 'bhConstants'
];

function InventoryGroupsActionsModalController(Account, InventoryGroup, Notify, Instance, Data) {
function InventoryGroupsActionsModalController(Account, InventoryGroup, Notify, Instance, Data, bhConstants) {
var vm = this, session = vm.session = {};

// map for actions
Expand All @@ -14,6 +14,7 @@ function InventoryGroupsActionsModalController(Account, InventoryGroup, Notify,
// expose to the view
vm.submit = submit;
vm.cancel = cancel;
vm.bhConstants = bhConstants;

// startup
startup();
Expand All @@ -34,18 +35,12 @@ function InventoryGroupsActionsModalController(Account, InventoryGroup, Notify,
/** add inventory group */
function addGroup(record) {
return InventoryGroup.create(record)
.then(function (res) {
return res;
})
.catch(Notify.handleError);
.catch(Notify.handleError);
}

/** edit inventory group */
function editGroup(record, uuid) {
return InventoryGroup.update(uuid, record)
.then(function (res) {
return res;
})
.catch(Notify.handleError);
}

Expand Down Expand Up @@ -86,7 +81,7 @@ function InventoryGroupsActionsModalController(Account, InventoryGroup, Notify,

Account.read()
.then(function (accounts) {
vm.accountList = accounts;
vm.accounts = accounts;
})
.catch(Notify.handleError);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form name="ActionForm" bh-form-defaults novalidate>
<form name="ActionForm" bh-submit="$ctrl.submit(ActionForm)" bh-form-defaults novalidate>
<div class="modal-header">
<i class="fa fa-list"></i>
<span ng-if="$ctrl.action==='add'">{{ 'INVENTORY.ADD_GROUP' | translate }}</span>
Expand Down Expand Up @@ -43,13 +43,14 @@

<ui-select
name="salesAccount"
ng-model="$ctrl.session.salesAccount"
theme="bootstrap"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
ng-model="$ctrl.session.salesAccount">
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}" allow-clear="true">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account in $ctrl.accountList | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === $ctrl.bhConstants.accounts.TITLE"
repeat="account in $ctrl.accounts | filter: { 'hrlabel' : $select.search } track by account.id">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand All @@ -66,12 +67,14 @@
</label>
<ui-select
name="stockAccount"
ng-model="$ctrl.session.stockAccount"
theme="bootstrap">
ng-model="$ctrl.session.stockAccount">
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}" allow-clear="true">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account in $ctrl.accountList | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === $ctrl.bhConstants.accounts.TITLE"
repeat="account in $ctrl.accounts | filter: { 'hrlabel' : $select.search } track by account.id">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand All @@ -85,12 +88,14 @@

<ui-select
name="cogsAccount"
ng-model="$ctrl.session.cogsAccount"
theme="bootstrap">
ng-model="$ctrl.session.cogsAccount">
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}" allow-clear="true">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account in $ctrl.accountList | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === $ctrl.bhConstants.accounts.TITLE"
repeat="account in $ctrl.accounts | filter: { 'hrlabel' : $select.search } track by account.id">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand All @@ -104,11 +109,9 @@
ng-click="$ctrl.cancel()">
{{ 'FORM.BUTTONS.CANCEL' | translate }}
</button>
<button type="submit"
class="btn btn-primary"
ng-click="$ctrl.submit(ActionForm)"
data-method="submit">

<bh-loading-button loading-state="ActionForm.$loading">
{{ 'FORM.BUTTONS.SUBMIT' | translate }}
</button>
</bh-loading-button>
</div>
</form>
16 changes: 2 additions & 14 deletions server/controllers/inventory/inventory/groups.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Inventory Groups Controller
* This controller is responsible for handling CRUD operations with inventory groups
Expand All @@ -17,24 +19,18 @@ exports.countInventory = countInventory;

/** list inventory group */
function list () {
'use strict';

return getGroups();
}

/** details of inventory group */
function details (identifier) {
'use strict';

return getGroups(identifier);
}



/** create new inventory group */
function create (record) {
'use strict';

record.uuid = db.bid(record.uuid || uuid.v4());

let sql = `INSERT INTO inventory_group SET ?;`;
Expand All @@ -48,8 +44,6 @@ function create (record) {

/** update an existing inventory group */
function update (record, identifier) {
'use strict';

let uid = db.bid(identifier);

let sql = `UPDATE inventory_group SET ? WHERE uuid = ?;`;
Expand All @@ -66,8 +60,6 @@ function update (record, identifier) {
* @param {string} uid the group uuid is optional
*/
function getGroups(uid) {
'use strict';

let sql = `
SELECT BUID(uuid) AS uuid, code, name, sales_account, cogs_account, stock_account
FROM inventory_group
Expand All @@ -83,8 +75,6 @@ function getGroups(uid) {
* @param {string} uid the group uuid
*/
function countInventory(uid) {
'use strict';

uid = (uid) ? db.bid(uid) : undefined;

let sql = `
Expand All @@ -97,8 +87,6 @@ function countInventory(uid) {

/** remove inventory group */
function remove (uuid) {
'use strict';

let uib = db.bid(uuid);
let sql = 'DELETE FROM inventory_group WHERE uuid = ?;';
return db.exec(sql, [uib]);
Expand Down
2 changes: 1 addition & 1 deletion server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ CREATE TABLE `inventory_group` (
`uuid` BINARY(16) NOT NULL,
`name` varchar(100) NOT NULL,
`code` varchar(30) NOT NULL,
`sales_account` mediumint(8) unsigned NOT NULL,
`sales_account` mediumint(8) unsigned DEFAULT NULL,
`cogs_account` mediumint(8) unsigned DEFAULT NULL,
`stock_account` mediumint(8) unsigned DEFAULT NULL,
`donation_account` mediumint(8) unsigned DEFAULT NULL,
Expand Down
6 changes: 2 additions & 4 deletions test/end-to-end/inventory/configuration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ describe('Inventory Configuration', () => {
code : '1704',
sales_account : 'Test Capital One',
stock_account : 'Test Capital Two',
cogs_account : 'Test Balance'
cogs_account : 'Test Debtor Accounts1'
};

const updateGroup = {
name : '[E2E] Inventory Group updated',
code : '2504',
sales_account : 'First Test Item Account',
stock_account : '',
cogs_account : ''
sales_account : 'Test Capital One',
};

// inventory type
Expand Down

0 comments on commit 8b0b859

Please sign in to comment.