02.04.26
This commit is contained in:
@@ -377,31 +377,15 @@ class Invoice(metaclass=PoolMeta):
|
|||||||
def report_nb_bale(self):
|
def report_nb_bale(self):
|
||||||
lots = self._get_report_invoice_lots()
|
lots = self._get_report_invoice_lots()
|
||||||
if lots:
|
if lots:
|
||||||
Uom = Pool().get('product.uom')
|
|
||||||
line = self._get_report_invoice_line() or self._get_report_trade_line()
|
|
||||||
invoice_unit = getattr(line, 'unit', None) if line else None
|
|
||||||
net = Decimal(str(self.report_net or 0))
|
|
||||||
total_packages = Decimal(0)
|
total_packages = Decimal(0)
|
||||||
total_weight = Decimal(0)
|
|
||||||
package_unit = None
|
package_unit = None
|
||||||
for lot in lots:
|
for lot in lots:
|
||||||
if getattr(lot, 'lot_qt', None):
|
if getattr(lot, 'lot_qt', None):
|
||||||
total_packages += Decimal(str(lot.lot_qt or 0))
|
total_packages += Decimal(str(lot.lot_qt or 0))
|
||||||
if not package_unit and getattr(lot, 'lot_unit', None):
|
if not package_unit and getattr(lot, 'lot_unit', None):
|
||||||
package_unit = lot.lot_unit
|
package_unit = lot.lot_unit
|
||||||
lot_quantity = Decimal(str(getattr(lot, 'lot_quantity', 0) or 0))
|
|
||||||
lot_unit_line = getattr(lot, 'lot_unit_line', None)
|
|
||||||
if lot_quantity and lot_unit_line and invoice_unit:
|
|
||||||
total_weight += Decimal(str(
|
|
||||||
Uom.compute_qty(
|
|
||||||
lot_unit_line, float(lot_quantity), invoice_unit,
|
|
||||||
round=False) or 0))
|
|
||||||
if total_packages:
|
if total_packages:
|
||||||
package_qty = total_packages
|
package_qty = total_packages.quantize(
|
||||||
if total_weight and net:
|
|
||||||
package_qty = (
|
|
||||||
net / (total_weight / total_packages))
|
|
||||||
package_qty = package_qty.quantize(
|
|
||||||
Decimal('1'), rounding=ROUND_HALF_UP)
|
Decimal('1'), rounding=ROUND_HALF_UP)
|
||||||
if package_qty:
|
if package_qty:
|
||||||
label = self._format_report_package_label(package_unit)
|
label = self._format_report_package_label(package_unit)
|
||||||
|
|||||||
@@ -333,8 +333,8 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
|
|
||||||
self.assertEqual(invoice.report_net, Decimal('800'))
|
self.assertEqual(invoice.report_net, Decimal('800'))
|
||||||
|
|
||||||
def test_invoice_report_nb_bale_uses_linked_lot_packaging(self):
|
def test_invoice_report_nb_bale_uses_linked_lot_quantity_only(self):
|
||||||
'invoice reports packaging from linked physical lots with signed prorata'
|
'invoice reports packaging from linked physical lots using lot_qt only'
|
||||||
Invoice = Pool().get('account.invoice')
|
Invoice = Pool().get('account.invoice')
|
||||||
|
|
||||||
line = Mock(type='line', quantity=Decimal('-15'))
|
line = Mock(type='line', quantity=Decimal('-15'))
|
||||||
@@ -353,17 +353,11 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
)
|
)
|
||||||
sale_line.lots = [lot]
|
sale_line.lots = [lot]
|
||||||
sale = Mock(lines=[sale_line])
|
sale = Mock(lines=[sale_line])
|
||||||
uom_model = Mock()
|
|
||||||
uom_model.compute_qty.return_value = Decimal('2000')
|
|
||||||
invoice = Invoice()
|
invoice = Invoice()
|
||||||
invoice.sales = [sale]
|
invoice.sales = [sale]
|
||||||
invoice.lines = [line]
|
invoice.lines = [line]
|
||||||
|
|
||||||
with patch(
|
self.assertEqual(invoice.report_nb_bale, 'NB BALES: 700')
|
||||||
'trytond.modules.purchase_trade.invoice.Pool'
|
|
||||||
) as PoolMock:
|
|
||||||
PoolMock.return_value.get.return_value = uom_model
|
|
||||||
self.assertEqual(invoice.report_nb_bale, 'NB BALES: -5')
|
|
||||||
|
|
||||||
def test_invoice_report_positive_rate_lines_keep_positive_components(self):
|
def test_invoice_report_positive_rate_lines_keep_positive_components(self):
|
||||||
'invoice final note pricing section keeps only positive component lines'
|
'invoice final note pricing section keeps only positive component lines'
|
||||||
|
|||||||
Reference in New Issue
Block a user