This commit is contained in:
2026-04-02 12:32:06 +02:00
parent 51ced23ab8
commit 613b679908
4 changed files with 97 additions and 12 deletions

View File

@@ -3930,15 +3930,15 @@
<text:p text:style-name="P25">Goods description</text:p>
</table:table-cell>
<table:table-cell table:style-name="Tableau5.A1" office:value-type="string">
<text:p text:style-name="P26">QUANTITY: <text:placeholder text:placeholder-type="text">&lt;format_number(invoice.report_lbs, invoice.party.lang) if invoice.report_lbs != &apos;&apos; else &apos;&apos;&gt;</text:placeholder><text:s/>LBS (<text:placeholder text:placeholder-type="text">&lt;format_number(invoice.report_net, invoice.party.lang) if invoice.report_net != &apos;&apos; else &apos;&apos;&gt;</text:placeholder> MTS)</text:p>
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text">&lt;for each=&quot;line in invoice.report_quantity_lines.splitlines()&quot;&gt;</text:placeholder></text:p>
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text">&lt;line&gt;</text:placeholder></text:p>
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
<text:p text:style-name="P26">QUANTITY: <text:placeholder text:placeholder-type="text">&lt;format_number(invoice.report_lbs, invoice.party.lang) if invoice.report_lbs != &apos;&apos; else &apos;&apos;&gt;</text:placeholder><text:s/>LBS (<text:placeholder text:placeholder-type="text">&lt;format_number(invoice.report_net, invoice.party.lang) if invoice.report_net != &apos;&apos; else &apos;&apos;&gt;</text:placeholder> <text:placeholder text:placeholder-type="text">&lt;invoice.report_weight_unit_upper&gt;</text:placeholder>)</text:p>
<text:p text:style-name="P26"/>
<text:p text:style-name="P21"><text:placeholder text:placeholder-type="text">&lt;invoice.report_description_upper or invoice.report_product_description&gt;</text:placeholder><text:s/>CROP <text:placeholder text:placeholder-type="text">&lt;invoice.report_crop_name&gt;</text:placeholder></text:p>
<text:p text:style-name="P21"><text:placeholder text:placeholder-type="text">&lt;invoice.report_attributes_name&gt;</text:placeholder></text:p>
<text:p text:style-name="P18"><text:placeholder text:placeholder-type="text">&lt;for each=&quot;line in invoice.report_rate_lines.splitlines()&quot;&gt;</text:placeholder></text:p>
<text:p text:style-name="P18">At <text:placeholder text:placeholder-type="text">&lt;line&gt;</text:placeholder></text:p>
<text:p text:style-name="P18"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text">&lt;for each=&quot;block in invoice.report_trade_blocks&quot;&gt;</text:placeholder></text:p>
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text">&lt;block[0]&gt;</text:placeholder></text:p>
<text:p text:style-name="P18">At <text:placeholder text:placeholder-type="text">&lt;block[1]&gt;</text:placeholder></text:p>
<text:p text:style-name="P18"/>
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
<text:p text:style-name="P18"/>
<text:p text:style-name="P18"/>
<text:p text:style-name="P32"><text:placeholder text:placeholder-type="text">&lt;invoice.report_incoterm&gt;</text:placeholder></text:p>
@@ -3957,10 +3957,10 @@
<text:p text:style-name="P15"><text:s text:c="19"/>BALES</text:p>
</table:table-cell>
<table:table-cell table:style-name="Tableau6.A1" office:value-type="string">
<text:p text:style-name="P41"><text:s text:c="13"/>Gross KGS</text:p>
<text:p text:style-name="P41"><text:s text:c="13"/>Gross <text:placeholder text:placeholder-type="text">&lt;invoice.report_weight_unit_upper&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Tableau6.A1" office:value-type="string">
<text:p text:style-name="P15"><text:s text:c="13"/>NET KGS</text:p>
<text:p text:style-name="P15"><text:s text:c="13"/>NET <text:placeholder text:placeholder-type="text">&lt;invoice.report_weight_unit_upper&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Tableau6.A1" office:value-type="string">
<text:p text:style-name="P41"><text:s text:c="10"/></text:p>

View File

