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

Codenarc integration #517

Closed
wants to merge 145 commits into from
Closed
Show file tree
Hide file tree
Changes from 144 commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
bacafa8
Implemented : add codenarc plugin usage with configuration based on s…
gilPts May 27, 2022
8bb7dec
Add commented text report type for codenarc
gilPts Dec 29, 2022
6752379
Fix codenarc AssignmentInConditional rule (OFBIZ-11167)
gilPts May 27, 2022
893bcb0
Fix codenarc ConstantAssertExpression rules : Checks for assert state…
gilPts Jan 13, 2023
d576d90
Fix codenarc DeadCode rule : Dead code appears after a return stateme…
gilPts Jul 1, 2022
1d94a0e
Fix codenarc EmptyCatchBlock rule : In most cases, exceptions should …
gilPts Jul 1, 2022
2451a4e
Fix codenarc EmptyElseBlock rule : Empty else blocks are confusing an…
gilPts Jul 1, 2022
151cc1f
Fix codenarc EmptyIfBlock rule : Empty if blocks are confusing and se…
gilPts Jul 1, 2022
9b148e6
Fix codenarc ElseBlockBraces rule Use braces for else blocks, even fo…
gilPts Jan 13, 2023
e85f460
Fix codenarc ForStatementBraces rule Use braces for for statements, e…
gilPts Jan 13, 2023
2b9c7ac
Add groovy parser script to get infracted rules ordered by number of …
gilPts Jul 3, 2022
230590a
Fix codenarc UnnecessaryGString rule : String objects should be creat…
gilPts Jul 12, 2022
905d185
Autofix of Indentation rule, review done. Remains issues
gilPts Jul 13, 2022
e1df9c6
Apply SpaceAroundOperator Rule
gilPts Jul 16, 2022
f1a681b
Apply TrailingWhitespace rule
gilPts Jul 16, 2022
d2597da
Apply UnnecessaryParenthesesForMethodCallWithClosure Rule Fix
gilPts Jul 16, 2022
43cea9e
Text format parser update to have table | syntax.
gilPts Aug 10, 2022
e67b9e0
Fix codenarc SpaceAroundMapEntryColon rules : Check for configured fo…
gilPts Aug 11, 2022
dbb74c5
NoDef rule implementation : remains 5 occurrence in GroovyBaseScript,…
gilPts Aug 12, 2022
476f8be
LineLength rule implementation
gilPts Aug 19, 2022
d6a38ff
Fix codenarc UnnecessaryObjectReferences rule : Violations are trigge…
gilPts Jan 13, 2023
2d37e83
Fix codenarc ExplicitCallToEqualsMethod rule : This rule detects when…
gilPts Dec 16, 2022
d97a65b
Fix codenarc IfStatementBraces rule : Use braces for if statements, e…
gilPts Dec 27, 2022
9374da0
Fix codenarc NoWildcardImports rule : Wildcard imports, static or oth…
gilPts Dec 29, 2022
cf2b0e4
Fix codenarc JavadocEmptyReturnTag rule : Checks for empty @return ta…
gilPts Dec 29, 2022
32fb43d
Fix codenarc CouldBeElvis rule : Catch an if block that could be writ…
gilPts Dec 30, 2022
df27b73
Fix codenarc UnusedImport rule : Imports for a class that is never re…
gilPts Dec 30, 2022
c39e4ef
Fix codenarc ConsecutiveBlankLines rule : Makes sure there are no con…
gilPts Dec 30, 2022
2d0d647
Fix codenarc InvertedIfElse rule : An inverted if-else statement is o…
gilPts Dec 30, 2022
1669295
Fix codenarc SpaceAfterComma rule : Checks that there is at least one…
gilPts Dec 30, 2022
61c4a55
Fix codenarc UnnecessarySemicolon rule : Semicolons as line terminato…
gilPts Dec 30, 2022
dfb86d9
Fix codenarc SpaceBeforeOpeningBrace rule : Check that there is at le…
gilPts Dec 30, 2022
a1db4f4
Fix codenarc SpaceBeforeOpeningBrace rule : Check that there is at le…
gilPts Dec 30, 2022
047b0be
Fix codenarc UnnecessaryGroovyImport rule : A Groovy file does not ne…
gilPts Dec 30, 2022
68f86ec
Fix codenarc BlockStartsWithBlankLine rule : Checks that code blocks …
gilPts Dec 30, 2022
8a0197b
Fix codenarc FileEndsWithoutNewline rule : Makes sure the source code…
gilPts Dec 30, 2022
2000a55
Fix codenarc ExplicitCallToCompareToMethod rules : This rule detects …
gilPts Dec 30, 2022
da3fe8e
Fix ExplicitCallToMultiply/PlusMethod codenarc rules : This rule dete…
gilPts Dec 30, 2022
cc890a7
Fix codenarc UnusedVariable rules : Checks for variables that are nev…
gilPts Dec 30, 2022
e83ef17
Fix codenarc InvertedCondition rules : An inverted condition is one w…
gilPts Jan 3, 2023
bda3160
Fix codenarc BlockStarts/EndsWithBlankLine rules : Checks that code b…
gilPts Jan 3, 2023
a6724f6
Fix codenarc NestedForLoop rules : Reports classes with nested for lo…
gilPts Jan 3, 2023
49107ec
Fix codenarc UnnecessaryPackageReference rules : Checks for explicit …
gilPts Jan 3, 2023
76ae6de
Fix codenarc Indentation rules : Check indentation for class and meth…
gilPts Jan 6, 2023
3b351c6
Fix codenarc UnnecessaryToString rules : Checks for unnecessary calls…
gilPts Jan 6, 2023
2d869c8
Fix codenarc UnnecessaryElseStatement rules : When an if statement bl…
gilPts Jan 6, 2023
d465a46
Fix codenarc ConfusingTernary rules : In a ternary expression avoid n…
gilPts Jan 6, 2023
adb0e9b
Fix codenarc JavadocMissingParamDescription rules : Checks for missin…
gilPts Jan 6, 2023
058e9bf
Fix codenarc UnnecessaryCast rules : Checks for unnecessary cast oper…
gilPts Jan 6, 2023
7ef169b
Fix codenarc LongLiteralWithLowerCaseL rules : In Java and Groovy, yo…
gilPts Jan 6, 2023
3c064f8
Fix codenarc NoDouble rules : Checks for use of the double or Double …
gilPts Jan 6, 2023
b294ef8
Fix codenarc AddEmptyString rules : Finds empty string literals whic…
gilPts Jan 6, 2023
4ffd621
Fix codenarc ExplicitArrayListInstantiation rules : This rule checks …
gilPts Jan 6, 2023
76d4c84
Fix codenarc CouldBeSwitchStatement rules : Checks for multiple if st…
gilPts Jan 6, 2023
fc60592
Fix codenarc LineLength rules : Checks the maximum length for each li…
gilPts Jan 6, 2023
6b098d4
Fix codenarc UnnecessaryBooleanInstantiation rules : Use Boolean.val…
gilPts Jan 6, 2023
05f39ab
Fix codenarc JavadocEmptyLastLine rules : check for javadoc comments…
gilPts Jan 6, 2023
5edaf98
Fix codenarc NoDef rules : def should not be used. You should replace…
gilPts Jan 6, 2023
ce420f8
Fix codenarc ReturnNullFromCatchBlock rules : Returning null from a c…
gilPts Jan 6, 2023
4b97381
Fix codenarc SpaceAfterCatch rules : Check that there is exactly one …
gilPts Jan 6, 2023
33746e5
Fix codenarc PublicMethodsBeforeNonPublicMethods rules : Enforce that…
gilPts Jan 6, 2023
b6e724e
Fix codenarc SpaceAfterOpeningBrace rules : Check that there is at le…
gilPts Jan 6, 2023
0e94039
Fix codenarc SpaceAroundOperator rules : Check that there is at least…
gilPts Jan 6, 2023
e9359b5
Fix codenarc ExplicitHashMapInstantiation rules : This rule checks fo…
gilPts Jan 6, 2023
b703a43
Fix codenarc MethodReturnTypeRequired rules : Checks that method retu…
gilPts Jan 6, 2023
e7341e6
Fix codenarc MethodReturnTypeRequired rules : Checks that method retu…
gilPts Jan 10, 2023
4b88eb8
Fix codenarc MissingBlankLineAfterImports rules : Makes sure there is…
gilPts Jan 10, 2023
e3b82e6
Fix codenarc MethodReturnTypeRequired rules : Checks that method retu…
gilPts Jan 10, 2023
045a8df
Fix codenarc SimpleDateFormatMissingLocale rules : Be sure to specify…
gilPts Jan 10, 2023
1bd3118
Fix codenarc TrailingWhitespace rules : Checks that no lines of sourc…
gilPts Jan 10, 2023
993bddf
Fix codenarc UnusedImport rules : Imports for a class that is never r…
gilPts Jan 11, 2023
79f05ce
Fix codenarc ImplementationAsType rules : Checks for use of a predef…
gilPts Jan 11, 2023
1afbfed
Fix codenarc ReturnsNullInsteadOfEmptyCollection rules : Consider ret…
gilPts Jan 11, 2023
45a3992
Fix codenarc UnnecessaryPublicModifier rules : The 'public' modifier …
gilPts Jan 11, 2023
e0824d2
Fix codenarc ExplicitHashSetInstantiation rules : This rule checks fo…
gilPts Jan 12, 2023
0b28cd9
Fix codenarc ExplicitLinkedListInstantiation rules : This rule checks…
gilPts Jan 12, 2023
ee0add0
Fix codenarc ExplicitTreeSetInstantiation rules : This rule checks fo…
gilPts Jan 12, 2023
ce59f09
Fix codenarc GStringAsMapKey rules : A GString should not be used as …
gilPts Jan 12, 2023
6e94957
Fix codenarc IfStatementCouldBeTernary rules : Checks for if statemen…
gilPts Jan 12, 2023
aee21e4
Fix codenarc NoJavaUtilDate rules : Do not use java.util.Date. Prefer…
gilPts Jan 12, 2023
2e38d64
Fix codenarc SpaceAfterClosingBrace rules : Check that there is at le…
gilPts Jan 12, 2023
264f6d7
Fix codenarc SpaceAfterFor rules : Check that there is exactly one sp…
gilPts Jan 12, 2023
c5d296c
Fix codenarc TernaryCouldBeElvis rules : Checks for ternary expressio…
gilPts Jan 12, 2023
930ad52
Fix codenarc UnnecessaryCallForLastElement rules : This rule checks f…
gilPts Jan 12, 2023
66087fc
Fix codenarc UnnecessaryDotClass rules : To make a reference to a cla…
gilPts Jan 12, 2023
578c6a7
Fix codenarc VariableName rules : Verifies that the name of each meth…
gilPts Jan 12, 2023
2f882f5
Fix codenarc BlankLineBeforePackage rules : Makes sure there are no b…
gilPts Jan 12, 2023
756d60f
Fix codenarc BracesForIfElse rules : Checks the location of the openi…
gilPts Jan 12, 2023
88aa7a1
Fix codenarc CatchNullPointerException rules : Catching NullPointerEx…
gilPts Jan 12, 2023
3c156f9
Fix codenarc ClassEndsWithBlankLine rules : Check whether the class e…
gilPts Jan 12, 2023
44dda0d
Fix codenarc ClassNameSameAsFilename rules : Reports files containing…
gilPts Jan 12, 2023
c884c21
Fix codenarc ClassStartsWithBlankLine rules : Check whether the class…
gilPts Jan 12, 2023
2d4759e
Fix codenarc DuplicateImport rules : Duplicate import statements are …
gilPts Jan 12, 2023
4948a5e
Fix codenarc GStringExpressionWithinString rules : Check for regular …
gilPts Jan 12, 2023
0587deb
Fix codenarc InsecureRandom rules : Reports usages of java.util.Rando…
gilPts Jan 12, 2023
891a54d
Fix codenarc MethodName rules : Verifies that the name of each method…
gilPts Jan 12, 2023
c3474f0
Fix codenarc MissingBlankLineAfterPackage rules : Makes sure there is…
gilPts Jan 12, 2023
d4e8b37
Fix codenarc NoFloat rules : Checks for use of the float or Float typ…
gilPts Jan 12, 2023
adb6ea1
Fix codenarc NoTabCharacter rules : Checks that all source files do n…
gilPts Jan 12, 2023
c24c10c
Fix codenarc ParameterName rules : Verifies that the name of each par…
gilPts Jan 12, 2023
7a68c47
Fix codenarc SpaceAroundClosureArrow rules : Checks that there is whi…
gilPts Jan 12, 2023
98ae328
Fix codenarc UnnecessaryBigDecimalInstantiation rules : It is unneces…
gilPts Jan 12, 2023
37c9a74
Fix codenarc UnnecessaryCollectCall rules : Some method calls to Obje…
gilPts Jan 12, 2023
aabdede
Fix codenarc UnnecessaryLongInstantiation rules : It is unnecessary t…
gilPts Jan 12, 2023
9124c3a
Fix codenarc InvertedCondition rules : An inverted condition is one w…
gilPts Jan 12, 2023
2530c42
Fix codenarc ClassJavadoc rules : Makes sure each class and interface…
gilPts Jan 12, 2023
43c2cf2
Fix codenarc ClassStartsWithBlankLine rules : Check whether the class…
gilPts Jan 12, 2023
187597a
Fix codenarc UnnecessaryPublicModifier rules : The 'public' modifier …
gilPts Jan 12, 2023
2e712d8
Fix codenarc ClassEndsWithBlankLine rules : Check whether the class e…
gilPts Jan 12, 2023
9dbe275
Fix codenarc UnnecessaryBigDecimalInstantiation rules : It is unneces…
gilPts Jan 12, 2023
7fc22f0
Fix codenarc JUnitStyleAssertions rules : This rule detects calling J…
gilPts Jan 12, 2023
5a6b51b
Fix codenarc BlankLineBeforePackage rules : Makes sure there are no b…
gilPts Jan 12, 2023
f972e28
Fix codenarc JUnitPublicNonTestMethod rules : Checks if a JUnit test …
gilPts Jan 12, 2023
31f4035
Fix codenarc ConfusingMultipleReturns rules : Multiple return values …
gilPts Jan 12, 2023
1ce61e2
Fix codenarc DuplicateMapKey rules : A map literal is created with du…
gilPts Jan 12, 2023
5d8006f
Fix codenarc MisorderedStaticImports rules : Static imports should ne…
gilPts Jan 12, 2023
906ed8a
Fix codenarc UnnecessaryLongInstantiation rules : It is unnecessary t…
gilPts Jan 12, 2023
e9a4e08
Fix codenarc AbstractClassWithoutAbstractMethod rules : The abstract …
gilPts Jan 12, 2023
5a31c96
Fix codenarc NoDef rules : def should not be used. You should replace…
gilPts Jan 12, 2023
41145b4
Fix codenarc UnnecessaryDotClass rules : To make a reference to a cla…
gilPts Jan 12, 2023
de89502
Fix codenarc PropertyName rules : Verifies that the name of each prop…
gilPts Jan 12, 2023
6493e46
Fix codenarc JUnitStyleAssertions rules : This rule detects calling J…
gilPts Jan 12, 2023
993af32
Fix codenarc UnnecessaryPublicModifier rules : The 'public' modifier …
gilPts Jan 12, 2023
969a174
Fix codenarc PublicMethodsBeforeNonPublicMethods rules : Enforce that…
gilPts Jan 12, 2023
9e2f71d
Fix codenarc NoDef rules : def should not be used. You should replace…
gilPts Jan 12, 2023
9a7ffd3
Fix codenarc UnnecessaryPublicModifier rules : The 'public' modifier …
gilPts Jan 12, 2023
17fac32
CodenarcMigration : fix old migrated test, that was enabled during mi…
gilPts Jan 13, 2023
8a83703
CodenarcMigration : remove old test that has never been active since …
gilPts Jan 13, 2023
cfcdc9e
CodenarcMigration : specify last codenarc version for java 17 compliance
gilPts Jan 20, 2023
9a7e8f1
Fix codenarc GStringExpressionWithinString rules : Check for regular …
gilPts Jan 20, 2023
a54ed06
Fix codenarc ReturnsNullInsteadOfEmptyCollection rules : Consider ret…
gilPts Jan 20, 2023
bb7c80b
Fix codenarc Indentation rules : Check indentation for class and meth…
gilPts Jan 20, 2023
0eec545
Removing "enhanced" rules from the ruleset, this are not necessary an…
gilPts Jan 20, 2023
3d7df5b
Delete custom parser used for integration
gilPts Jan 20, 2023
e7d0ae1
Revert "Add commented text report type for codenarc"
gilPts Jan 24, 2023
217c5a5
Improved: apply codenarc rules to new RequirementServices.groovy script
gilPts Jan 27, 2023
f58a85c
Add a test to avoid int cast exception
gilPts Feb 8, 2023
e51fe20
Improved: fix rounding that should by applied after operation
gilPts Feb 8, 2023
4bf86a2
Improved: remove useless variable.
gilPts Mar 3, 2023
8bab391
Update applications/marketing/groovyScripts/marketing/reports/Trackin…
gilPts Mar 10, 2023
72ab021
Update applications/marketing/groovyScripts/marketing/reports/Marketi…
gilPts Mar 10, 2023
44fd596
Apply suggestion from Nicolas in pull request
gilPts Mar 24, 2023
237c605
Remove codenarc disable comment, since using with method on object al…
gilPts Mar 24, 2023
54a7f8a
Apply suggestion from Jacques in
gilPts Mar 24, 2023
71ace35
Return dve value for variable Assignment, thanks Daniel Watford.
gilPts Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,47 @@ import org.apache.ofbiz.entity.GenericValue
import org.apache.ofbiz.entity.util.EntityUtil
gilPts marked this conversation as resolved.
Show resolved Hide resolved
import org.apache.ofbiz.service.ModelService


