Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0046770Openbravo ERP03. Procurement managementpublic2021-05-21 04:122021-06-15 11:41
lbressan 
markmm82 
highmajoralways
closedfixed 
5
 
PR21Q3 
Core
No
0046770: Bad tax calculated in Purchase Order lines with multi-country business partner
When using a multi-country Business Partner in a purchase order, the taxes of the lines are not selected correctly, regardless of the Tax Location.

The problem is caused by the BillTo_ID field, which is not visible in the purchase order, but which takes the value of the first of the addresses.
org.openbravo.erpCommon.ad_callouts.SE_Order_BPartner
...
    // Bill to

    if (strLocation != null && !strLocation.isEmpty()) {
      info.addResult("inpbilltoId", strLocation);
    }
...
This field is not present in the purchase order, so it cannot be changed even if the Partner Address field is changed to another country.

This field is then used for the calculation in the C_GetTax Database function.

org.openbravo.erpCommon.ad_callouts.SL_Order_Product
...
        try {
          String strCTaxID = Tax.get(this, strMProductID, data[0].dateordered, strADOrgID,
              strMWarehouseID,
              (StringUtils.isEmpty(data[0].billtoId) ? strCBPartnerLocationID : data[0].billtoId),
              strCBPartnerLocationID, data[0].cProjectId, StringUtils.equals(strIsSOTrx, "Y"),
              StringUtils.equals(data[0].iscashvat, "Y"));
          info.addResult("inpcTaxId", strCTaxID);
        }
...

org.openbravo.erpCommon.ad_callouts
SL_Order_Tax_data.xsql
...
  <SqlMethod name="select" type="preparedStatement" return="multiple">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
      SELECT C_Order.BillTo_ID, C_Order.DateOrdered, C_Order.C_Project_ID, C_Order.IsCashVat
      FROM C_Order
      WHERE C_Order_ID = ?
      ]]>
    </Sql>
...

org.openbravo.erpCommon.businessUtility
Tax_data.xsql
...
   <SqlMethod name="taxGet" type="preparedStatement" return="String" default="">
      <SqlMethodComment></SqlMethodComment>
      <Sql><![CDATA[
        SELECT C_GetTax(?, TO_DATE(?), ?, ?, ?, ?, ?, ?, ?, ?) AS TAX FROM DUAL
      ]]></Sql>
...
1. Enter the Back Office to any Client-Organization (Example: The White Valley Group-Category Tree Store)
2. Choose a Business Partner and add an address from a country different from the other countries of the other Locations that it has. (Example: Mountains & Snow S.L has addresses from Spain, add an address from France, with all empty fields except the country)
3. Create a new Tax Category.
4. Create new Tax Rates for this Tax Category between the country of all the Business Partner Locations and the country of the Organization (In this example: Category Tree Store is from Spain, add Tax Rates Spain-Spain, Spain -France and France-Spain).
5. Assign that Tax Category to a Product (Example: Alpine ski boot).
6. Create a Purchase Order with the chosen Organization.
7. Add the chosen Business Partner. (It should load by default the new Location created)
8. Change Partner Location.
9. Add a line.
10. Select the chosen product.
11. Check which Tax is charged on the line.
12. Delete the line.
13. Change Partner Location.
14. Repeat the test on the line.
1. Use org.openbravo.erpCommon.ad_callouts.SE_Order_BPartnerLocation to update BillTo_ID to the appropriate value.
2. Correct the callout to select the correct address from the C_Order for the Purchase Orders.
No tags attached.
Issue History
2021-05-21 04:12lbressanNew Issue
2021-05-21 04:12lbressanAssigned To => Triage Finance
2021-05-21 04:12lbressanModules => Core
2021-05-21 04:12lbressanResolution time => 1623276000
2021-05-21 04:12lbressanTriggers an Emergency Pack => No
2021-05-21 11:30vmromanosAssigned ToTriage Finance => markmm82
2021-05-21 21:05lbressanDescription Updatedbug_revision_view_page.php?rev_id=22578#r22578
2021-06-09 18:13markmm82Statusnew => scheduled
2021-06-09 22:30markmm82Note Added: 0129289
2021-06-10 01:15hgbotNote Added: 0129293
2021-06-10 14:32hgbotNote Added: 0129349
2021-06-10 15:43markmm82Note Edited: 0129289bug_revision_view_page.php?bugnote_id=0129289#r22710
2021-06-10 18:02hgbotNote Added: 0129364
2021-06-11 00:04hgbotNote Added: 0129371
2021-06-11 00:14hgbotNote Added: 0129372
2021-06-11 14:25hgbotNote Added: 0129413
2021-06-11 23:01hgbotNote Added: 0129422
2021-06-15 11:41hgbotResolutionopen => fixed
2021-06-15 11:41hgbotStatusscheduled => closed
2021-06-15 11:41hgbotFixed in Version => PR21Q3
2021-06-15 11:41hgbotNote Added: 0129510
2021-06-15 11:41hgbotNote Added: 0129511

