02.04.26
This commit is contained in:
@@ -319,47 +319,107 @@ class Sale(metaclass=PoolMeta):
|
||||
def default_tol_min(cls):
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def default_tol_max(cls):
|
||||
return 0
|
||||
|
||||
@property
|
||||
def report_terms(self):
|
||||
if self.lines:
|
||||
return self.lines[0].note
|
||||
else:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_gross(self):
|
||||
if self.lines:
|
||||
return sum([l.get_current_gross_quantity() for l in self.lines[0].lots if l.lot_type == 'physic'])
|
||||
else:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_net(self):
|
||||
if self.lines:
|
||||
return sum([l.get_current_quantity() for l in self.lines[0].lots if l.lot_type == 'physic'])
|
||||
else:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_qt(self):
|
||||
if self.lines:
|
||||
return quantity_to_words(self.lines[0].quantity)
|
||||
else:
|
||||
return ''
|
||||
|
||||
@property
|
||||
@classmethod
|
||||
def default_tol_max(cls):
|
||||
return 0
|
||||
|
||||
def _get_report_lines(self):
|
||||
return [line for line in self.lines if getattr(line, 'type', None) == 'line']
|
||||
|
||||
def _get_report_first_line(self):
|
||||
lines = self._get_report_lines()
|
||||
if lines:
|
||||
return lines[0]
|
||||
|
||||
@staticmethod
|
||||
def _format_report_number(value, digits='0.0000', keep_trailing_decimal=False,
|
||||
strip_trailing_zeros=True):
|
||||
value = Decimal(str(value or 0)).quantize(Decimal(digits))
|
||||
text = format(value, 'f')
|
||||
if strip_trailing_zeros:
|
||||
text = text.rstrip('0').rstrip('.')
|
||||
if keep_trailing_decimal and '.' not in text:
|
||||
text += '.0'
|
||||
return text or '0'
|
||||
|
||||
def _format_report_price_words(self, line):
|
||||
if getattr(line, 'linked_price', None):
|
||||
return amount_to_currency_words(line.linked_price, 'USC', 'USC')
|
||||
return amount_to_currency_words(line.unit_price)
|
||||
|
||||
def _format_report_price_line(self, line):
|
||||
currency = getattr(line, 'linked_currency', None) or self.currency
|
||||
unit = getattr(line, 'linked_unit', None) or getattr(line, 'unit', None)
|
||||
pricing_text = getattr(line, 'get_pricing_text', '') or ''
|
||||
parts = [
|
||||
(currency.rec_name.upper() if currency and currency.rec_name else '').strip(),
|
||||
self._format_report_number(
|
||||
line.linked_price if getattr(line, 'linked_price', None)
|
||||
else line.unit_price,
|
||||
strip_trailing_zeros=False),
|
||||
'PER',
|
||||
(unit.rec_name.upper() if unit and unit.rec_name else '').strip(),
|
||||
f"({self._format_report_price_words(line)})",
|
||||
]
|
||||
if pricing_text:
|
||||
parts.append(pricing_text)
|
||||
return ' '.join(part for part in parts if part)
|
||||
|
||||
@property
|
||||
def report_terms(self):
|
||||
line = self._get_report_first_line()
|
||||
if line:
|
||||
return line.note
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_gross(self):
|
||||
line = self._get_report_first_line()
|
||||
if line:
|
||||
return sum([l.get_current_gross_quantity() for l in line.lots if l.lot_type == 'physic'])
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_net(self):
|
||||
line = self._get_report_first_line()
|
||||
if line:
|
||||
return sum([l.get_current_quantity() for l in line.lots if l.lot_type == 'physic'])
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_total_quantity(self):
|
||||
lines = self._get_report_lines()
|
||||
if lines:
|
||||
total = sum(Decimal(str(line.quantity or 0)) for line in lines)
|
||||
return self._format_report_number(total, keep_trailing_decimal=True)
|
||||
return '0.0'
|
||||
|
||||
@property
|
||||
def report_quantity_unit_upper(self):
|
||||
line = self._get_report_first_line()
|
||||
if line and line.unit:
|
||||
return line.unit.rec_name.upper()
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_qt(self):
|
||||
lines = self._get_report_lines()
|
||||
if lines:
|
||||
total = sum(Decimal(str(line.quantity or 0)) for line in lines)
|
||||
return quantity_to_words(total)
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_nb_bale(self):
|
||||
text_bale = 'NB BALES: '
|
||||
nb_bale = 0
|
||||
if self.lines:
|
||||
for line in self.lines:
|
||||
lines = self._get_report_lines()
|
||||
if lines:
|
||||
for line in lines:
|
||||
if line.lots:
|
||||
nb_bale += sum([l.lot_qt for l in line.lots if l.lot_type == 'physic'])
|
||||
return text_bale + str(int(nb_bale))
|
||||
if nb_bale:
|
||||
return 'NB BALES: ' + str(int(nb_bale))
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_crop_name(self):
|
||||
@@ -375,29 +435,37 @@ class Sale(metaclass=PoolMeta):
|
||||
''
|
||||
|
||||
@property
|
||||
def report_packing(self):
|
||||
nb_packing = 0
|
||||
unit = ''
|
||||
if self.lines:
|
||||
for line in self.lines:
|
||||
if line.lots:
|
||||
nb_packing += sum([l.lot_qt for l in line.lots if l.lot_type == 'physic'])
|
||||
if len(line.lots)>1:
|
||||
unit = line.lots[1].lot_unit.name
|
||||
return str(int(nb_packing)) + unit
|
||||
def report_packing(self):
|
||||
nb_packing = 0
|
||||
unit = ''
|
||||
lines = self._get_report_lines()
|
||||
if lines:
|
||||
for line in lines:
|
||||
if line.lots:
|
||||
nb_packing += sum([l.lot_qt for l in line.lots if l.lot_type == 'physic'])
|
||||
if len(line.lots)>1:
|
||||
unit = line.lots[1].lot_unit.name
|
||||
return str(int(nb_packing)) + unit
|
||||
|
||||
@property
|
||||
def report_price(self):
|
||||
if self.lines:
|
||||
if self.lines[0].price_type == 'priced':
|
||||
if self.lines[0].linked_price:
|
||||
return amount_to_currency_words(self.lines[0].linked_price,'USC','USC')
|
||||
def report_price(self):
|
||||
line = self._get_report_first_line()
|
||||
if line:
|
||||
if line.price_type == 'priced':
|
||||
if line.linked_price:
|
||||
return amount_to_currency_words(line.linked_price,'USC','USC')
|
||||
else:
|
||||
return amount_to_currency_words(self.lines[0].unit_price)
|
||||
elif self.lines[0].price_type == 'basis':
|
||||
return amount_to_currency_words(self.lines[0].unit_price) + ' ' + self.lines[0].get_pricing_text
|
||||
else:
|
||||
return ''
|
||||
return amount_to_currency_words(line.unit_price)
|
||||
elif line.price_type == 'basis':
|
||||
return amount_to_currency_words(line.unit_price) + ' ' + line.get_pricing_text
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_price_lines(self):
|
||||
lines = self._get_report_lines()
|
||||
if lines:
|
||||
return '\n'.join(self._format_report_price_line(line) for line in lines)
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_delivery(self):
|
||||
@@ -413,20 +481,33 @@ class Sale(metaclass=PoolMeta):
|
||||
|
||||
@property
|
||||
def report_delivery_period_description(self):
|
||||
if self.lines and self.lines[0].del_period:
|
||||
return self.lines[0].del_period.description or ''
|
||||
line = self._get_report_first_line()
|
||||
if line and line.del_period:
|
||||
return line.del_period.description or ''
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_shipment_periods(self):
|
||||
periods = []
|
||||
for line in self._get_report_lines():
|
||||
period = line.del_period.description if line.del_period else ''
|
||||
if period and period not in periods:
|
||||
periods.append(period)
|
||||
if periods:
|
||||
return '\n'.join(periods)
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_payment_date(self):
|
||||
if self.lines:
|
||||
if self.lc_date:
|
||||
return format_date_en(self.lc_date)
|
||||
Date = Pool().get('ir.date')
|
||||
payment_date = self.lines[0].sale.payment_term.lines[0].get_date(Date.today(),self.lines[0])
|
||||
if payment_date:
|
||||
payment_date = format_date_en(payment_date)
|
||||
return payment_date
|
||||
def report_payment_date(self):
|
||||
line = self._get_report_first_line()
|
||||
if line:
|
||||
if self.lc_date:
|
||||
return format_date_en(self.lc_date)
|
||||
Date = Pool().get('ir.date')
|
||||
payment_date = line.sale.payment_term.lines[0].get_date(Date.today(), line)
|
||||
if payment_date:
|
||||
payment_date = format_date_en(payment_date)
|
||||
return payment_date
|
||||
|
||||
@property
|
||||
def report_shipment(self):
|
||||
|
||||
Reference in New Issue
Block a user