Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #144 added ability to define a product that represents a bill o… #147

Merged
merged 2 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixed #144 added ability to define a product that represents a bill o…
…f materials
  • Loading branch information
jmiranda committed May 6, 2016
commit acd8985a5ba265dfb2960f56f84767d4cc89efaa
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.google.zxing.BarcodeFormat
import com.mysql.jdbc.MysqlDataTruncation
import grails.converters.JSON
import org.pih.warehouse.core.MailService
import org.pih.warehouse.core.UnitOfMeasure

import javax.activation.MimetypesFileTypeMap
import java.sql.SQLException
Expand Down Expand Up @@ -1074,6 +1075,23 @@ class ProductController {
render(template:'productGroups', model:[product: product, productGroups:product.productGroups])
}

def addProductComponent = {
Product assemblyProduct = productService.addProductComponent(params.assemblyProduct.id, params.componentProduct.id, params.quantity as BigDecimal, params.unitOfMeasure)
render(template:'productComponents', model:[productInstance: assemblyProduct])
}

def deleteProductComponent = {

def productInstance
def productComponent = ProductComponent.get(params.id)
if (productComponent) {
productInstance = productComponent.assemblyProduct
productComponent.assemblyProduct.removeFromProductComponents(productComponent)
productComponent.delete()
}
render(template:'productComponents', model:[productInstance: productInstance])
}