@@ -191,6 +191,19 @@ class Invoice(metaclass=PoolMeta):
details.append(detail)
return '\n'.join(details)
@property
def report_trade_blocks(self):
sale = self._get_report_sale()
if sale and getattr(sale, 'report_trade_blocks', None):
return sale.report_trade_blocks
blocks = []
quantity_lines = self.report_quantity_lines.splitlines()
rate_lines = self.report_rate_lines.splitlines()
for index, quantity_line in enumerate(quantity_lines):
price_line = rate_lines[index] if index < len(rate_lines) else ''
blocks.append((quantity_line, price_line))
return blocks
@property
def report_rate_currency_upper(self):
line = self._get_report_invoice_line()
@@ -337,6 +350,17 @@ class Invoice(metaclass=PoolMeta):
return ''
return round(Decimal(net) * Decimal('2204.62'),2)
@property
def report_weight_unit_upper(self):
sale = self._get_report_sale()
if sale and getattr(sale, 'report_quantity_unit_upper', None):
return sale.report_quantity_unit_upper
line = self._get_report_trade_line() or self._get_report_invoice_line()
unit = getattr(line, 'unit', None) if line else None
if unit and unit.rec_name:
return unit.rec_name.upper()
return 'KGS'
@property
def report_bl_date(self):
shipment = self._get_report_shipment()

View File

@@ -440,12 +440,19 @@ class Sale(metaclass=PoolMeta):
if line and line.unit:
return line.unit.rec_name.upper()
return ''
def _get_report_line_quantity(self, line):
phys_lots = [l for l in line.lots if l.lot_type == 'physic']
if phys_lots:
return sum(Decimal(str(l.get_current_quantity() or 0))
for l in phys_lots)
return Decimal(str(line.quantity or 0))
@property
def report_qt(self):
lines = self._get_report_lines()
if lines:
total = sum(Decimal(str(line.quantity or 0)) for line in lines)
total = sum(self._get_report_line_quantity(line) for line in lines)
return quantity_to_words(total)
return ''
@@ -456,10 +463,11 @@ class Sale(metaclass=PoolMeta):
return ''
details = []
for line in lines:
current_quantity = self._get_report_line_quantity(line)
quantity = self._format_report_number(
line.quantity, keep_trailing_decimal=True)
current_quantity, keep_trailing_decimal=True)
unit = line.unit.rec_name.upper() if line.unit and line.unit.rec_name else ''
words = quantity_to_words(Decimal(str(line.quantity or 0)))
words = quantity_to_words(current_quantity)
period = line.del_period.description if getattr(line, 'del_period', None) else ''
detail = ' '.join(
part for part in [
@@ -523,6 +531,28 @@ class Sale(metaclass=PoolMeta):
if lines:
return '\n'.join(self._format_report_price_line(line) for line in lines)
return ''
@property
def report_trade_blocks(self):
lines = self._get_report_lines()
blocks = []
for line in lines:
current_quantity = self._get_report_line_quantity(line)
quantity = self._format_report_number(
current_quantity, keep_trailing_decimal=True)
unit = line.unit.rec_name.upper() if line.unit and line.unit.rec_name else ''
words = quantity_to_words(current_quantity)
period = line.del_period.description if getattr(line, 'del_period', None) else ''
quantity_line = ' '.join(
part for part in [
quantity,
unit,
f"({words})",
f"- {period}" if period else '',
] if part)
price_line = self._format_report_price_line(line)
blocks.append((quantity_line, price_line))
return blocks
@property
def report_delivery(self):

View File

@@ -279,5 +279,36 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(sale.report_net, Decimal('2000'))
self.assertEqual(sale.report_gross, Decimal('2000'))
def test_sale_report_trade_blocks_use_lot_current_quantity(self):
'sale trade blocks use current lot quantity for quantity display'
Sale = Pool().get('sale.sale')
lot = Mock()
lot.lot_type = 'physic'
lot.get_current_quantity.return_value = Decimal('950')
line = Mock()
line.type = 'line'
line.lots = [lot]
line.quantity = Decimal('1000')
line.unit = Mock(rec_name='MT')
line.del_period = Mock(description='MARCH 2026')
line.price_type = 'priced'
line.linked_currency = Mock(rec_name='USC')
line.linked_unit = Mock(rec_name='POUND')
line.linked_price = Decimal('8.3000')
line.unit_price = Decimal('0')
line.get_pricing_text = 'ON ICE Cotton #2 MARCH 2026'
sale = Sale()
sale.currency = Mock(rec_name='USD')
sale.lines = [line]
self.assertEqual(
sale.report_trade_blocks,
[(
'950.0 MT (NINE HUNDRED AND FIFTY METRIC TONS) - MARCH 2026',
'USC 8.3000 PER POUND (EIGHT USC AND THIRTY CENTS) ON ICE Cotton #2 MARCH 2026',
)])
del ModuleTestCase