Цитата:
Сообщение от
byte
После запуска переоценки я обнаружил, что она корректирует закрытые проводки.
По-видимому проблема, описанная в первом посте была вызвана именно переоценкой курсовых по закрытым проводкам. Во избежание этого рекомендую добавить в запросы CustRateAdjustment и VendRateAdjustment (возможно и EmplRateAdjustment_RU) критериев по полю Closed = 0.
Приведу код, который позволил сторнировать неправильные корректировки нереализованной курсовой. Для его работы требуется сделать public метод postExchAdj класса CustVendExchAdjustment_W.
X++:
CustTrans custTrans,
custTrans2,
custTransNew;
CustSettlement custSettlement,
custSettlement2;
CustTransOpen custTransOpen,
custTransOpen2;
LedgerTrans ledgerTrans;
ExchRate exchRate;
CustVendExchAdjustment_W custVendExchAdjustment;
CustVendTransSettlement custVendTransSettlement;
CustVendSettle custVendSettle;
CustVendExchAdj custVendExchAdj;
CustVendExchAdjTrans custVendExchAdjTrans;
LedgerVoucherGroup ledgerVoucherGroup;
LedgerVoucher ledgerVoucher;
LedgerVoucherObject ledgerVoucherObject;
TransDate transDate = 31\03\2013;
Voucher voucher;
Set set = new Set(types::Container);
SetIterator si;
;
while select forupdate custTrans where
custTrans.TransType != LedgerTransType::ExchAdjustment &&
custTrans.CurrencyCode != "RUR"
notexists join custTransOpen2 where
custTransOpen2.RefRecId == custTrans.RecId
{
if(custTrans.AmountMST != custTrans.SettleAmountMST - custTrans.ExchAdjustment)
{
if(custTrans.AmountMST == custTrans.SettleAmountMST - custTrans.CustExchAdjustmentRealized)
{
info(strfmt("Расходится на нереализованную курсовую;%1;%2;%3", custTrans.Voucher, custTrans.RecId, custTrans.TransDate));
while select custSettlement where
custSettlement.TransRecId == custTrans.RecId &&
custSettlement.ExchAdjustment
join custTrans2 where
custTrans2.Voucher == custSettlement.OffsetTransVoucher &&
custTrans2.TransType == LedgerTransType::ExchAdjustment &&
custTrans2.CustExchAdjustmentUnrealized
{
set.add([custTrans.RecId, custTrans2.RecId]);
}
}
else
{
info(strfmt(";%1;%2;%3", custTrans.Voucher, custTrans.RecId, custTrans.TransDate));
}
}
}
ttsbegin;
si = new SetIterator(set);
while(si.more())
{
custTrans = CustTrans::find(conpeek(si.value(), 1), true);
custTrans2 = CustTrans::find(conpeek(si.value(), 2));
custVendTransSettlement = CustVendTransSettlement::construct(SysModule::Cust);
custVendExchAdj = new CustExchAdj();
custVendExchAdjTrans = CustVendExchAdjTrans::construct(SysModule::Cust, custVendExchAdj);
custVendExchAdjustment = CustVendExchAdjustment_W::newFromExchAdj(custVendExchAdj, custVendExchAdjTrans);
custVendExchAdjustment.setCustVendTransSettlement(custVendTransSettlement);
custVendExchAdjustment.parmTransactionDate(transDate);
custVendExchAdjustment.setSettlementGroupPlaceHolder(1);
ledgerVoucher = LedgerVoucher::newLedgerPost( DetailSummary::Summary,
SysModule::Cust,
"" );
ledgerVoucher.parmCompanyId(curext());
//voucher = NumberSeq::newGetNum(CustParameters::numRefCustExchAdjVoucher()).num();
voucher = custTrans2.Voucher;
ledgerVoucherObject = LedgerVoucherObject::newVoucher( voucher,
transDate,
SysModule::Cust,
LedgerTransType::ExchAdjustment,
true );
ledgerVoucher.addVoucher(ledgerVoucherObject);
custVendExchAdjustment.parmLedgerVoucher(ledgerVoucher);
exchRate = ExchRates::findExchRateDate(custTrans.CurrencyCode,
custVendExchAdjTrans.exchrateDate(custTrans)).ExchRate;
custTrans.LastSettleVoucher = ledgerVoucher.lastVoucher();
custTrans.LastSettleCompany = ledgerVoucher.parmCompanyId();
custTrans.LastExchAdjVoucher = custTrans.LastSettleVoucher;
custTrans.LastExchAdjRate = exchRate;
custTrans.LastExchAdj = transDate;
custTrans.LastSettleDate = custTrans.LastExchAdj;
custTrans.update();
custVendExchAdjustment.postExchAdj( custTrans2.CustExchAdjustmentUnrealized,
custTrans,
true,
false,
"",
datenull(),
0,
NoneTableTrans::Transaction,
custTrans.Dimension,
custTrans.PostingProfile,
false,
"",
0,
false,
custTrans,
custTrans,
voucher );
custSettlement2 = custVendExchAdjustment.parmCustVendSettle().updateTransaction_W(custTrans, null);
custVendTransSettlement.addSettlement(custSettlement2, 1, custTrans.TransType);
ledgerVoucher.end();
custVendTransSettlement.post();
si.next();
}
ttscommit;