kg lbs
This commit is contained in:
@@ -131,6 +131,45 @@ class Invoice(metaclass=PoolMeta):
|
||||
return lots[0].lot_unit_line
|
||||
return getattr(line, 'unit', None)
|
||||
|
||||
@staticmethod
|
||||
def _get_report_lbs_unit():
|
||||
Uom = Pool().get('product.uom')
|
||||
for domain in (
|
||||
[('symbol', '=', 'LBS')],
|
||||
[('rec_name', '=', 'LBS')],
|
||||
[('name', '=', 'LBS')],
|
||||
[('symbol', '=', 'LB')],
|
||||
[('rec_name', '=', 'LB')],
|
||||
[('name', '=', 'LB')]):
|
||||
units = Uom.search(domain, limit=1)
|
||||
if units:
|
||||
return units[0]
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _convert_report_quantity_to_lbs(cls, quantity, unit):
|
||||
value = Decimal(str(quantity or 0))
|
||||
if value == 0:
|
||||
return Decimal('0.00')
|
||||
if not unit:
|
||||
return (value * Decimal('2204.62')).quantize(Decimal('0.01'))
|
||||
label = (
|
||||
getattr(unit, 'symbol', None)
|
||||
or getattr(unit, 'rec_name', None)
|
||||
or getattr(unit, 'name', None)
|
||||
or ''
|
||||
).strip().upper()
|
||||
if label in {'LBS', 'LB', 'POUND', 'POUNDS'}:
|
||||
return value.quantize(Decimal('0.01'))
|
||||
lbs_unit = cls._get_report_lbs_unit()
|
||||
if lbs_unit:
|
||||
converted = Pool().get('product.uom').compute_qty(
|
||||
unit, float(value), lbs_unit) or 0
|
||||
return Decimal(str(converted)).quantize(Decimal('0.01'))
|
||||
if label in {'KG', 'KGS', 'KILOGRAM', 'KILOGRAMS'}:
|
||||
return (value * Decimal('2.20462')).quantize(Decimal('0.01'))
|
||||
return (value * Decimal('2204.62')).quantize(Decimal('0.01'))
|
||||
|
||||
@staticmethod
|
||||
def _clean_report_description(value):
|
||||
text = (value or '').strip()
|
||||
@@ -517,7 +556,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
quantity, keep_trailing_decimal=True)
|
||||
unit = self._get_report_invoice_line_unit(line)
|
||||
unit_name = unit.rec_name.upper() if unit and unit.rec_name else ''
|
||||
lbs = round(Decimal(quantity) * Decimal('2204.62'), 2)
|
||||
lbs = self._convert_report_quantity_to_lbs(quantity, unit)
|
||||
parts = [quantity_text, unit_name]
|
||||
if lbs != '':
|
||||
parts.append(
|
||||
@@ -746,7 +785,9 @@ class Invoice(metaclass=PoolMeta):
|
||||
net = self.report_net
|
||||
if net == '':
|
||||
return ''
|
||||
return round(Decimal(net) * Decimal('2204.62'),2)
|
||||
invoice_line = self._get_report_invoice_line()
|
||||
unit = self._get_report_invoice_line_unit(invoice_line) if invoice_line else None
|
||||
return self._convert_report_quantity_to_lbs(net, unit)
|
||||
|
||||
@property
|
||||
def report_weight_unit_upper(self):
|
||||
@@ -996,7 +1037,8 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
net = self.report_net
|
||||
if net == '':
|
||||
return ''
|
||||
return round(Decimal(net) * Decimal('2204.62'),2)
|
||||
unit = Invoice._get_report_invoice_line_unit(self)
|
||||
return Invoice._convert_report_quantity_to_lbs(net, unit)
|
||||
|
||||
|
||||
class ReportTemplateMixin:
|
||||
|
||||
Reference in New Issue
Block a user