/**
* Delete product group from database
*/
Expand Down
12 changes: 11 additions & 1 deletion grails-app/domain/org/pih/warehouse/product/Product.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Product implements Comparable, Serializable {
// http:https://en.wikipedia.org/wiki/Stock_keeping_unit
String productCode

// Type of product (good, service, fixed asset)
ProductType productType

// Price per unit (global for the entire system)
Float pricePerUnit

Expand Down Expand Up @@ -194,6 +197,8 @@ class Product implements Comparable, Serializable {
// Secondary categories (currently not used)
List categories = new ArrayList();

List productComponents

// Auditing
Date dateCreated;
Date lastUpdated;
Expand All @@ -212,7 +217,8 @@ class Product implements Comparable, Serializable {
packages: ProductPackage,
synonyms: Synonym,
inventoryLevels: InventoryLevel,
inventoryItems: InventoryItem
inventoryItems: InventoryItem,
productComponents: ProductComponent
]

static mapping = {
Expand All @@ -224,14 +230,18 @@ class Product implements Comparable, Serializable {
documents joinTable: [name: 'product_document', column: 'document_id', key: 'product_id']
productGroups joinTable: [name: 'product_group_product', column: 'product_group_id', key: 'product_id']
synonyms cascade: 'all-delete-orphan', sort: 'name'
productComponents cascade: "all-delete-orphan"
}

static mappedBy = [productComponents:"assemblyProduct"]

static constraints = {
name(nullable: false, blank: false, maxSize: 255)
description(nullable: true)
productCode(nullable: true, maxSize: 255, unique: true)
unitOfMeasure(nullable: true, maxSize: 255)
category(nullable: false)
productType(nullable:true)

active(nullable: true)
coldChain(nullable: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2012 Partners In Health. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http:https://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
package org.pih.warehouse.product

import org.pih.warehouse.core.UnitOfMeasure

class ProductComponent {

String id
Product componentProduct
BigDecimal quantity
UnitOfMeasure unitOfMeasure

Date dateCreated
Date lastUpdated


static belongsTo = [assemblyProduct:Product]

static mapping = {
id generator: 'uuid'
}

static constraints = {
componentProduct(nullable: false)
quantity(nullable: false)
unitOfMeasure(nullable: false)
assemblyProduct(nullable:false)
}
}
24 changes: 24 additions & 0 deletions grails-app/domain/org/pih/warehouse/product/ProductType.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2012 Partners In Health. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http:https://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
package org.pih.warehouse.product

class ProductType {

String name
ProductTypeCode productTypeCode

Date dateCreated
Date lastUpdated

static constraints = {
name(blank:false)
productTypeCode(nullable:false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9 http:https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">

<changeSet author="jmiranda (generated)" id="1462507674793-1">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="product_component"/>
</not>
</preConditions>
<createTable tableName="product_component">
<column autoIncrement="false" name="id" type="CHAR(38)">
<constraints nullable="false" primaryKey="true" />
</column>
<column name="assembly_product_id" type="CHAR(38)">
<constraints nullable="false"/>
</column>
<column name="component_product_id" type="CHAR(38)">
<constraints nullable="false"/>
</column>
<column name="quantity" type="DECIMAL(19,2)">
<constraints nullable="false"/>
</column>
<column name="unit_of_measure_id" type="CHAR(38)">
<constraints nullable="false"/>
</column>
<column name="version" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="date_created" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="last_updated" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="product_components_idx" type="INT"/>
</createTable>
</changeSet>

<changeSet author="jmiranda (generated)" id="1462507674793-2">
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="FKB511C5AD20E351EA"/>
</not>
</preConditions>
<addForeignKeyConstraint baseColumnNames="component_product_id" baseTableName="product_component"
constraintName="FKB511C5AD20E351EA" deferrable="false" initiallyDeferred="false"
referencedColumnNames="id" referencedTableName="product"/>
</changeSet>

<changeSet author="jmiranda (generated)" id="1462507674793-3">
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="FKB511C5AD24DEBC91"/>
</not>
</preConditions>
<addForeignKeyConstraint baseColumnNames="unit_of_measure_id" baseTableName="product_component"
constraintName="FKB511C5AD24DEBC91" deferrable="false" initiallyDeferred="false"
referencedColumnNames="id" referencedTableName="unit_of_measure"/>
</changeSet>
<changeSet author="jmiranda (generated)" id="1462507674793-4">
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="FKB511C5ADFB4C199C"/>
</not>
</preConditions>
<addForeignKeyConstraint baseColumnNames="assembly_product_id" baseTableName="product_component"
constraintName="FKB511C5ADFB4C199C" deferrable="false" initiallyDeferred="false"
referencedColumnNames="id" referencedTableName="product"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9 http:https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">

<changeSet author="jmiranda (generated)" id="1462558005401-1">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="product_type"/>
</not>
</preConditions>
<createTable tableName="product_type">
<column autoIncrement="false" name="id" type="CHAR(38)">
<constraints nullable="false" primaryKey="true" />
</column>
<column name="version" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="date_created" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="last_updated" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="product_type_code" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet author="jmiranda (generated)" id="1462558005401-2">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="product" columnName="product_type_id"/>
</not>
</preConditions>
<addColumn tableName="product">
<column name="product_type_id" type="CHAR(38)"/>
</addColumn>
</changeSet>

<changeSet author="jmiranda (generated)" id="1462558005401-3">
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="FKED8DCCEFABD88AC6"/>
</not>
</preConditions>
<addForeignKeyConstraint baseColumnNames="product_type_id" baseTableName="product"
constraintName="FKED8DCCEFABD88AC6" deferrable="false" initiallyDeferred="false"
referencedColumnNames="id" referencedTableName="product_type"/>
</changeSet>


</databaseChangeLog>
9 changes: 9 additions & 0 deletions grails-app/migrations/0.8.x/changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9 http:https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">

<include file="0.8.x/changelog-2016-05-04-2245-create-product-type-table.xml"/>
<include file="0.8.x/changelog-2016-05-04-2245-create-product-component-table.xml"/>

</databaseChangeLog>
1 change: 1 addition & 0 deletions grails-app/migrations/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

<include file="0.5.x/changelog.xml"/>
<include file="0.6.x/changelog.xml"/>
<include file="0.8.x/changelog.xml"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.pih.warehouse.auth.AuthService
import org.pih.warehouse.core.ApiException
import org.pih.warehouse.core.Constants
import org.pih.warehouse.core.Tag
import org.pih.warehouse.core.UnitOfMeasure
import org.pih.warehouse.importer.ImportDataCommand
import org.pih.warehouse.inventory.InventoryLevel
import org.pih.warehouse.inventory.TransactionCode
Expand Down Expand Up @@ -1132,4 +1133,23 @@ class ProductService {
return similarProducts
}


Product addProductComponent(String assemblyProductId, String componentProductId, BigDecimal quantity, String unitOfMeasureId) {
def assemblyProduct = Product.get(assemblyProductId)
if (assemblyProduct) {
def componentProduct = Product.get(componentProductId)
if (componentProduct) {
def unitOfMeasure = UnitOfMeasure.get(unitOfMeasureId)
log.info "Adding " + componentProduct.name + " to " + assemblyProduct.name

ProductComponent productComponent = new ProductComponent(componentProduct: componentProduct,
quantity: quantity, unitOfMeasure: unitOfMeasure, assemblyProduct: assemblyProduct)
assemblyProduct.addToProductComponents(productComponent)
assemblyProduct.save(flush:true, failOnError: true)
}
}
return assemblyProduct
}


}
Loading