02.04.26
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from decimal import Decimal
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.modules.purchase_trade.numbers_to_words import amount_to_currency_words
|
||||
@@ -329,12 +329,26 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
@property
|
||||
def report_nb_bale(self):
|
||||
unit = self.report_weight_unit_upper
|
||||
net = self.report_net
|
||||
if net != '' and unit == 'MT':
|
||||
quantity = abs(Decimal(str(net or 0))).quantize(Decimal('1'))
|
||||
if quantity:
|
||||
return 'NB BALES: ' + str(int(quantity))
|
||||
line = self._get_report_trade_line() or self._get_report_invoice_line()
|
||||
unit = getattr(line, 'unit', None) if line else None
|
||||
if net != '' and unit:
|
||||
Uom = Pool().get('product.uom')
|
||||
bale_uom = Uom.get_by_name('bale')
|
||||
if not bale_uom:
|
||||
bale_uoms = Uom.search([
|
||||
('name', 'ilike', 'bale'),
|
||||
], limit=1)
|
||||
bale_uom = bale_uoms[0] if bale_uoms else None
|
||||
if bale_uom and getattr(unit, 'category', None) == getattr(
|
||||
bale_uom, 'category', None):
|
||||
bale_qty = Decimal(str(
|
||||
Uom.compute_qty(unit, float(net), bale_uom, round=False)
|
||||
or 0))
|
||||
bale_qty = bale_qty.quantize(
|
||||
Decimal('1'), rounding=ROUND_HALF_UP)
|
||||
if bale_qty:
|
||||
return 'NB BALES: ' + str(int(bale_qty))
|
||||
sale = self._get_report_sale()
|
||||
if sale and sale.report_nb_bale:
|
||||
return sale.report_nb_bale
|
||||
|
||||
@@ -333,16 +333,25 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
|
||||
self.assertEqual(invoice.report_net, Decimal('800'))
|
||||
|
||||
def test_invoice_report_nb_bale_uses_abs_mt_difference(self):
|
||||
'invoice final note displays bale count as rounded MT differential'
|
||||
def test_invoice_report_nb_bale_uses_uom_conversion_with_sign(self):
|
||||
'invoice final note converts signed net quantity to bale using UoM rules'
|
||||
Invoice = Pool().get('account.invoice')
|
||||
|
||||
line = Mock(type='line', quantity=Decimal('-15'))
|
||||
line.unit = Mock(rec_name='MT')
|
||||
line.unit.category = Mock()
|
||||
bale_uom = Mock(category=line.unit.category)
|
||||
uom_model = Mock()
|
||||
uom_model.get_by_name.return_value = bale_uom
|
||||
uom_model.compute_qty.return_value = Decimal('-53.6')
|
||||
invoice = Invoice()
|
||||
invoice.lines = [line]
|
||||
|
||||
self.assertEqual(invoice.report_nb_bale, 'NB BALES: 15')
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.invoice.Pool'
|
||||
) as PoolMock:
|
||||
PoolMock.return_value.get.return_value = uom_model
|
||||
self.assertEqual(invoice.report_nb_bale, 'NB BALES: -54')
|
||||
|
||||
def test_invoice_report_positive_rate_lines_keep_positive_components(self):
|
||||
'invoice final note pricing section keeps only positive component lines'
|
||||
|
||||
Reference in New Issue
Block a user