def createPartyAcctgPreference() {
Map createPartyAcctgPreference() {
//check that the party is an INTERNAL_ORGANIZATION, as defined in PartyRole
partyRole = select().from('PartyRole').where([partyId:parameters.partyId,roleTypeId:"INTERNAL_ORGANIZATIO"]).queryOne()
partyRole = select().from('PartyRole').where([partyId: parameters.partyId, roleTypeId: 'INTERNAL_ORGANIZATIO']).queryOne()
if (!partyRole) {
String errorMessage = UtilProperties.getMessage("AccountingUiLabels","AccountingPartyMustBeInternalOrganization", locale)
String errorMessage = UtilProperties.getMessage('AccountingUiLabels', 'AccountingPartyMustBeInternalOrganization', locale)
logError(errorMessage)
return error(errorMessage)
}
//Does not check if the Party is actually a company because real people have to pay taxes too

//TODO: maybe check to make sure that all fields are not null
newEntity = delegator.makeValidValue("PartyAcctgPreference", parameters)
newEntity = delegator.makeValidValue('PartyAcctgPreference', parameters)
delegator.create(newEntity)
return success()
}

def getPartyAccountingPreferences() {
Map getPartyAccountingPreferences() {
Map result = success()
GenericValue aggregatedPartyAcctgPref = delegator.makeValidValue("PartyAcctgPreference", parameters)
GenericValue aggregatedPartyAcctgPref = delegator.makeValidValue('PartyAcctgPreference', parameters)
String currentOrganizationPartyId = parameters.organizationPartyId
Boolean containsEmptyFields = true

while (currentOrganizationPartyId && containsEmptyFields) {
GenericValue currentPartyAcctgPref = select().from('PartyAcctgPreference').where([partyId:currentOrganizationPartyId]).queryOne()
GenericValue currentPartyAcctgPref = select().from('PartyAcctgPreference').where([partyId: currentOrganizationPartyId]).queryOne()
containsEmptyFields = false
if (currentPartyAcctgPref) {
for (String entityKey : currentPartyAcctgPref.keySet()) {
Object entityValue = currentPartyAcctgPref.get(entityKey)
if (entityValue) {
aggregatedPartyAcctgPref.put(entityKey,entityValue)
aggregatedPartyAcctgPref.put(entityKey, entityValue)
} else {
containsEmptyFields = true
}
}
} else {
containsEmptyFields = true
}
List<GenericValue> parentPartyRelationships = select().from('PartyRelationship').where([partyIdTo:currentOrganizationPartyId, partyRelationshipTypeId:"GROUP_ROLLUP", roleTypeIdFrom:"_NA_", roleTypeIdTo:"_NA_"]).filterByDate().queryList()
List<GenericValue> parentPartyRelationships = select().from('PartyRelationship')
.where([partyIdTo: currentOrganizationPartyId, partyRelationshipTypeId: 'GROUP_ROLLUP', roleTypeIdFrom: '_NA_',
roleTypeIdTo: '_NA_'])
.filterByDate().queryList()
if (parentPartyRelationships) {
GenericValue parentPartyRelationship = EntityUtil.getFirst(parentPartyRelationships)
currentOrganizationPartyId = parentPartyRelationship.partyIdFrom
Expand All @@ -73,34 +75,32 @@ def getPartyAccountingPreferences() {
}

if (aggregatedPartyAcctgPref) {
aggregatedPartyAcctgPref.put("partyId",parameters.organizationPartyId)
result.put("partyAccountingPreference", aggregatedPartyAcctgPref)
aggregatedPartyAcctgPref.put('partyId', parameters.organizationPartyId)
result.put('partyAccountingPreference', aggregatedPartyAcctgPref)
}
return result
}

def setAcctgCompany() {
Map setAcctgCompany() {
Map result = success()
//Set user preference
GenericValue partyAcctgPreference = select().from('PartyAcctgPreference').where([partyId: parameters.organizationPartyId]).queryOne()
if (partyAcctgPreference) {
result = runService("setUserPreference", [userPrefValue: parameters.organizationPartyId, userPrefGroupTypeId: "GLOBAL_PREFERENCES", userPrefTypeId: "ORGANIZATION_PARTY"])
result = runService('setUserPreference',
[userPrefValue: parameters.organizationPartyId, userPrefGroupTypeId: 'GLOBAL_PREFERENCES', userPrefTypeId: 'ORGANIZATION_PARTY'])
}
result.put("organizationPartyId", parameters.organizationPartyId)
result.put('organizationPartyId', parameters.organizationPartyId)

return result
}

def updateFXConversion() {
Map updateFXConversion() {
//Set the FX rate changes as of now
Timestamp nowTimestamp = parameters.asOfTimestamp
if (!nowTimestamp) {
nowTimestamp = UtilDateTime.nowTimestamp()
}
Timestamp nowTimestamp = parameters.asOfTimestamp ?: UtilDateTime.nowTimestamp()

//find the existing exchange rates for this currency pair
exprBldr = new EntityConditionBuilder()
condition = exprBldr.AND() {
condition = exprBldr.AND {
EQUALS(uomId: parameters.uomId)
EQUALS(uomIdTo: parameters.uomIdTo)
}
Expand All @@ -109,38 +109,35 @@ def updateFXConversion() {
EQUALS(purposeEnumId: parameters.purposeEnumId)
}
}
List<GenericValue> uomConversions = select().from('UomConversionDated').where(condition).orderBy("-fromDate").filterByDate().queryList()
List<GenericValue> uomConversions = select().from('UomConversionDated').where(condition).orderBy('-fromDate').filterByDate().queryList()

//expire all of them
for (GenericValue uomConversion : uomConversions) {
if (!parameters.fromDate) {
uomConversion.put("thruDate", nowTimestamp)
if (parameters.fromDate) {
uomConversion.put('thruDate', parameters.fromDate)
} else {
uomConversion.put("thruDate", parameters.fromDate)
uomConversion.put('thruDate', nowTimestamp)
}
}
delegator.storeAll(uomConversions)

//now create a new conversion relationship
Map createParams = dispatcher.getDispatchContext().makeValidContext("createUomConversionDated", ModelService.IN_PARAM, parameters)
Map createParams = dispatcher.getDispatchContext().makeValidContext('createUomConversionDated', ModelService.IN_PARAM, parameters)
if (!parameters.fromDate) {
createParams.put("fromDate", nowTimestamp)
createParams.put('fromDate', nowTimestamp)
}
result = runService("createUomConversionDated", createParams)
result = runService('createUomConversionDated', createParams)

return success()
}

def getFXConversion() {
Map getFXConversion() {
Map result = success()
Timestamp asOfTimestamp = parameters.asOfTimestamp
if (!asOfTimestamp) {
asOfTimestamp = UtilDateTime.nowTimestamp()
}
Timestamp asOfTimestamp = parameters.asOfTimestamp ?: UtilDateTime.nowTimestamp()

//find the existing exchange rates
exprBldr = new EntityConditionBuilder()
thruDateCondition = exprBldr.OR() {
thruDateCondition = exprBldr.OR {
EQUALS(thruDate: null)
GREATER_THAN_EQUAL_TO(thruDate: asOfTimestamp)
}
Expand All @@ -154,20 +151,20 @@ def getFXConversion() {
EQUALS(purposeEnumId: parameters.purposeEnumId)
}
}
List<GenericValue> rates = select().from('UomConversionDated').where(condition).orderBy("-fromDate").filterByDate().queryList()
List<GenericValue> rates = select().from('UomConversionDated').where(condition).orderBy('-fromDate').filterByDate().queryList()

BigDecimal conversionRate
int decimalScale = 2
int roundingMode = BigDecimal.ROUND_HALF_UP
if (rates) {
conversionFactor = EntityUtil.getFirst(rates).getBigDecimal("conversionFactor")
conversionFactor = EntityUtil.getFirst(rates).getBigDecimal('conversionFactor')
BigDecimal originalValue = BigDecimal.ONE
conversionRate = originalValue.divide(conversionFactor, decimalScale, roundingMode)
} else {
String errorMessage = "Could not find conversion rate"
String errorMessage = 'Could not find conversion rate'
logError(errorMessage)
return error(errorMessage)
}
result.put("conversionRate",conversionRate)
result.put('conversionRate', conversionRate)
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@

gilPts marked this conversation as resolved.
Show resolved Hide resolved
import org.apache.ofbiz.accounting.util.UtilAccounting

context.payments.removeAll{UtilAccounting.isReceipt(it)}
context.payments.removeAll { UtilAccounting.isReceipt(it) }
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.apache.ofbiz.entity.condition.EntityConditionBuilder
danwatford marked this conversation as resolved.
Show resolved Hide resolved

// Optional prefix parameter to filter InvoiceItemTypes by (i.e. "INV" or "PINV") defaults to INV
invItemTypePrefix = context.invItemTypePrefix ?: "INV"
invItemTypePrefix += "_%"
invItemTypePrefix = context.invItemTypePrefix ?: 'INV'
invItemTypePrefix += '_%'

organizationPartyId = parameters.organizationPartyId
exprBldr = new EntityConditionBuilder()
Expand All @@ -30,25 +30,25 @@ invoiceItemTypes = from('InvoiceItemType').where(exprBldr.LIKE(invoiceItemTypeId
context.invoiceItemTypes = invoiceItemTypes.collect { invoiceItemType ->
defaultAccount = true
glAccount = null
invoiceItemTypeOrgs = invoiceItemType.getRelated("InvoiceItemTypeGlAccount", [organizationPartyId : organizationPartyId], null, false)
invoiceItemTypeOrgs = invoiceItemType.getRelated('InvoiceItemTypeGlAccount', [organizationPartyId: organizationPartyId], null, false)
overrideGlAccountId = null
if (invoiceItemTypeOrgs) {
invoiceItemTypeOrg = invoiceItemTypeOrgs[0]
overrideGlAccountId = invoiceItemTypeOrg.glAccountId

glAccounts = invoiceItemTypeOrg.getRelated("GlAccount", null, null, false)
glAccounts = invoiceItemTypeOrg.getRelated('GlAccount', null, null, false)
if (glAccounts) {
glAccount = glAccounts[0]
defaultAccount = false
}
} else {
glAccount = invoiceItemType.getRelatedOne("DefaultGlAccount", false)
glAccount = invoiceItemType.getRelatedOne('DefaultGlAccount', false)
}

return [invoiceItemTypeId : invoiceItemType.invoiceItemTypeId,
description : invoiceItemType.description,
defaultGlAccountId : invoiceItemType.defaultGlAccountId,
overrideGlAccountId : overrideGlAccountId,
defaultAccount : defaultAccount,
activeGlDescription : glAccount?.accountName]
return [invoiceItemTypeId: invoiceItemType.invoiceItemTypeId,
description: invoiceItemType.description,
defaultGlAccountId: invoiceItemType.defaultGlAccountId,
overrideGlAccountId: overrideGlAccountId,
defaultAccount: defaultAccount,
activeGlDescription: glAccount?.accountName]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,63 @@
* under the License.
*/

import org.apache.ofbiz.service.ModelService;
import org.apache.ofbiz.service.ModelService
import org.apache.ofbiz.service.ServiceUtil

/**
* Copy an existing Agreement
*/

def copyAgreement() {
agreement = from('Agreement').where('agreementId', parameters.agreementId).queryOne();
Map copyAgreement() {
agreement = from('Agreement').where('agreementId', parameters.agreementId).queryOne()
serviceResult = success()
if (agreement) {
Map createAgreementInMap = dispatcher.getDispatchContext().makeValidContext('createAgreement', ModelService.IN_PARAM, agreement)
result = run service: 'createAgreement', with: createAgreementInMap
if (ServiceUtil.isError(result)) return result
if (ServiceUtil.isError(result)) {
return result
}
agreementIdTo = result.agreementId
agreementItems = agreement.getRelated('AgreementItem', null, null, false)
agreementItems.each { agreementItem ->
Map createAgreementItemInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementItem', ModelService.IN_PARAM, agreementItem)
Map createAgreementItemInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementItem',
ModelService.IN_PARAM, agreementItem)
createAgreementItemInMap.agreementId = agreementIdTo
result = run service: 'createAgreementItem', with: createAgreementItemInMap
}
if ('Y' == parameters.copyAgreementTerms) {
if (parameters.copyAgreementTerms == 'Y') {
agreementTerms = agreement.getRelated('AgreementTerm', null, null, false)
agreementTerms.each { agreementTerm ->
Map createAgreementTermInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementTerm', ModelService.IN_PARAM, agreementTerm)
Map createAgreementTermInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementTerm',
ModelService.IN_PARAM, agreementTerm)
createAgreementTermInMap.agreementId = agreementIdTo
createAgreementTermInMap.remove("agreementTermId")
createAgreementTermInMap.remove('agreementTermId')
result = run service: 'createAgreementTerm', with: createAgreementTermInMap
}
}
if ('Y' == parameters.copyAgreementProducts) {
if (parameters.copyAgreementProducts == 'Y') {
agreementProductAppls = agreement.getRelated('AgreementProductAppl', null, null, false)
agreementProductAppls.each { agreementProductAppl ->
Map createAgreementProductApplInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementProductAppl', ModelService.IN_PARAM, agreementProductAppl)
Map createAgreementProductApplInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementProductAppl',
ModelService.IN_PARAM, agreementProductAppl)
createAgreementProductApplInMap.agreementId = agreementIdTo
result = run service: 'createAgreementProductAppl', with: createAgreementProductApplInMap
}
}
if ('Y' == parameters.copyAgreementFacilities) {
if (parameters.copyAgreementFacilities == 'Y') {
agreementFacilityAppls = agreement.getRelated('AgreementFacilityAppl', null, null, false)
agreementFacilityAppls.each { agreementFacilityAppl ->
Map createAgreementFacilityApplInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementFacilityAppl', ModelService.IN_PARAM, agreementFacilityAppl)
Map createAgreementFacilityApplInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementFacilityAppl',
ModelService.IN_PARAM, agreementFacilityAppl)
createAgreementFacilityApplInMap.agreementId = agreementIdTo
result = run service: 'createAgreementFacilityAppl', with: createAgreementFacilityApplInMap
}
}
if ('Y' == parameters.copyAgreementParties) {
if (parameters.copyAgreementParties == 'Y') {
agreementPartyApplics = agreement.getRelated('AgreementPartyApplic', null, null, false)
agreementPartyApplics.each { agreementPartyApplic ->
Map createAgreementPartyApplicInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementPartyApplic', ModelService.IN_PARAM, agreementPartyApplic)
Map createAgreementPartyApplicInMap = dispatcher.getDispatchContext().makeValidContext('createAgreementPartyApplic',
ModelService.IN_PARAM, agreementPartyApplic)
createAgreementPartyApplicInMap.agreementId = agreementIdTo
result = run service: 'createAgreementPartyApplic', with: createAgreementPartyApplicInMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*******************************************************************************/
if (partyIdFrom) {
context.partyNameResultFrom = runService("getPartyNameForDate", [partyId: partyIdFrom, compareDate: agreementDate, lastNameFirst: "Y"])
context.partyNameResultFrom = runService('getPartyNameForDate', [partyId: partyIdFrom, compareDate: agreementDate, lastNameFirst: 'Y'])
}
if (partyIdTo) {
context.partyNameResultTo = runService("getPartyNameForDate", [partyId: partyIdTo, compareDate: agreementDate, lastNameFirst: "Y"])
}
context.partyNameResultTo = runService('getPartyNameForDate', [partyId: partyIdTo, compareDate: agreementDate, lastNameFirst: 'Y'])
}