Skip to content

Commit

Permalink
Add default product for resource:
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Jan 20, 2025
1 parent c297afe commit 81112aa
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 9 deletions.
4 changes: 4 additions & 0 deletions base/src/org/compiere/model/MProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public static MProduct forS_Resource_ID(Properties ctx, int S_Resource_ID, Strin
}
}
// Load from DB
MResource resource = MResource.get(ctx, S_Resource_ID);
if(resource.get_ValueAsInt("S_DefaultProduct_ID") > 0) {
return MProduct.get(ctx, resource.get_ValueAsInt("S_DefaultProduct_ID"));
}
MProduct p = new Query(ctx, Table_Name, COLUMNNAME_S_Resource_ID+"=?", trxName)
.setParameters(new Object[]{S_Resource_ID})
.firstOnly();
Expand Down
24 changes: 15 additions & 9 deletions base/src/org/compiere/model/MResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ protected boolean beforeSave (boolean newRecord)
{
if (newRecord)
{
if (getValue() == null || getValue().length() == 0)
setValue(getName());
m_product = new MProduct(this, getResourceType());
m_product.saveEx(get_TrxName());
MResourceType resourceType = MResourceType.get(getCtx(), getS_ResourceType_ID());
if(resourceType.get_ValueAsInt("S_DefaultProduct_ID") > 0) {
set_ValueOfColumn("S_DefaultProduct_ID", resourceType.get_ValueAsInt("S_DefaultProduct_ID"));
} else {
if (getValue() == null || getValue().length() == 0)
setValue(getName());
m_product = new MProduct(this, getResourceType());
m_product.saveEx(get_TrxName());
}
}
//
// Validate Manufacturing Resource
Expand All @@ -174,11 +179,12 @@ protected boolean afterSave (boolean newRecord, boolean success)
{
if (!success)
return success;

MProduct prod = getProduct();
if (prod.setResource(this))
prod.saveEx(get_TrxName());

if(get_ValueAsInt("S_DefaultProduct_ID") <= 0) {
MProduct prod = getProduct();
if (prod.setResource(this)) {
prod.saveEx(get_TrxName());
}
}
return success;
} // afterSave

Expand Down
26 changes: 26 additions & 0 deletions resources/0.0.6/10330_SP000_Add_Entity_Type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Migrations>
<Migration EntityType="D" Name="SP000 Add Entity Type" ReleaseNo="0.0.6" SeqNo="10330">
<Step SeqNo="10" StepType="AD">
<PO AD_Table_ID="882" Action="I" Record_ID="50182" Table="AD_EntityType">
<Data AD_Column_ID="15604" Column="Version" isNewNull="true"/>
<Data AD_Column_ID="84318" Column="UUID">f4c494b6-70e9-44f2-acf3-9c15b1041434</Data>
<Data AD_Column_ID="15600" Column="UpdatedBy">100</Data>
<Data AD_Column_ID="15599" Column="Updated">2025-01-20 18:18:23.612</Data>
<Data AD_Column_ID="15607" Column="Processing">false</Data>
<Data AD_Column_ID="15601" Column="Name">Solop: Core Changes</Data>
<Data AD_Column_ID="15605" Column="ModelPackage">com.solop.sp000.model</Data>
<Data AD_Column_ID="15596" Column="IsActive">true</Data>
<Data AD_Column_ID="15603" Column="Help">https://github.com/solop-develop/adempiere-base</Data>
<Data AD_Column_ID="15592" Column="EntityType">SP000</Data>
<Data AD_Column_ID="15602" Column="Description">Core Changes</Data>
<Data AD_Column_ID="15598" Column="CreatedBy">100</Data>
<Data AD_Column_ID="15597" Column="Created">2025-01-20 18:18:23.612</Data>
<Data AD_Column_ID="15606" Column="Classpath" isNewNull="true"/>
<Data AD_Column_ID="15594" Column="AD_Org_ID">0</Data>
<Data AD_Column_ID="15595" Column="AD_EntityType_ID">50182</Data>
<Data AD_Column_ID="15593" Column="AD_Client_ID">0</Data>
</PO>
</Step>
</Migration>
</Migrations>
Loading

0 comments on commit 81112aa

Please sign in to comment.