CN/DN
This commit is contained in:
@@ -923,6 +923,48 @@ class Invoice(metaclass=PoolMeta):
|
|||||||
total += current_gross - previous_gross
|
total += current_gross - previous_gross
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
def _get_report_weight_adjustment_totals(self):
|
||||||
|
reused_lots = self._get_report_reused_lot_lines()
|
||||||
|
if not reused_lots:
|
||||||
|
return None
|
||||||
|
|
||||||
|
invoice_total = Decimal(0)
|
||||||
|
landed_total = Decimal(0)
|
||||||
|
matched = False
|
||||||
|
for data in reused_lots.values():
|
||||||
|
lot = data['lot']
|
||||||
|
lines = data['lines']
|
||||||
|
negative_lines = [
|
||||||
|
line for line in lines
|
||||||
|
if Decimal(str(getattr(line, 'quantity', 0) or 0)) < 0
|
||||||
|
]
|
||||||
|
positive_lines = [
|
||||||
|
line for line in lines
|
||||||
|
if Decimal(str(getattr(line, 'quantity', 0) or 0)) > 0
|
||||||
|
]
|
||||||
|
if not negative_lines or not positive_lines:
|
||||||
|
continue
|
||||||
|
|
||||||
|
invoice_total += sum(
|
||||||
|
abs(self._get_report_invoice_line_weights(line)[0])
|
||||||
|
for line in negative_lines)
|
||||||
|
current_net, _ = self._get_report_lot_hist_weights(lot)
|
||||||
|
if current_net is None:
|
||||||
|
landed_total += sum(
|
||||||
|
abs(self._get_report_invoice_line_weights(line)[0])
|
||||||
|
for line in positive_lines)
|
||||||
|
else:
|
||||||
|
landed_total += current_net
|
||||||
|
matched = True
|
||||||
|
|
||||||
|
if not matched:
|
||||||
|
return None
|
||||||
|
return {
|
||||||
|
'invoice': invoice_total,
|
||||||
|
'landed': landed_total,
|
||||||
|
'difference': abs(landed_total - invoice_total),
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_report_invoice_line_unit(line):
|
def _get_report_invoice_line_unit(line):
|
||||||
snapshots = Invoice._get_report_invoice_line_weight_snapshots(line)
|
snapshots = Invoice._get_report_invoice_line_weight_snapshots(line)
|
||||||
@@ -1736,6 +1778,9 @@ class Invoice(metaclass=PoolMeta):
|
|||||||
@property
|
@property
|
||||||
def report_gross(self):
|
def report_gross(self):
|
||||||
if self.lines:
|
if self.lines:
|
||||||
|
adjustment = self._get_report_weight_adjustment_totals()
|
||||||
|
if adjustment:
|
||||||
|
return adjustment['landed']
|
||||||
reused_gross = self._get_report_reused_lot_gross_total()
|
reused_gross = self._get_report_reused_lot_gross_total()
|
||||||
if reused_gross is not None:
|
if reused_gross is not None:
|
||||||
non_reused_total = sum(
|
non_reused_total = sum(
|
||||||
@@ -1757,6 +1802,9 @@ class Invoice(metaclass=PoolMeta):
|
|||||||
@property
|
@property
|
||||||
def report_net(self):
|
def report_net(self):
|
||||||
if self.lines:
|
if self.lines:
|
||||||
|
adjustment = self._get_report_weight_adjustment_totals()
|
||||||
|
if adjustment:
|
||||||
|
return adjustment['invoice']
|
||||||
return sum(
|
return sum(
|
||||||
self._get_report_invoice_line_weights(line)[0]
|
self._get_report_invoice_line_weights(line)[0]
|
||||||
for line in self._get_report_invoice_lines())
|
for line in self._get_report_invoice_lines())
|
||||||
@@ -1790,6 +1838,9 @@ class Invoice(metaclass=PoolMeta):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def report_weight_difference(self):
|
def report_weight_difference(self):
|
||||||
|
adjustment = self._get_report_weight_adjustment_totals()
|
||||||
|
if adjustment:
|
||||||
|
return adjustment['difference']
|
||||||
gross = self.report_gross
|
gross = self.report_gross
|
||||||
net = self.report_net
|
net = self.report_net
|
||||||
if gross == '' or net == '':
|
if gross == '' or net == '':
|
||||||
|
|||||||
@@ -6779,8 +6779,8 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
self.assertEqual(invoice.report_net, Decimal('800'))
|
self.assertEqual(invoice.report_net, Decimal('800'))
|
||||||
self.assertEqual(invoice.report_gross, Decimal('820'))
|
self.assertEqual(invoice.report_gross, Decimal('820'))
|
||||||
|
|
||||||
def test_invoice_report_uses_line_quantities_when_same_lot_is_invoiced_twice(self):
|
def test_invoice_report_shows_old_current_and_difference_for_same_lot_note(self):
|
||||||
'invoice final note keeps line differences when two lines share the same lot'
|
'final note weight adjustment shows old, current and difference weights'
|
||||||
Invoice = Pool().get('account.invoice')
|
Invoice = Pool().get('account.invoice')
|
||||||
|
|
||||||
mt = Mock(id=1, rec_name='MT')
|
mt = Mock(id=1, rec_name='MT')
|
||||||
@@ -6843,8 +6843,12 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
with patch('trytond.modules.purchase_trade.invoice.Pool') as PoolMock:
|
with patch('trytond.modules.purchase_trade.invoice.Pool') as PoolMock:
|
||||||
PoolMock.return_value.get.return_value = uom_model
|
PoolMock.return_value.get.return_value = uom_model
|
||||||
|
|
||||||
self.assertEqual(invoice.report_net, Decimal('-5.000'))
|
self.assertEqual(invoice.report_net, Decimal('999995.0'))
|
||||||
self.assertEqual(invoice.report_gross, Decimal('-6'))
|
self.assertEqual(invoice.report_gross, Decimal('999990'))
|
||||||
|
self.assertEqual(invoice.report_weight_difference, Decimal('5.0'))
|
||||||
|
self.assertEqual(invoice.report_net_display, '999995.00')
|
||||||
|
self.assertEqual(invoice.report_gross_display, '999990.00')
|
||||||
|
self.assertEqual(invoice.report_weight_difference_display, '5.00')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
invoice.report_quantity_lines.splitlines(),
|
invoice.report_quantity_lines.splitlines(),
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user