Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0036969Openbravo ERP03. Procurement managementpublic2017-09-28 12:332018-01-03 12:38
ngarcia 
markmm82 
urgentmajoralways
closedfixed 
5
 
3.0PR18Q1 
aferraz
Core
No
0036969: Purchase order lines created from Requisitions are created with 0 price if price list includes taxes and a discount is defined
Purchase order lines created from Requisitions are created with 0 price if price list includes taxes and a discount is defined
As group admin role:
   Create a new record in Discounts and Promotions window:
      Discount/Promotion Type: Price Adjustment
      Included Product: Only those defined
      Discount %: 50
      Add Cerveza Ale 0,5L product in Products tab

   Change Tarifa Bebidas Alegres to Price includes tax = Y
   Create a new Requisition
      Business Partner. Bebidas Alegres, S.L.
   Add the previously created product and complete it
   Go to Manage Requisitions window and Create Purchase Order
   Go to Purchase Order and check the Gross Unit Price, Line Net Amount and Line Gross Amount are 0
No tags attached.
related to defect 0038085 closed markmm82 Prices in Invoice lines of discounts copied by Copy Lines process are updated to 0 when completing if a price adjustment exists 
Issue History
2017-09-28 12:33ngarciaNew Issue
2017-09-28 12:33ngarciaAssigned To => Triage Finance
2017-09-28 12:33ngarciaModules => Core
2017-09-28 12:33ngarciaResolution time => 1508364000
2017-09-28 12:33ngarciaTriggers an Emergency Pack => No
2017-09-28 12:33ngarciaIssue Monitored: networkb
2017-09-28 16:39aferrazAssigned ToTriage Finance => markmm82
2017-09-28 23:50markmm82Statusnew => scheduled
2017-10-03 13:43hgbotCheckin
2017-10-03 13:43hgbotNote Added: 0099716
2017-10-03 13:43hgbotStatusscheduled => resolved
2017-10-03 13:43hgbotResolutionopen => fixed
2017-10-03 13:43hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/5f2720a854ccbb7a34411ddfb013207705781de0 [^]
2017-10-03 13:43aferrazReview Assigned To => aferraz
2017-10-03 13:43aferrazNote Added: 0099717
2017-10-03 13:43aferrazStatusresolved => closed
2017-10-03 13:43aferrazFixed in Version => 3.0PR18Q1
2017-10-03 13:45aferrazNote Added: 0099718
2018-01-03 12:38hudsonbotCheckin
2018-01-03 12:38hudsonbotNote Added: 0101308
2018-03-08 15:55ngarciaRelationship addedrelated to 0038085

Notes
(0099716)
hgbot   
2017-10-03 13:43   
Repository: erp/devel/pi
Changeset: 5f2720a854ccbb7a34411ddfb013207705781de0
Author: Mark <markmm82 <at> gmail.com>
Date: Mon Oct 02 17:19:19 2017 -0400
URL: http://code.openbravo.com/erp/devel/pi/rev/5f2720a854ccbb7a34411ddfb013207705781de0 [^]

Fixes issue 36969: Purchase order created from Requisitions created with 0 price

Purchase order lines created from Requisitions are created with 0 price if price
list includes taxes and a discount is defined.

When M_REQUISITION_CREATEPO process is executed it creates the order and its lines.
Then it call the C_ORDER_POST1, to process the created order and it calls the
M_PROMOTION_CALCULATE to recalculate prices and quantities if discounts, and in
this case it uses the grosspricestd of lines to recalculates the gross_unit_price
and line_gross_amount if price list includes taxes:

if (v_taxIncluded = 'Y') then
update c_orderline set
    gross_unit_price = grosspricestd,
    line_gross_amount = round(grosspricestd * qtyordered, v_stdPrecision)
where c_orderline_id = Cur_Order.id;

The process was failling because order lines were created without a GROSSPRICESTD
column defined, and it was taking 0 instead of the right price. Due that, when the
values of the lines were recalculated to apply discounts it reset all values to ZERO
and order ends with incorrect totals.

To avoid that, the GROSSPRICESTD is defined when the lines are created.

---
M src-db/database/model/functions/M_REQUISITION_CREATEPO.xml
---
(0099717)
aferraz   
2017-10-03 13:43   
Code review + Testing OK
(0099718)
aferraz   
2017-10-03 13:45   
Test Plan 1: Create PO from requisition, Price List including taxes and applying a discount
As group admin role:
   Create a new record in Discounts and Promotions window:
      Discount/Promotion Type: Price Adjustment
      Included Product: Only those defined
      Discount %: 50
      Add Cerveza Ale 0,5L product in Products tab

   Change Tarifa Bebidas Alegres to Price includes tax = Y
   Verify Cerveza Ale 0,5L has a Unit Price = List Price = 1.36

   Create a new Requisition
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Add a line to it:
      Need by date: Next week
      Product: Cerveza Ale 0,5L
      Quantity: 10 Units
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Complete the requisition.
   Go to Manage Requisitions window and Create Purchase Order from created requisition. take note of the document no. of generated purchase order.
   Go to Purchase Order header and check the following values:
      Total Gross Amount: 6.80
      Total Net Amount: 5.62
   Go to Lines and see the created line has the following values:
      Product: Cerveza Ale 0,5L
      Ordered Quantity: 10
      Net Unit Price: 0.56
      Gross Unit Price: 0.68
      Line Net Amount: 5.62
      Line Gross Amount: 6.80
      Tax: Adquisiciones IVA 21%

      As Price Includes Taxes, Gross Unit Price (GUP)
      GUP = Price List Unit Price - discount
      GUP = 1.36 - (1.36 * 0.5)
      GUP = 0.68

      Net Unit Price Computation (NUP)
      NUP + NUP * TAX = GUP
      NUP + NUP * 0.21 = 0.68
      NUP (1 + 0.21) = 0.68
      NUP = 0.68 / 1.21
      NUP = 0.56198
      NUP = 0.56 (Rounded)

      Line Net Amount = Net Unit Price * Qty = 0.56198 * 10 = 5.6198 = 5.62 rounded
      Line Gross Amount = Gross Unit Price * Qty = 0.68 * 10 = 6.80

