CN/DN
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
from datetime import date as dt_date
|
||||
import os
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from sql import Literal
|
||||
@@ -19,6 +20,8 @@ from trytond.modules.sale.sale import SaleReport as BaseSaleReport
|
||||
from trytond.modules.purchase.purchase import (
|
||||
PurchaseReport as BasePurchaseReport)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class InvoiceLineLotWeight(ModelSQL, ModelView):
|
||||
"Invoice Line Lot Weight"
|
||||
@@ -926,6 +929,20 @@ class Invoice(metaclass=PoolMeta):
|
||||
def _get_report_weight_adjustment_totals(self):
|
||||
reused_lots = self._get_report_reused_lot_lines()
|
||||
if not reused_lots:
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_NO_REUSED_LOTS: invoice=%s "
|
||||
"line_count=%s lines=%s",
|
||||
getattr(self, 'id', None),
|
||||
len(self._get_report_invoice_lines()),
|
||||
[
|
||||
{
|
||||
'line': getattr(line, 'id', None),
|
||||
'quantity': str(getattr(line, 'quantity', None)),
|
||||
'lot': getattr(getattr(line, 'lot', None), 'id', None),
|
||||
'lot_keys': self._get_report_line_lot_keys(line),
|
||||
}
|
||||
for line in self._get_report_invoice_lines()
|
||||
])
|
||||
return None
|
||||
|
||||
invoice_total = Decimal(0)
|
||||
@@ -934,6 +951,12 @@ class Invoice(metaclass=PoolMeta):
|
||||
for data in reused_lots.values():
|
||||
lot = data['lot']
|
||||
lines = data['lines']
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_GROUP: invoice=%s lot=%s "
|
||||
"line_ids=%s quantities=%s",
|
||||
getattr(self, 'id', None), getattr(lot, 'id', None),
|
||||
[getattr(line, 'id', None) for line in lines],
|
||||
[str(getattr(line, 'quantity', None)) for line in lines])
|
||||
negative_lines = [
|
||||
line for line in lines
|
||||
if Decimal(str(getattr(line, 'quantity', 0) or 0)) < 0
|
||||
@@ -943,18 +966,47 @@ class Invoice(metaclass=PoolMeta):
|
||||
if Decimal(str(getattr(line, 'quantity', 0) or 0)) > 0
|
||||
]
|
||||
if not negative_lines or not positive_lines:
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_SKIP_GROUP: invoice=%s lot=%s "
|
||||
"negative=%s positive=%s",
|
||||
getattr(self, 'id', None), getattr(lot, 'id', None),
|
||||
[str(getattr(line, 'quantity', None))
|
||||
for line in negative_lines],
|
||||
[str(getattr(line, 'quantity', None))
|
||||
for line in positive_lines])
|
||||
continue
|
||||
|
||||
invoice_total += sum(
|
||||
invoice_values = [
|
||||
abs(self._get_report_invoice_line_weights(line)[0])
|
||||
for line in negative_lines)
|
||||
landed_total += sum(
|
||||
for line in negative_lines]
|
||||
landed_values = [
|
||||
abs(self._get_report_invoice_line_quantity_from_line(line))
|
||||
for line in positive_lines)
|
||||
for line in positive_lines]
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_VALUES: invoice=%s lot=%s "
|
||||
"negative_raw=%s invoice_values=%s positive_raw=%s "
|
||||
"landed_values=%s",
|
||||
getattr(self, 'id', None), getattr(lot, 'id', None),
|
||||
[str(getattr(line, 'quantity', None))
|
||||
for line in negative_lines],
|
||||
[str(value) for value in invoice_values],
|
||||
[str(getattr(line, 'quantity', None))
|
||||
for line in positive_lines],
|
||||
[str(value) for value in landed_values])
|
||||
invoice_total += sum(invoice_values)
|
||||
landed_total += sum(landed_values)
|
||||
matched = True
|
||||
|
||||
if not matched:
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_NO_MATCH: invoice=%s reused_lots=%s",
|
||||
getattr(self, 'id', None), list(reused_lots.keys()))
|
||||
return None
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_RESULT: invoice=%s invoice_weight=%s "
|
||||
"landed_weight=%s difference=%s",
|
||||
getattr(self, 'id', None), invoice_total, landed_total,
|
||||
abs(landed_total - invoice_total))
|
||||
return {
|
||||
'invoice': invoice_total,
|
||||
'landed': landed_total,
|
||||
@@ -1776,6 +1828,9 @@ class Invoice(metaclass=PoolMeta):
|
||||
if self.lines:
|
||||
adjustment = self._get_report_weight_adjustment_totals()
|
||||
if adjustment:
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_USE_GROSS: invoice=%s value=%s",
|
||||
getattr(self, 'id', None), adjustment['landed'])
|
||||
return adjustment['landed']
|
||||
reused_gross = self._get_report_reused_lot_gross_total()
|
||||
if reused_gross is not None:
|
||||
@@ -1800,6 +1855,9 @@ class Invoice(metaclass=PoolMeta):
|
||||
if self.lines:
|
||||
adjustment = self._get_report_weight_adjustment_totals()
|
||||
if adjustment:
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_USE_NET: invoice=%s value=%s",
|
||||
getattr(self, 'id', None), adjustment['invoice'])
|
||||
return adjustment['invoice']
|
||||
return sum(
|
||||
self._get_report_invoice_line_weights(line)[0]
|
||||
@@ -1836,6 +1894,10 @@ class Invoice(metaclass=PoolMeta):
|
||||
def report_weight_difference(self):
|
||||
adjustment = self._get_report_weight_adjustment_totals()
|
||||
if adjustment:
|
||||
logger.warning(
|
||||
"REPORT_WEIGHT_ADJUSTMENT_USE_DIFFERENCE: invoice=%s "
|
||||
"value=%s",
|
||||
getattr(self, 'id', None), adjustment['difference'])
|
||||
return adjustment['difference']
|
||||
gross = self.report_gross
|
||||
net = self.report_net
|
||||
|
||||
Reference in New Issue
Block a user