Notes
(0129289)
markmm82   
2021-06-09 22:30   
(edited on: 2021-06-10 15:43)
Test Plan:
1. Login as The White Valley Group client and select Category Tree Store org as defaults.
2. Go to Business Partner window and select Mountains & Snow S.L.
  2.1 Notice he already has a spain address.
  2.2 Create a new address for France with all empty fields except the country.
3. Create a new Tax Category.
  Organization = Category Tree Store
  Name = Issue46770TaxCategory
4. Create three new Tax Rates for this Tax Category:
  4.1 To be applied from Spain to Spain:
     Organization = Category Tree Store
     Name = SpainSpain
     Tax Category = Issue46770TaxCategory
     Rate = 10
     Country = Destination Country = Spain
  4.2 To be applied from Spain to France:
     Organization = Category Tree Store
     Name = SpainFrance
     Rate = 20
     Tax Category = Issue46770TaxCategory
     Country = Spain
     Destination Country = France
  4.1 To be applied from France to Spain:
     Organization = Category Tree Store
     Name = FranceSpain
     Rate = 30
     Tax Category = Issue46770TaxCategory
     Country = France
     Destination Country = Spain
5. Assign that "Issue46770TaxCategory" Tax Category to "Alpine ski boot" product.
6. Create a Purchase Order
   Organization = Category Tree Store
   Business Partner = Mountains & Snow S.L
   Notice it loads by default the new Location created for France

   Go to "More Information" section and be sure that same location is selected for the Invoice Address.
7. Add a line.
8. Select the "Alpine ski boot" product.
  Notice that "FranceSpain" tax is selected by default in the Tax field.
  This is correct as BP invoice address belongs to France.
9. Delete the line.
10. Go to header an change invoice address by selecting Spain location (.Zaragoza, Plaza Mayor 2).
11. Add a line.
12. Select the "Alpine ski boot" product.
  Notice that "SpainSpain" tax is selected by default in the Tax field.
  This is correct as BP invoice address belongs to Spain.
13. Add quantity and complete the order.
  Notice the process ends successfully.

Repeat the test for Sales Orders.

(0129293)
hgbot   
2021-06-10 01:15   
Merge Request created: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/387 [^]
(0129349)
hgbot   
2021-06-10 14:32   
Merge request closed: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/387 [^]
(0129364)
hgbot   
2021-06-10 18:02   
Merge Request created: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/389 [^]
(0129371)
hgbot   
2021-06-11 00:04   
Merge request closed: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/389 [^]
(0129372)
hgbot   
2021-06-11 00:14   
Merge Request created: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/390 [^]
(0129413)
hgbot   
2021-06-11 14:25   
Merge request closed: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/390 [^]
(0129422)
hgbot   
2021-06-11 23:01   
Merge Request created: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/394 [^]
(0129510)
hgbot   
2021-06-15 11:41   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/openbravo [^]
Changeset: 1a40d11a29609c0f0c0bc0f7a0b0877fcb067ba5
Author: Mark Orlando Molina <markmm82@gmail.com>
Date: 2021-06-15T09:41:00+00:00
URL: https://gitlab.com/openbravo/product/openbravo/-/commit/1a40d11a29609c0f0c0bc0f7a0b0877fcb067ba5 [^]

Fixes BUG-46770: Displayed "Invoice from" field in Purchase Order window

---
M modules/org.openbravo.v3/src-db/database/configScript.xml
M src-db/database/sourcedata/AD_FIELD.xml
---
(0129511)
hgbot   
2021-06-15 11:41   
Merge request merged: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/394 [^]