CN/DN
This commit is contained in:
@@ -923,6 +923,48 @@ class Invoice(metaclass=PoolMeta):
|
||||
total += current_gross - previous_gross
|
||||
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
|
||||
def _get_report_invoice_line_unit(line):
|
||||
snapshots = Invoice._get_report_invoice_line_weight_snapshots(line)
|
||||
@@ -1736,6 +1778,9 @@ class Invoice(metaclass=PoolMeta):
|
||||
@property
|
||||
def report_gross(self):
|
||||
if self.lines:
|
||||
adjustment = self._get_report_weight_adjustment_totals()
|
||||
if adjustment:
|
||||
return adjustment['landed']
|
||||
reused_gross = self._get_report_reused_lot_gross_total()
|
||||
if reused_gross is not None:
|
||||
non_reused_total = sum(
|
||||
@@ -1757,6 +1802,9 @@ class Invoice(metaclass=PoolMeta):
|
||||
@property
|
||||
def report_net(self):
|
||||
if self.lines:
|
||||
adjustment = self._get_report_weight_adjustment_totals()
|
||||
if adjustment:
|
||||
return adjustment['invoice']
|
||||
return sum(
|
||||
self._get_report_invoice_line_weights(line)[0]
|
||||
for line in self._get_report_invoice_lines())
|
||||
@@ -1790,6 +1838,9 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
@property
|
||||
def report_weight_difference(self):
|
||||
adjustment = self._get_report_weight_adjustment_totals()
|
||||
if adjustment:
|
||||
return adjustment['difference']
|
||||
gross = self.report_gross
|
||||
net = self.report_net
|
||||
if gross == '' or net == '':
|
||||
|
||||
Reference in New Issue
Block a user