Import Price - New Excel file structure
This commit is contained in:
@@ -5,6 +5,7 @@ from decimal import Decimal
|
||||
from datetime import date
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock, patch
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from trytond.model.exceptions import ValidationError
|
||||
from trytond.pool import Pool
|
||||
@@ -308,6 +309,47 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertIn('Errors:', message)
|
||||
self.assertIn('Row 2 - LME Copper / 2026-03-27', message)
|
||||
|
||||
def test_import_prices_reads_forward_price_matrix(self):
|
||||
'import prices expands forward month columns into price rows'
|
||||
ns = {'s': 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'}
|
||||
sheet = ElementTree.fromstring('''
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<sheetData>
|
||||
<row r="1">
|
||||
<c r="A1" t="inlineStr"><is><t>price_index</t></is></c>
|
||||
<c r="B1" t="inlineStr"><is><t>price_date</t></is></c>
|
||||
<c r="C1" t="inlineStr"><is><t>2026-06</t></is></c>
|
||||
<c r="D1" t="inlineStr"><is><t>2026-07</t></is></c>
|
||||
<c r="E1" t="inlineStr"><is><t>2026-08</t></is></c>
|
||||
</row>
|
||||
<row r="2">
|
||||
<c r="A2" t="inlineStr"><is><t>CFR Chile</t></is></c>
|
||||
<c r="B2" t="inlineStr"><is><t>2026-05-01</t></is></c>
|
||||
<c r="C2"><v>400</v></c>
|
||||
<c r="D2"><v>410</v></c>
|
||||
<c r="E2"><v>420</v></c>
|
||||
</row>
|
||||
<row r="3">
|
||||
<c r="A3" t="inlineStr"><is><t>FOB Peru</t></is></c>
|
||||
<c r="B3" t="inlineStr"><is><t>2026-05-01</t></is></c>
|
||||
<c r="C3"><v>390</v></c>
|
||||
<c r="D3"><v>400</v></c>
|
||||
<c r="E3"><v>410</v></c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
||||
''')
|
||||
rows = sheet.findall('.//s:sheetData/s:row', ns)
|
||||
|
||||
result = ImportPrices._read_forward_price_rows(rows, [], ns)
|
||||
|
||||
self.assertEqual(len(result), 6)
|
||||
self.assertEqual(result[0]['price_index'], 'CFR Chile 2026-06')
|
||||
self.assertEqual(result[0]['price_date'], '2026-05-01')
|
||||
self.assertEqual(result[0]['price_value'], '400')
|
||||
self.assertEqual(result[-1]['price_index'], 'FOB Peru 2026-08')
|
||||
self.assertEqual(result[-1]['_row_number'], 3)
|
||||
|
||||
def test_price_value_unique_rejects_duplicate_create(self):
|
||||
'price value uniqueness rejects duplicate model creation'
|
||||
price_value = SimpleNamespace(
|
||||
|
||||
Reference in New Issue
Block a user