Add Packing list template
This commit is contained in:
@@ -533,6 +533,46 @@ class ShipmentIn(metaclass=PoolMeta):
|
||||
value = Decimal(str(value or 0)).quantize(Decimal('0.01'))
|
||||
return format(value, 'f')
|
||||
|
||||
@staticmethod
|
||||
def _format_report_quantity(value, digits='0.001'):
|
||||
if value in (None, ''):
|
||||
return ''
|
||||
quantity = Decimal(str(value or 0)).quantize(Decimal(digits))
|
||||
text = format(quantity, 'f')
|
||||
return text.rstrip('0').rstrip('.') or '0'
|
||||
|
||||
def _get_report_trade(self):
|
||||
line = self._get_report_trade_line()
|
||||
if not line:
|
||||
return None
|
||||
return getattr(line, 'sale', None) or getattr(line, 'purchase', None)
|
||||
|
||||
def _get_report_weight_totals(self):
|
||||
net = Decimal('0')
|
||||
gross = Decimal('0')
|
||||
for move in (self.incoming_moves or self.moves or []):
|
||||
lot = getattr(move, 'lot', None)
|
||||
if lot:
|
||||
lot_net = (
|
||||
lot.get_current_quantity()
|
||||
if hasattr(lot, 'get_current_quantity')
|
||||
else lot.get_current_quantity_converted()
|
||||
if hasattr(lot, 'get_current_quantity_converted')
|
||||
else getattr(move, 'quantity', 0)
|
||||
)
|
||||
lot_gross = (
|
||||
lot.get_current_gross_quantity()
|
||||
if hasattr(lot, 'get_current_gross_quantity')
|
||||
else lot_net
|
||||
)
|
||||
net += Decimal(str(lot_net or 0))
|
||||
gross += Decimal(str(lot_gross or 0))
|
||||
else:
|
||||
quantity = Decimal(str(getattr(move, 'quantity', 0) or 0))
|
||||
net += quantity
|
||||
gross += quantity
|
||||
return net, gross
|
||||
|
||||
@property
|
||||
def report_product_name(self):
|
||||
line = self._get_report_trade_line()
|
||||
@@ -652,6 +692,87 @@ class ShipmentIn(metaclass=PoolMeta):
|
||||
today = Date.today()
|
||||
date_text = today.strftime('%d-%m-%Y') if today else ''
|
||||
return ', '.join(part for part in [place, date_text] if part)
|
||||
|
||||
@property
|
||||
def report_packing_product_class(self):
|
||||
return self.report_product_name
|
||||
|
||||
@property
|
||||
def report_packing_contract_number(self):
|
||||
trade = self._get_report_trade()
|
||||
return (
|
||||
getattr(trade, 'reference', None)
|
||||
or getattr(trade, 'number', None)
|
||||
or self.reference
|
||||
or self.number
|
||||
or '')
|
||||
|
||||
@property
|
||||
def report_packing_invoice_qty(self):
|
||||
quantity = self.quantity if self.quantity not in (None, '') else 0
|
||||
return self._format_report_quantity(quantity)
|
||||
|
||||
@property
|
||||
def report_packing_invoice_qty_unit(self):
|
||||
unit = self.unit
|
||||
return (
|
||||
getattr(unit, 'symbol', None)
|
||||
or getattr(unit, 'rec_name', None)
|
||||
or '')
|
||||
|
||||
@property
|
||||
def report_packing_origin(self):
|
||||
trade = self._get_report_trade()
|
||||
return (
|
||||
getattr(trade, 'product_origin', None)
|
||||
or getattr(self.from_location, 'name', None)
|
||||
or '')
|
||||
|
||||
@property
|
||||
def report_packing_product(self):
|
||||
return self.report_product_name
|
||||
|
||||
@property
|
||||
def report_packing_counterparty_name(self):
|
||||
trade = self._get_report_trade()
|
||||
party = getattr(trade, 'party', None) if trade else None
|
||||
if party:
|
||||
return party.rec_name or ''
|
||||
return getattr(self.supplier, 'rec_name', '') or ''
|
||||
|
||||
@property
|
||||
def report_packing_ship_name(self):
|
||||
if self.vessel and self.vessel.vessel_name:
|
||||
return self.vessel.vessel_name
|
||||
return self.transport_type or ''
|
||||
|
||||
@property
|
||||
def report_packing_loading_port(self):
|
||||
return getattr(self.from_location, 'name', '') or ''
|
||||
|
||||
@property
|
||||
def report_packing_destination_port(self):
|
||||
return getattr(self.to_location, 'name', '') or ''
|
||||
|
||||
@property
|
||||
def report_packing_chunk_number(self):
|
||||
return self.bl_number or self.number or ''
|
||||
|
||||
@property
|
||||
def report_packing_chunk_date(self):
|
||||
if self.bl_date:
|
||||
return self.bl_date.strftime('%d-%m-%Y')
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_packing_gross_weight(self):
|
||||
_, gross = self._get_report_weight_totals()
|
||||
return self._format_report_quantity(gross)
|
||||
|
||||
@property
|
||||
def report_packing_net_weight(self):
|
||||
net, _ = self._get_report_weight_totals()
|
||||
return self._format_report_quantity(net)
|
||||
|
||||
def get_rec_name(self, name=None):
|
||||
if self.number:
|
||||
@@ -2153,3 +2274,12 @@ class ShipmentInsuranceReport(ShipmentTemplateReportMixin, BaseSupplierShipping)
|
||||
def _resolve_configured_report_path(cls, action):
|
||||
return cls._resolve_template_path(
|
||||
'shipment_insurance_report_template', 'stock')
|
||||
|
||||
|
||||
class ShipmentPackingListReport(ShipmentTemplateReportMixin, BaseSupplierShipping):
|
||||
__name__ = 'stock.shipment.in.packing_list'
|
||||
|
||||
@classmethod
|
||||
def _resolve_configured_report_path(cls, action):
|
||||
return cls._resolve_template_path(
|
||||
'shipment_packing_list_report_template', 'stock')
|
||||
|
||||
Reference in New Issue
Block a user