unit correction

This commit is contained in:
2026-04-09 21:55:40 +02:00
parent 8a90216357
commit 229b6037fb
4 changed files with 40 additions and 13 deletions

View File

@@ -3930,7 +3930,7 @@
<text:p text:style-name="P25">Goods description</text:p> <text:p text:style-name="P25">Goods description</text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau5.A1" office:value-type="string"> <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> <text:placeholder text:placeholder-type="text">&lt;invoice.report_weight_unit_upper&gt;</text:placeholder>)</text:p> <text:p text:style-name="P26">QUANTITY: <text:placeholder text:placeholder-type="text">&lt;invoice.report_lbs_display&gt;</text:placeholder><text:s/>LBS (<text:placeholder text:placeholder-type="text">&lt;invoice.report_net_display&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="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:placeholder text:placeholder-type="text">&lt;&apos; CROP &apos; + invoice.report_crop_name if invoice.report_crop_name else &apos;&apos;&gt;</text:placeholder></text:p> <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:placeholder text:placeholder-type="text">&lt;&apos; CROP &apos; + invoice.report_crop_name if invoice.report_crop_name else &apos;&apos;&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="P21"><text:placeholder text:placeholder-type="text">&lt;invoice.report_attributes_name&gt;</text:placeholder></text:p>
@@ -3974,10 +3974,10 @@
<text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;invoice.report_nb_bale&gt;</text:placeholder><text:s/></text:p> <text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;invoice.report_nb_bale&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau6.A2" office:value-type="string"> <table:table-cell table:style-name="Tableau6.A2" office:value-type="string">
<text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;format_number(invoice.report_gross, invoice.party.lang) if invoice.report_gross != &apos;&apos; else &apos;&apos;&gt;</text:placeholder><text:s/></text:p> <text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;invoice.report_gross_display&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau6.A2" office:value-type="string"> <table:table-cell table:style-name="Tableau6.A2" office:value-type="string">
<text:p text:style-name="P30"><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:s/></text:p> <text:p text:style-name="P30"><text:placeholder text:placeholder-type="text">&lt;invoice.report_net_display&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau6.A2" office:value-type="string"> <table:table-cell table:style-name="Tableau6.A2" office:value-type="string">
<text:p text:style-name="P16"/> <text:p text:style-name="P16"/>
@@ -4001,7 +4001,7 @@
<text:p text:style-name="P16">Equivalent to LBS</text:p> <text:p text:style-name="P16">Equivalent to LBS</text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau7.A1" office:value-type="string"> <table:table-cell table:style-name="Tableau7.A1" office:value-type="string">
<text:p text:style-name="P16"><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/></text:p> <text:p text:style-name="P16"><text:placeholder text:placeholder-type="text">&lt;invoice.report_lbs_display&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau7.A1" office:value-type="string"> <table:table-cell table:style-name="Tableau7.A1" office:value-type="string">
<text:p text:style-name="P20"/> <text:p text:style-name="P20"/>

View File

