Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0021884Openbravo ERP05. Production managementpublic2012-10-08 18:032012-10-18 18:39
VictorVillar 
ioritzCia 
immediatemajoralways
closedfixed 
5
pi 
3.0MP17 
Core
No
0021884: wrong calculation of ending date for m_costing register under some cirumstancies
Using the old generate average cost process, under some cirumstancies the new register in the m_costing has a wrong calculation date.
as group admin role,
Go to Product window,
   Create a new register:
       Org: España
       Name: test
       cost type: legacy average
       purchase: Yes
       Sale: yes
  go to price list tab:
      new register for Tarifa Bebidas Alegres
  go to Costing tab:
      create a new register org: España
      Cost type: Legacy Standard
      Starting date: 01-07-2011
      Ending date: 02-07-2011
Go to Goods receipt window:
      create a new register for Org: España
       business partner: Fruta de la vida
       movement date: 03-07-2011
     Lines tab:
       product: test
       movement qty: 40
       storage bin: whatever
Complete it.

Go to Purchase order window:
     Create a new register:
       org: España
       BP: Bebidas Alegres
       price list: Bebidas Alegres
 lines tab:
      Product: test
      ordered qty: 3
Book it

Go to Goods receipt window:
      create a new register for Org: España
       business partner: Bebidas Alegres
       movement date: today
   Create lines from order created before
Complete it

Launch the Generate average cost process, incremental= No
Go to Product || Costing tab: realise that the date to of the second register is lower than the date from.

the problem is that there is an update of dates before check if it is possible to calculate the cost:

  v_Cost:=Cur_ProdCost.COST;
  v_Date:=Cur_ProdCost.DATETO;
          UPDATE M_COSTING
          SET DATETO = Cur_InOutLine.MOVEMENTDATE,
          Updated=now(),
            UpdatedBy=v_User
          WHERE M_COSTING_ID = Cur_ProdCost.M_COSTING_ID;
       
The solution should be:
1.- First check if it is possible to calculate the cost before doing the any date update.

Move the following update:

UPDATE M_COSTING
          SET DATETO = Cur_InOutLine.MOVEMENTDATE,
          Updated=TO_DATE(NOW()),
            UpdatedBy=v_User
          WHERE M_COSTING_ID = Cur_ProdCost.M_COSTING_ID;

just before the insert:

INSERT
          INTO M_COSTING
        (
          M_COSTING_ID, CREATED, CREATEDBY, UPDATED,
          UPDATEDBY, AD_CLIENT_ID, AD_ORG_ID, M_PRODUCT_ID,
          DATETO, DATEFROM, ISMANUAL, M_INOUTLINE_ID,
          C_INVOICELINE_ID, QTY, PRICE, CUMQTY,
          COST, COSTTYPE, ISPERMANENT
        )
        VALUES
        (
          Ad_Sequence_Nextno('M_Costing'), TO_DATE(NOW()), v_User, TO_DATE(NOW()),
          v_User, Cur_InOutLine.AD_CLIENT_ID, Cur_InOutLine.AD_ORG_ID, Cur_InOutLine.M_PRODUCT_ID,
          COALESCE(v_Date, TO_DATE('31-12-9999', 'DD-MM-YYYY')), Cur_InOutLine.MOVEMENTDATE, 'N', Cur_InOutLine.M_INOUTLINE_ID,
          NULL, Cur_InOutLine.MOVEMENTQTY, v_PriceNew, COALESCE(v_Qty, 0) + Cur_InOutLine.MOVEMENTQTY + v_CumQty, v_CostNew,
          'AV', 'N'
        );

Also it should be necessary assign the Cur_ProdCost.M_COSTING_ID into a variable in order to use it later in the update before the insert.
No tags attached.
Issue History
2012-10-08 18:03VictorVillarNew Issue
2012-10-08 18:03VictorVillarAssigned To => dmiguelez
2012-10-08 18:03VictorVillarModules => Core
2012-10-08 18:04VictorVillarAssigned Todmiguelez => jonalegriaesarte
2012-10-08 18:04VictorVillarIssue Monitored: networkb
2012-10-10 10:54VictorVillarProposed Solution updated
2012-10-10 11:17jonalegriaesarteAssigned Tojonalegriaesarte => ioritzCia
2012-10-15 09:45ioritzCiaStatusnew => scheduled
2012-10-15 09:45ioritzCiafix_in_branch => pi
2012-10-16 09:13hgbotCheckin
2012-10-16 09:13hgbotNote Added: 0053361
2012-10-16 09:13hgbotStatusscheduled => resolved
2012-10-16 09:13hgbotResolutionopen => fixed
2012-10-16 09:13hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/805f83eefd4313796312f807f63a4197440754a4 [^]
2012-10-16 18:54hudsonbotCheckin
2012-10-16 18:54hudsonbotNote Added: 0053400
2012-10-18 18:39VictorVillarNote Added: 0053477
2012-10-18 18:39VictorVillarStatusresolved => closed

Notes
(0053361)
hgbot   
2012-10-16 09:13   
Repository: erp/devel/pi
Changeset: 805f83eefd4313796312f807f63a4197440754a4
Author: Ioritz Cia <ioritz.cia <at> openbravo.com>
Date: Wed Oct 10 18:55:28 2012 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/805f83eefd4313796312f807f63a4197440754a4 [^]

Fixes issue 21884: wrong calculation of ending date
for m_costing register under some cirumstancies.

---
M src-db/database/model/functions/M_GENERATE_AVERAGE_COSTS.xml
---
(0053400)
hudsonbot   
2012-10-16 18:54   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/0381663eaf40 [^]

Maturity status: Test
(0053477)
VictorVillar   
2012-10-18 18:39   
Verified