[ 
https://issues.apache.org/jira/browse/OFBIZ-5345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13859493#comment-13859493
 ] 

Paul Foxworthy commented on OFBIZ-5345:
---------------------------------------

Hi Christian,

I'm confused.

At 
https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?hb=true#to252,
 a new invoice is created, with a new invoice id. So there should never be 
existing invoice items for the newly created invoice. The code in the patch for 
InvoiceServices.java assumes there might be, and generates a sequence number 
greater than any existing item. If I'm right, there will never be any existing 
invoice item, and the trunk code setting the sequence to a simple 1 is fine.

I don't see how your proposed change to InvoiceServices.java would fix the 
primary key violation you saw.

The proposed changes for InvoiceServices.xml won't do any harm, but they will 
add overhead to invoice creation. If you know you're starting with a brand new 
invoice, there ought to be no need to check for any related InvoiceRoles or 
ContactMechs. There won't be any.

The primary key violation you are seeing seems to me to be coming from here: 
https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?hb=true#to270

The only reason the violation would arise is if you had two OrderRoles with the 
same party and the same roleTypeId. I wonder if the reason Jacopo can't 
duplicate the problem is that he doesn't have that starting state. If I'm 
right, a better fix would be to prevent duplicate OrderRoles in the first 
place, rather than adding overhead to creating an invoice. Perhaps we are 
missing a primary key or unique constraint on the OrderRole.

In short, I'm not yet convinced the changes are necessary. What am I missing?

Cheers

Paul Foxworthy


> Cannot pick or pack shipment for mutiple sales orders
> -----------------------------------------------------
>
>                 Key: OFBIZ-5345
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-5345
>             Project: OFBiz
>          Issue Type: Bug
>          Components: order
>    Affects Versions: Release Branch 12.04
>            Reporter: Christian Carlow
>         Attachments: InvoiceServices.java.patch, InvoiceServices.xml.patch
>
>
> I get this error when trying to change the statusId of a shipment to picked 
> or packed:
> Error calling event: org.ofbiz.webapp.event.EventHandlerException: Service 
> invocation error (Could not commit transaction for service [updateShipment] 
> call: Roll back error, could not commit transaction, was rolled back instead 
> because of: Failure in create operation for entity [InvoiceRole]: 
> org.ofbiz.entity.GenericEntityException: Error while inserting: 
> [GenericEntity:InvoiceRole][createdStamp,2013-10-09 
> 13:13:57.498(java.sql.Timestamp)][createdTxStamp,2013-10-09 
> 13:13:49.522(java.sql.Timestamp)][datetimePerformed,2013-10-09 
> 13:13:57.498(java.sql.Timestamp)][invoiceId,CI6(java.lang.String)][lastUpdatedStamp,2013-10-09
>  13:13:57.498(java.sql.Timestamp)][lastUpdatedTxStamp,2013-10-09 
> 13:13:49.522(java.sql.Timestamp)][partyId,DemoCustCompany(java.lang.String)][roleTypeId,PLACING_CUSTOMER(java.lang.String)]
>  (SQL Exception while executing the following:INSERT INTO public.INVOICE_ROLE 
> (INVOICE_ID, PARTY_ID, ROLE_TYPE_ID, DATETIME_PERFORMED, PERCENTAGE, 
> LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, CREATED_TX_STAMP) 
> VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: duplicate key value violates 
> unique constraint "pk_invoice_role"<br/>  Detail: Key (invoice_id, party_id, 
> role_type_id)=(CI6, DemoCustCompany, PLACING_CUSTOMER) already exists.)). 
> Rolling back transaction.org.ofbiz.entity.GenericEntityException: Error while 
> inserting: [GenericEntity:InvoiceRole][createdStamp,2013-10-09 
> 13:13:57.498(java.sql.Timestamp)][createdTxStamp,2013-10-09 
> 13:13:49.522(java.sql.Timestamp)][datetimePerformed,2013-10-09 
> 13:13:57.498(java.sql.Timestamp)][invoiceId,CI6(java.lang.String)][lastUpdatedStamp,2013-10-09
>  13:13:57.498(java.sql.Timestamp)][lastUpdatedTxStamp,2013-10-09 
> 13:13:49.522(java.sql.Timestamp)][partyId,DemoCustCompany(java.lang.String)][roleTypeId,PLACING_CUSTOMER(java.lang.String)]
>  (SQL Exception while executing the following:INSERT INTO public.INVOICE_ROLE 
> (INVOICE_ID, PARTY_ID, ROLE_TYPE_ID, DATETIME_PERFORMED, PERCENTAGE, 
> LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, CREATED_TX_STAMP) 
> VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: duplicate key value violates 
> unique constraint "pk_invoice_role"<br/>  Detail: Key (invoice_id, party_id, 
> role_type_id)=(CI6, DemoCustCompany, PLACING_CUSTOMER) already exists.)) 
> (Error while inserting: [GenericEntity:InvoiceRole][createdStamp,2013-10-09 
> 13:13:57.498(java.sql.Timestamp)][createdTxStamp,2013-10-09 
> 13:13:49.522(java.sql.Timestamp)][datetimePerformed,2013-10-09 
> 13:13:57.498(java.sql.Timestamp)][invoiceId,CI6(java.lang.String)][lastUpdatedStamp,2013-10-09
>  13:13:57.498(java.sql.Timestamp)][lastUpdatedTxStamp,2013-10-09 
> 13:13:49.522(java.sql.Timestamp)][partyId,DemoCustCompany(java.lang.String)][roleTypeId,PLACING_CUSTOMER(java.lang.String)]
>  (SQL Exception while executing the following:INSERT INTO public.INVOICE_ROLE 
> (INVOICE_ID, PARTY_ID, ROLE_TYPE_ID, DATETIME_PERFORMED, PERCENTAGE, 
> LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, CREATED_TX_STAMP) 
> VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: duplicate key value violates 
> unique constraint "pk_invoice_role"<br/>  Detail: Key (invoice_id, party_id, 
> role_type_id)=(CI6, DemoCustCompany, PLACING_CUSTOMER) already exists.))))
> The createInvoiceForOrder service is called for each orderId in 
> createInvoicesFromShipments of InvoiceServices.java but the 
> createInvoiceForOrder calls createInvoiceRole which attempts to insert the 
> OrderRoles associated with the orderId which causes primary key violations.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to