@@ -3916,7 +3916,7 @@
<text:p text:style-name="P26">Goods description</text:p> <text:p text:style-name="P26">Goods description</text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau5.A1" office:value-type="string"> <table:table-cell table:style-name="Tableau5.A1" office:value-type="string">
<text:p text:style-name="P27">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="P27">QUANTITY: <text:placeholder text:placeholder-type="text">&lt;invoice.report_lbs_display&gt;</text:placeholder><text:s/>LBS (<text:placeholder text:placeholder-type="text">&lt;invoice.report_net_display&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="P27"/> <text:p text:style-name="P27"/>
<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:placeholder text:placeholder-type="text">&lt;&apos; CROP &apos; + invoice.report_crop_name if invoice.report_crop_name else &apos;&apos;&gt;</text:placeholder></text:p> <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:placeholder text:placeholder-type="text">&lt;&apos; CROP &apos; + invoice.report_crop_name if invoice.report_crop_name else &apos;&apos;&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="P21"><text:placeholder text:placeholder-type="text">&lt;invoice.report_attributes_name&gt;</text:placeholder></text:p>
@@ -3959,10 +3959,10 @@
<text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;invoice.report_cndn_nb_bale&gt;</text:placeholder><text:s/></text:p> <text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;invoice.report_cndn_nb_bale&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau6.A2" office:value-type="string"> <table:table-cell table:style-name="Tableau6.A2" office:value-type="string">
<text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;format_number(invoice.report_gross, invoice.party.lang) if invoice.report_gross != &apos;&apos; else &apos;&apos;&gt;</text:placeholder><text:s/></text:p> <text:p text:style-name="P15"><text:placeholder text:placeholder-type="text">&lt;invoice.report_gross_display&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau6.A2" office:value-type="string"> <table:table-cell table:style-name="Tableau6.A2" office:value-type="string">
<text:p text:style-name="P32"><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:s/></text:p> <text:p text:style-name="P32"><text:placeholder text:placeholder-type="text">&lt;invoice.report_net_display&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau6.A2" office:value-type="string"> <table:table-cell table:style-name="Tableau6.A2" office:value-type="string">
<text:p text:style-name="P16"/> <text:p text:style-name="P16"/>
@@ -3986,7 +3986,7 @@
<text:p text:style-name="P16">Equivalent to LBS</text:p> <text:p text:style-name="P16">Equivalent to LBS</text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau7.A1" office:value-type="string"> <table:table-cell table:style-name="Tableau7.A1" office:value-type="string">
<text:p text:style-name="P16"><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/></text:p> <text:p text:style-name="P16"><text:placeholder text:placeholder-type="text">&lt;invoice.report_lbs_display&gt;</text:placeholder><text:s/></text:p>
</table:table-cell> </table:table-cell>
<table:table-cell table:style-name="Tableau7.A1" office:value-type="string"> <table:table-cell table:style-name="Tableau7.A1" office:value-type="string">
<text:p text:style-name="P20"/> <text:p text:style-name="P20"/>

View File

@@ -26,6 +26,11 @@ class Invoice(metaclass=PoolMeta):
text += '.0' text += '.0'
return text or '0' return text or '0'
@classmethod
def _format_report_quantity_display(cls, value):
return cls._format_report_number(
value, digits='0.01', strip_trailing_zeros=False)
def _get_report_invoice_line(self): def _get_report_invoice_line(self):
for line in self.lines or []: for line in self.lines or []:
if getattr(line, 'type', None) == 'line': if getattr(line, 'type', None) == 'line':
@@ -658,15 +663,14 @@ class Invoice(metaclass=PoolMeta):
quantity, _ = self._get_report_invoice_line_weights(line) quantity, _ = self._get_report_invoice_line_weights(line)
if quantity == '': if quantity == '':
continue continue
quantity_text = self._format_report_number( quantity_text = self._format_report_quantity_display(quantity)
quantity, keep_trailing_decimal=True)
unit = self._get_report_invoice_line_unit(line) unit = self._get_report_invoice_line_unit(line)
unit_name = unit.rec_name.upper() if unit and unit.rec_name else '' unit_name = unit.rec_name.upper() if unit and unit.rec_name else ''
lbs = self._convert_report_quantity_to_lbs(quantity, unit) lbs = self._convert_report_quantity_to_lbs(quantity, unit)
parts = [quantity_text, unit_name] parts = [quantity_text, unit_name]
if lbs != '': if lbs != '':
parts.append( parts.append(
f"({self._format_report_number(lbs, digits='0.01')} LBS)") f"({self._format_report_quantity_display(lbs)} LBS)")
detail = ' '.join(part for part in parts if part) detail = ' '.join(part for part in parts if part)
if detail: if detail:
details.append(detail) details.append(detail)
@@ -856,6 +860,27 @@ class Invoice(metaclass=PoolMeta):
return 'Unchanged' return 'Unchanged'
return nb_bale return nb_bale
@property
def report_net_display(self):
net = self.report_net
if net == '':
return ''
return self._format_report_quantity_display(net)
@property
def report_gross_display(self):
gross = self.report_gross
if gross == '':
return ''
return self._format_report_quantity_display(gross)
@property
def report_lbs_display(self):
lbs = self.report_lbs
if lbs == '':
return ''
return self._format_report_quantity_display(lbs)
@property @property
def report_gross(self): def report_gross(self):
if self.lines: if self.lines:

View File

@@ -1130,7 +1130,7 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(invoice.report_weight_unit_upper, 'LBS') self.assertEqual(invoice.report_weight_unit_upper, 'LBS')
self.assertEqual( self.assertEqual(
invoice.report_quantity_lines, invoice.report_quantity_lines,
'950.0 LBS (950.00 LBS)') '950.00 LBS (950.00 LBS)')
def test_invoice_report_lbs_converts_kilogram_to_lbs(self): def test_invoice_report_lbs_converts_kilogram_to_lbs(self):
'invoice lbs helper converts kilogram quantities with the proper uom ratio' 'invoice lbs helper converts kilogram quantities with the proper uom ratio'
@@ -1159,7 +1159,9 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(invoice.report_lbs, Decimal('2204608.98')) self.assertEqual(invoice.report_lbs, Decimal('2204608.98'))
self.assertEqual( self.assertEqual(
invoice.report_quantity_lines, invoice.report_quantity_lines,
'999995.0 KILOGRAM (2204608.98 LBS)') '999995.00 KILOGRAM (2204608.98 LBS)')
self.assertEqual(invoice.report_net_display, '999995.00')
self.assertEqual(invoice.report_lbs_display, '2204608.98')
def test_invoice_report_weights_keep_line_sign_with_lot_hist_values(self): def test_invoice_report_weights_keep_line_sign_with_lot_hist_values(self):
'invoice lot hist values keep the invoice line sign for final notes' 'invoice lot hist values keep the invoice line sign for final notes'