Test Plan 2: Create PO from requisition, Price List NOT including taxes and applying a discount
As group admin role:
   Create a new record in Discounts and Promotions window:
      Discount/Promotion Type: Price Adjustment
      Included Product: Only those defined
      Discount %: 50
      Add Cerveza Ale 0,5L product in Products tab

   Change Tarifa Bebidas Alegres to Price includes tax = N
   Verify Cerveza Ale 0,5L has a Unit Price = List Price = 1.36

   Create a new Requisition
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Add a line to it:
      Need by date: Next week
      Product: Cerveza Ale 0,5L
      Quantity: 10 Units
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Complete the requisition.
   Go to Manage Requisitions window and Create Purchase Order from created requisition. take note of the document no. of generated purchase order.
   Go to Purchase Order header and check the following values:
      Total Gross Amount: 8.23
      Total Net Amount: 6.80
   Go to Lines and see the created line has the following values:
      Product: Cerveza Ale 0,5L
      Ordered Quantity: 10
      Net Unit Price: 0.68
      Line Net Amount: 6.80
      Net List Price: 1.36
      Tax: Adquisiciones IVA 21%

      As Price NOT Includes Taxes, Net Unit Price Computation (NUP)
      NUP = Price List Unit Price - discount
      NUP = 1.36 - (1.36 * 0.5)
      NUP = 0.68

      Line Net Amount = Net Unit Price * Qty = 0.68 * 10 = 6.80
      
      Header Total Gross Amount = Line Net Amount + Tax = 6.80 + (6.80 * 0.21) = 8.228 = 8.23 rounded.


Test Plan 3: Create PO from requisition, Price List NOT including taxes
As group admin role:
   Remove any discount if exists for Cerveza Ale.

   Change Tarifa Bebidas Alegres to Price includes tax = N
   Verify Cerveza Ale 0,5L has a Unit Price = List Price = 1.36

   Create a new Requisition
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Add a line to it:
      Need by date: Next week
      Product: Cerveza Ale 0,5L
      Quantity: 10 Units
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Complete the requisition.
   Go to Manage Requisitions window and Create Purchase Order from created requisition. take note of the document no. of generated purchase order.
   Go to Purchase Order header and check the following values:
      Total Gross Amount: 16.46
      Total Net Amount: 13.60
   Go to Lines and see the created line has the following values:
      Product: Cerveza Ale 0,5L
      Ordered Quantity: 10
      Net Unit Price: 1.36
      Line Net Amount: 13.60
      Net List Price: 1.36
      Tax: Adquisiciones IVA 21%
 
      Header Total Gross Amount = Line Net Amount + Tax = 13.60 + (13.60 * 0.21) = 16.456 = 16.46 rounded.


Test Plan 4: Create PO from requisition, Price List including taxes
As group admin role:
   Remove any discount if exists for Cerveza Ale.

   Change Tarifa Bebidas Alegres to Price includes tax = Y
   Verify Cerveza Ale 0,5L has a Unit Price = List Price = 1.36

   Create a new Requisition
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Add a line to it:
      Need by date: Next week
      Product: Cerveza Ale 0,5L
      Quantity: 10 Units
      Business Partner: Bebidas Alegres, S.L.
      Price List: Tarifa Bebidas Alegres
   Complete the requisition.
   Go to Manage Requisitions window and Create Purchase Order from created requisition. take note of the document no. of generated purchase order.
   Go to Purchase Order header and check the following values:
      Total Gross Amount: 13.60
      Total Net Amount: 11.24
   Go to Lines and see the created line has the following values:
      Product: Cerveza Ale 0,5L
      Ordered Quantity: 10
      Net Unit Price: 1.12
      Gross Unit Price: 1.36
      Line Net Amount: 11.24
      Line Gross Amount: 13.60
      Tax: Adquisiciones IVA 21%

      As Price Includes Taxes, Gross Unit Price (GUP)
      GUP = 1.36

      Net Unit Price Computation (NUP)
      NUP + NUP * TAX = GUP
      NUP + NUP * 0.21 = 1.36
      NUP (1 + 0.21) = 1.36
      NUP = 1.36 / 1.21
      NUP = 1.1239
      NUP = 1.12 (Rounded)

      Line Net Amount = Net Unit Price * Qty = 1.1239 * 10 = 11.239 = 11.24 rounded
      Line Gross Amount = Gross Unit Price * Qty = 1.36 * 10 = 13.60


For all test cases 1 to 4 you can compare doing manual Purchase orders and you will get the same results.
(0101308)
hudsonbot   
2018-01-03 12:38   
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/c81e0d3cbab5 [^]
Maturity status: Test