Skip to content

Commit

Permalink
Merge pull request #6000 from metasfresh/gh5999
Browse files Browse the repository at this point in the history
Gh5999 Add Shipment to Customs Invoice
  • Loading branch information
teosarca committed Jan 7, 2020
2 parents 7d99247 + 3e9dcc7 commit c81a458
Show file tree
Hide file tree
Showing 12 changed files with 560 additions and 236 deletions.
@@ -0,0 +1,78 @@
-- 2020-01-07T13:42:28.321Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process (AccessLevel,AD_Client_ID,AD_Org_ID,AD_Process_ID,AllowProcessReRun,Classname,CopyFromProcess,Created,CreatedBy,EntityType,IsActive,IsApplySecuritySettings,IsBetaFunctionality,IsDirectPrint,IsOneInstanceOnly,IsReport,IsServerProcess,IsTranslateExcelHeaders,IsUseBPartnerLanguage,LockWaitTimeout,Name,RefreshAllAfterExecution,ShowHelp,Type,Updated,UpdatedBy,Value) VALUES ('3',0,0,541240,'Y','de.metas.customs.process.M_InOut_AddTo_CustomsInvoice','N',TO_TIMESTAMP('2020-01-07 15:42:28','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','N','N','N','N','N','N','Y','Y',0,'Add Shipments To Customs Invoice','N','N','Java',TO_TIMESTAMP('2020-01-07 15:42:28','YYYY-MM-DD HH24:MI:SS'),100,'M_InOut_AddTo_CustomsInvoice')
;

-- 2020-01-07T13:42:28.331Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Trl (AD_Language,AD_Process_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language, t.AD_Process_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process t WHERE l.IsActive='Y'AND (l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N') AND t.AD_Process_ID=541240 AND NOT EXISTS (SELECT 1 FROM AD_Process_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_ID=t.AD_Process_ID)
;

-- 2020-01-07T13:43:01.929Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Element_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAutocomplete,IsCentrallyMaintained,IsEncrypted,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,187,0,541240,541661,30,'C_BPartner_ID',TO_TIMESTAMP('2020-01-07 15:43:01','YYYY-MM-DD HH24:MI:SS'),100,'Bezeichnet einen Geschäftspartner','D',0,'Ein Geschäftspartner ist jemand, mit dem Sie interagieren. Dies kann Lieferanten, Kunden, Mitarbeiter oder Handelsvertreter umfassen.','Y','N','Y','N','Y','N','Geschäftspartner',10,TO_TIMESTAMP('2020-01-07 15:43:01','YYYY-MM-DD HH24:MI:SS'),100)
;

-- 2020-01-07T13:43:01.935Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language, t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y'AND (l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N') AND t.AD_Process_Para_ID=541661 AND NOT EXISTS (SELECT 1 FROM AD_Process_Para_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_Para_ID=t.AD_Process_Para_ID)
;

-- 2020-01-07T13:43:44.053Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Element_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,AD_Val_Rule_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAutocomplete,IsCentrallyMaintained,IsEncrypted,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,189,0,541240,541662,30,131,'C_BPartner_Location_ID',TO_TIMESTAMP('2020-01-07 15:43:43','YYYY-MM-DD HH24:MI:SS'),100,'Identifiziert die (Liefer-) Adresse des Geschäftspartners','D',0,'Identifiziert die Adresse des Geschäftspartners','Y','N','Y','N','Y','N','Standort',20,TO_TIMESTAMP('2020-01-07 15:43:43','YYYY-MM-DD HH24:MI:SS'),100)
;

-- 2020-01-07T13:43:44.057Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language, t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y'AND (l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N') AND t.AD_Process_Para_ID=541662 AND NOT EXISTS (SELECT 1 FROM AD_Process_Para_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_Para_ID=t.AD_Process_Para_ID)
;

-- 2020-01-07T13:44:11.276Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Element_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,ColumnName,Created,CreatedBy,EntityType,FieldLength,IsActive,IsAutocomplete,IsCentrallyMaintained,IsEncrypted,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,576742,0,541240,541663,30,'C_Customs_Invoice_Line_ID',TO_TIMESTAMP('2020-01-07 15:44:11','YYYY-MM-DD HH24:MI:SS'),100,'D',0,'Y','N','Y','N','N','N','Customs Invoice Line',30,TO_TIMESTAMP('2020-01-07 15:44:11','YYYY-MM-DD HH24:MI:SS'),100)
;

