Skip to content

Force Do Not Update Prices At All on Sales Return Request Terms ​

This Groovy script enforces one setting on document terms. Whenever a document term for Sales Return Request is saved, the script ticks Do Not Update Prices At All in its configuration, so that no return request term can be saved with automatic repricing switched on.

Customer-specific example

This script was written for one customer's setup. It is hard-wired to one document type and one setting; adapt it before you use it elsewhere:

  • It only touches terms whose document type is Sales Return Request.
  • It only sets Do Not Update Prices At All, on the From Document page of the term's configuration. To force a different setting, the script has to be edited.
Class nameEASetDoNotUpdateSalesPrice
ScriptEASetDoNotUpdateSalesPrice.groovy
Runs onDocument Term. Target action PreUpdateCalculatedFields.
UsesNo parameters. Leave Parameter 1 empty.
Shipped asSource to paste. It is not built into the system.

When to use it ​

A sales return request is usually made from the original invoice, and the customer must be refunded at the price they actually paid. If the request's term lets the system recalculate prices, a price list that has changed since the sale can quietly alter the refund. The setting that prevents this is described under Price-Update Control. This script makes sure it can never be left off, even when someone adds a new return request term later.

It also shows a pattern worth knowing: an entity flow on Document Term can read and change the term's configuration while the term is being saved.

How it works ​

  1. It checks the document type. If the term being saved is not for Sales Return Request, the script does nothing.
  2. It sets the option. It ticks Do Not Update Prices At All in the term's configuration. The term is then saved with the option on, whatever the user chose.

Setting it up ​

  1. Open Administration → Display Customization → Entity Flow and create a flow with target type Document Term.
  2. In the Details grid, add a line with Target Action set to PreUpdateCalculatedFields, and paste the whole script into its Groovy Script column. Leave Class Name empty: it is filled in when you save.
  3. Leave all parameters empty, and save the flow.
  4. Open each existing Sales Return Request term on Basic → Settings → Document Term, make any change and save it, so that the script runs on it once. Terms created later are covered on their first save.

The script ​

groovy
package com.namasoft.modules.supplychain.domain.utils.plugnplay.groovy

import com.namasoft.common.utilities.ObjectChecker
import com.namasoft.infra.domainbase.datafields.BooleanDF
import com.namasoft.infra.domainbase.datafields.LongTextDF
import com.namasoft.infra.domainbase.entity.base.EntityAction
import com.namasoft.infra.domainbase.modules.basic.bookandterm.DocumentTerm
import com.namasoft.infra.domainbase.util.Result
import com.namasoft.modules.supplychain.domain.valueobjects.SalesDocTermConfig
import com.namasoft.modules.supplychain.utils.SCEntityTypes

public class EASetDoNotUpdateSalesPrice implements EntityAction<DocumentTerm> {
    @Override
    Result doAction(DocumentTerm term, LongTextDF... parameters) {
        Result result = Result.createAccumulatingResult();
        if (ObjectChecker.areNotEqual(term.getDocumentType(), SCEntityTypes.SalesReturnRequest()))
            return result;
        SalesDocTermConfig config = term.getTermConfig();
        config.setDoNotUpdatePricesAtAll(BooleanDF.TRUE());
        return result;
    }

    @Override
    String describe() {
        return "Use it on PreUpdateCalculatedFields of Document Term. When a term for Sales Return Request is saved, the script ticks " +
                "Do Not Update Prices At All on the From Document page of its configuration, so a user cannot leave it off. " +
                "Terms of other document types are saved unchanged. Parameter 1 is not used.";
    }

    @Override
    List<String> columnNames() {
        return Arrays.asList("Not used - leave empty");
    }
}