Skip to main content
Solved

How to use decimal Precision in the DAC to default from company screen


Forum|alt.badge.img

I facing the issue with the unitcost field where datatype is decimal(25,6) and in the DAC, i have used 
[PXDBDecimal(typeof(Search<CommonSetup.decPlPrcCst>))]. In Company Screen i have set Price/Cost  = 4 still its defaulting 6 decimal place. please guide if missed any thing to default from the company set up.

 

 

Best answer by harikanthm60

@Naveen Boga thank you for you support. Using this DefaultUnitCost method its working as expected.
  protected virtual void DefaultUnitCost(PXCache sender, TSProdMTran row)
        {
            object UnitCost;
            sender.RaiseFieldDefaulting<TSProdMTran.unitCost>(row, out UnitCost);
            if (UnitCost != null && (decimal)UnitCost != 0m)
            {
                decimal? unitcost = INUnitAttribute.ConvertToBase<TSProdMTran.inventoryID>(sender, row, row.UOM, (decimal)UnitCost, INPrecision.UNITCOST);
                sender.SetValueExt<TSProdMTran.unitCost>(row, unitcost);
                decimal? extcost = row.IssueQty * row.UnitCost;
                sender.SetValueExt<TSProdMTran.extCost>(row, extcost);
            }

Below code is changing the decimal precision as set in the company screen using Price?cost decimal field.
decimal? unitcost = INUnitAttribute.ConvertToBase<TSProdMTran.inventoryID>(sender, row, row.UOM, (decimal)UnitCost, INPrecision.UNITCOST);

View original
Did this topic help you find an answer to your question?

7 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3409 replies
  • August 25, 2022

Hi @harikanthm60  Can you please share the DAC field?


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 15 replies
  • August 25, 2022

 @Naveen Boga  i have shared the dac field

#region UnitCost
        public abstract class unitCost : PX.Data.BQL.BqlDecimal.Field<unitCost>
        {
        }
        protected decimal? _UnitCost;
        //[PXDBPriceCost(MinValue = 0)]
        [PXDBDecimal(typeof(Search<CommonSetup.decPlPrcCst>))]
        [PXDefault(TypeCode.Decimal, "0.0", typeof(Coalesce<Search<INItemSite.tranUnitCost, Where<INItemSite.inventoryID, 
            Equal<Current<TSProdFormula.inventoryID>>, And<INItemSite.siteID, Equal<Current<TSProdFormula.siteID>>>>>,
            Search<INItemCost.tranUnitCost, Where<INItemCost.inventoryID, Equal<Current<TSProdFormula.inventoryID>>>>>))]
        [PXUIField(DisplayName = "Unit Cost",Enabled =false,IsReadOnly = true)]
        public virtual decimal? UnitCost
        {
            get
            {
                return this._UnitCost;
            }
            set
            {
                this._UnitCost = value;
            }
        }
        #endregion


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3409 replies
  • August 25, 2022

@harikanthm60  Can you please try with below instead of this -  [PXDBDecimal(typeof(Search<CommonSetup.decPlPrcCst>))]

 

I have not tested but can you try with the below one?

[PXPriceCost]


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 15 replies
  • August 25, 2022

I have tried Using [PXPriceCost] its not working. @Naveen Boga 

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3409 replies
  • August 26, 2022

@harikanthm60  Sorry for the multiple posts. [PXDBPriceCost] should work.

Have you tried this already?


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 15 replies
  • August 26, 2022

@Naveen Boga i have already tried  [PXDBPriceCost] an i pasted the DAC please do check its not working.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 15 replies
  • Answer
  • September 2, 2022

@Naveen Boga thank you for you support. Using this DefaultUnitCost method its working as expected.
  protected virtual void DefaultUnitCost(PXCache sender, TSProdMTran row)
        {
            object UnitCost;
            sender.RaiseFieldDefaulting<TSProdMTran.unitCost>(row, out UnitCost);
            if (UnitCost != null && (decimal)UnitCost != 0m)
            {
                decimal? unitcost = INUnitAttribute.ConvertToBase<TSProdMTran.inventoryID>(sender, row, row.UOM, (decimal)UnitCost, INPrecision.UNITCOST);
                sender.SetValueExt<TSProdMTran.unitCost>(row, unitcost);
                decimal? extcost = row.IssueQty * row.UnitCost;
                sender.SetValueExt<TSProdMTran.extCost>(row, extcost);
            }

Below code is changing the decimal precision as set in the company screen using Price?cost decimal field.
decimal? unitcost = INUnitAttribute.ConvertToBase<TSProdMTran.inventoryID>(sender, row, row.UOM, (decimal)UnitCost, INPrecision.UNITCOST);


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings