bug template

This commit is contained in:
2026-04-09 21:38:26 +02:00
parent 9c8d7f11ae
commit 4bbd7a5e76
2 changed files with 106 additions and 0 deletions

View File

@@ -109,6 +109,9 @@ class Invoice(metaclass=PoolMeta):
def _get_report_invoice_line_weights(self, line):
lots = self._get_report_preferred_lots(line)
if lots and self._report_invoice_line_reuses_lot(line):
quantity = self._get_report_invoice_line_quantity_from_line(line)
return quantity, quantity
if lots:
sign = self._get_report_line_sign(line)
net_total = Decimal(0)
@@ -124,6 +127,49 @@ class Invoice(metaclass=PoolMeta):
quantity = Decimal(str(getattr(line, 'quantity', 0) or 0))
return quantity, quantity
@staticmethod
def _get_report_line_lot_keys(line):
keys = []
for lot in Invoice._get_report_preferred_lots(line):
lot_id = getattr(lot, 'id', None)
keys.append(lot_id if lot_id is not None else id(lot))
return tuple(sorted(keys))
def _report_invoice_line_reuses_lot(self, line):
line_keys = self._get_report_line_lot_keys(line)
if not line_keys:
return False
for other in self._get_report_invoice_lines():
if other is line:
continue
if self._get_report_line_lot_keys(other) == line_keys:
return True
return False
@staticmethod
def _convert_report_quantity(quantity, from_unit, to_unit):
value = Decimal(str(quantity or 0))
if not from_unit or not to_unit:
return value
if getattr(from_unit, 'id', None) == getattr(to_unit, 'id', None):
return value
from_name = getattr(from_unit, 'rec_name', None)
to_name = getattr(to_unit, 'rec_name', None)
if from_name and to_name and from_name == to_name:
return value
converted = Pool().get('product.uom').compute_qty(
from_unit, float(value), to_unit) or 0
return Decimal(str(converted))
@classmethod
def _get_report_invoice_line_quantity_from_line(cls, line):
quantity = Decimal(str(getattr(line, 'quantity', 0) or 0))
return cls._convert_report_quantity(
quantity,
getattr(line, 'unit', None),
cls._get_report_invoice_line_unit(line),
)
@staticmethod
def _get_report_invoice_line_unit(line):
lots = Invoice._get_report_preferred_lots(line)
@@ -1022,6 +1068,9 @@ class InvoiceLine(metaclass=PoolMeta):
@property
def report_net(self):
if self.type == 'line':
invoice = getattr(self, 'invoice', None)
if invoice and invoice._report_invoice_line_reuses_lot(self):
return Invoice._get_report_invoice_line_quantity_from_line(self)
lot = getattr(self, 'lot', None)
if lot:
net, _ = Invoice._get_report_lot_hist_weights(lot)