-- 2020-01-07T13:44:11.279Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language, t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y'AND (l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N') AND t.AD_Process_Para_ID=541663 AND NOT EXISTS (SELECT 1 FROM AD_Process_Para_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_Para_ID=t.AD_Process_Para_ID)
;

-- 2020-01-07T13:49:05.309Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Val_Rule (AD_Client_ID,AD_Org_ID,AD_Val_Rule_ID,Created,CreatedBy,EntityType,IsActive,Name,Type,Updated,UpdatedBy) VALUES (0,0,540478,TO_TIMESTAMP('2020-01-07 15:49:05','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','C_Customs_Invoice_For_Partner_And_Location','S',TO_TIMESTAMP('2020-01-07 15:49:05','YYYY-MM-DD HH24:MI:SS'),100)
;

-- 2020-01-07T13:50:09.954Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Val_Rule SET Code='C_Customs_Invoice.C_BPartner_ID=@C_BPartner_ID@ AND C_Customs_Invoice.C_BPartner_Location_ID=@C_BPartner_Location_ID@',Updated=TO_TIMESTAMP('2020-01-07 15:50:09','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Val_Rule_ID=540478
;

-- 2020-01-07T13:50:41.590Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Process_Para SET AD_Element_ID=576740, ColumnName='C_Customs_Invoice_ID', Name='Zollrechnung',Updated=TO_TIMESTAMP('2020-01-07 15:50:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=541663
;

-- 2020-01-07T13:51:20.830Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Process_Para SET AD_Val_Rule_ID=540478,Updated=TO_TIMESTAMP('2020-01-07 15:51:20','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=541663
;

-- 2020-01-07T17:37:54.661Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Table_Process (AD_Client_ID,AD_Org_ID,AD_Process_ID,AD_Table_ID,AD_Table_Process_ID,AD_Window_ID,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,WEBUI_DocumentAction,WEBUI_IncludedTabTopAction,WEBUI_ViewAction,WEBUI_ViewQuickAction,WEBUI_ViewQuickAction_Default) VALUES (0,0,541240,319,540774,169,TO_TIMESTAMP('2020-01-07 19:37:54','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_TIMESTAMP('2020-01-07 19:37:54','YYYY-MM-DD HH24:MI:SS'),100,'Y','N','Y','N','N')
;






-- 2020-01-07T19:22:45.491Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_Val_Rule SET Code='C_Customs_Invoice.C_BPartner_ID=@C_BPartner_ID@ AND C_Customs_Invoice.C_BPartner_Location_ID=@C_BPartner_Location_ID@ AND C_Customs_Invoice.DocStatus = ''DR''',Updated=TO_TIMESTAMP('2020-01-07 21:22:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Val_Rule_ID=540478
;




Expand Up @@ -4,7 +4,6 @@
import de.metas.organization.OrgId;
import de.metas.product.ProductId;
import de.metas.quantity.Quantity;
import de.metas.uom.UomId;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -52,9 +51,6 @@ public class CustomsInvoiceLine
@NonNull
Quantity quantity;

@NonNull
UomId uomId;

@NonNull
OrgId orgId;

Expand Down
@@ -1,11 +1,11 @@
package de.metas.customs;

import static org.adempiere.model.InterfaceWrapperHelper.deleteAll;
import static org.adempiere.model.InterfaceWrapperHelper.deleteRecord;
import static org.adempiere.model.InterfaceWrapperHelper.load;
import static org.adempiere.model.InterfaceWrapperHelper.newInstance;
import static org.adempiere.model.InterfaceWrapperHelper.saveRecord;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
Expand All @@ -14,7 +14,6 @@
import org.adempiere.ad.dao.IQueryBL;
import org.compiere.model.I_C_Customs_Invoice;
import org.compiere.model.I_C_Customs_Invoice_Line;
import org.compiere.model.I_C_UOM;
import org.compiere.model.I_M_InOutLine;
import org.compiere.model.I_M_InOutLine_To_C_Customs_Invoice_Line;
import org.compiere.model.I_M_Product;
Expand All @@ -40,6 +39,7 @@
import de.metas.product.IProductDAO;
import de.metas.product.ProductId;
import de.metas.quantity.Quantity;
import de.metas.quantity.Quantitys;
import de.metas.uom.IUOMDAO;
import de.metas.uom.UomId;
import de.metas.user.UserId;
Expand Down Expand Up @@ -200,18 +200,15 @@ private Function<I_C_Customs_Invoice_Line, CustomsInvoiceLine> constructCustomsI
@NonNull final CurrencyId currencyId)
{
return customsInvoiceLinePo -> {
final I_M_Product product = productDAO.getById(customsInvoiceLinePo.getM_Product_ID());
final I_C_UOM uom = uomDAO.getById(product.getC_UOM_ID());
final Quantity qty = Quantity.of(BigDecimal.ZERO, uom);

final Quantity qty = Quantitys.create(customsInvoiceLinePo.getInvoicedQty(), UomId.ofRepoId(customsInvoiceLinePo.getC_UOM_ID()));
final Money lineNetAmt = Money.of(customsInvoiceLinePo.getLineNetAmt(), currencyId);

return CustomsInvoiceLine.builder()
.id(CustomsInvoiceLineId.ofRepoId(customsInvoiceId, customsInvoiceLinePo.getC_Customs_Invoice_Line_ID()))
.lineNo(customsInvoiceLinePo.getLineNo())
.productId(ProductId.ofRepoId(customsInvoiceLinePo.getM_Product_ID()))
.quantity(qty)
.uomId(UomId.ofRepoId(product.getC_UOM_ID()))
.orgId(Env.getOrgId())
.lineNetAmt(lineNetAmt)
.build();
Expand Down Expand Up @@ -259,8 +256,6 @@ record = existingRecord;
final ProductId productId = line.getProductId();
record.setM_Product_ID(productId.getRepoId());

record.setC_UOM_ID(line.getUomId().getRepoId());

saveRecord(record);

line.setId(CustomsInvoiceLineId.ofRepoId(record.getC_Customs_Invoice_ID(), record.getC_Customs_Invoice_Line_ID()));
Expand All @@ -280,9 +275,9 @@ public CustomsInvoice updateDocActionAndStatus(@NonNull final CustomsInvoice cus
.build();
}

public void setCustomsInvoiceLineToShipmentLine(
@NonNull final InOutAndLineId shipmentLine,
public void setCustomsInvoiceLineToShipmentLine(@NonNull final InOutAndLineId shipmentLine,
@NonNull final CustomsInvoiceLineId customsInvoiceLineId,
@NonNull final Quantity inoutLineQtyInPriceUOM,
@NonNull final Money priceActual)
{
final IInOutDAO inoutDAO = Services.get(IInOutDAO.class);
Expand All @@ -298,14 +293,14 @@ public void setCustomsInvoiceLineToShipmentLine(
inoutLineToCustomsInvoiceLine.setC_Customs_Invoice_ID(customsInvoiceLineRecord.getC_Customs_Invoice_ID());

inoutLineToCustomsInvoiceLine.setM_Product_ID(shipmentLineRecord.getM_Product_ID());
inoutLineToCustomsInvoiceLine.setC_UOM_ID(shipmentLineRecord.getC_UOM_ID());
inoutLineToCustomsInvoiceLine.setMovementQty(shipmentLineRecord.getMovementQty());

inoutLineToCustomsInvoiceLine.setC_UOM_ID(inoutLineQtyInPriceUOM.getUomId().getRepoId());
inoutLineToCustomsInvoiceLine.setMovementQty(inoutLineQtyInPriceUOM.toBigDecimal());

inoutLineToCustomsInvoiceLine.setPriceActual(priceActual.toBigDecimal());
inoutLineToCustomsInvoiceLine.setC_Currency_ID(priceActual.getCurrencyId().getRepoId());

saveRecord(inoutLineToCustomsInvoiceLine);

}

public Set<ProductId> retrieveProductIdsWithNoCustomsTariff(final CustomsInvoiceId customsInvoiceId)
Expand All @@ -328,4 +323,9 @@ private boolean hasNoCustomsTariff(final I_C_Customs_Invoice_Line line)
return product.getM_CustomsTariff_ID() <= 0;
}

public void deleteAllocation(I_M_InOutLine_To_C_Customs_Invoice_Line shipmentLineToCustomsInvoiceLineAlloc)
{
deleteRecord(shipmentLineToCustomsInvoiceLineAlloc);
}

}

0 comments on commit c81a458

Please sign in to comment.