Use decimal 0 without digits as default value
If the digits of the field is 0, than using '0.0' trigger the validation error introduced by 2be02f249a1d. Closes #13197 (grafted from 979cd092ea24f04328af5f4ff315c418e1c5b3e6) --HG-- branch : 7.0
This commit is contained in:
@@ -634,8 +634,8 @@ class Reconciliation(ModelSQL, ModelView):
|
||||
def check_lines(cls, reconciliations):
|
||||
Lang = Pool().get('ir.lang')
|
||||
for reconciliation in reconciliations:
|
||||
debit = Decimal('0.0')
|
||||
credit = Decimal('0.0')
|
||||
debit = Decimal(0)
|
||||
credit = Decimal(0)
|
||||
account = None
|
||||
if reconciliation.lines:
|
||||
party = reconciliation.lines[0].party
|
||||
@@ -1160,13 +1160,13 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
||||
@fields.depends('debit', 'credit', 'amount_second_currency')
|
||||
def on_change_debit(self):
|
||||
if self.debit:
|
||||
self.credit = Decimal('0.0')
|
||||
self.credit = Decimal(0)
|
||||
self._amount_second_currency_sign()
|
||||
|
||||
@fields.depends('debit', 'credit', 'amount_second_currency')
|
||||
def on_change_credit(self):
|
||||
if self.credit:
|
||||
self.debit = Decimal('0.0')
|
||||
self.debit = Decimal(0)
|
||||
self._amount_second_currency_sign()
|
||||
|
||||
@fields.depends('amount_second_currency', 'debit', 'credit')
|
||||
@@ -1547,8 +1547,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
||||
lines = list(lines)
|
||||
reconcile_account = None
|
||||
reconcile_party = None
|
||||
amount = Decimal('0.0')
|
||||
amount_second_currency = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
amount_second_currency = Decimal(0)
|
||||
second_currencies = set()
|
||||
posted = True
|
||||
for line in lines:
|
||||
@@ -1990,8 +1990,8 @@ class ReconcileLines(Wizard):
|
||||
def get_writeoff(self):
|
||||
"Return writeoff amount and company"
|
||||
company = currency = None
|
||||
amount = Decimal('0.0')
|
||||
amount_second_currency = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
amount_second_currency = Decimal(0)
|
||||
second_currencies = set()
|
||||
for line in self.records:
|
||||
amount += line.debit - line.credit
|
||||
|
||||
@@ -1094,7 +1094,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin):
|
||||
'''
|
||||
taxes = cls.sort_taxes(taxes)
|
||||
res = cls._unit_compute(taxes, price_unit, date)
|
||||
quantity = Decimal(str(quantity or 0.0))
|
||||
quantity = Decimal(str(quantity or 0))
|
||||
for row in res:
|
||||
row['base'] *= quantity
|
||||
row['amount'] *= quantity
|
||||
|
||||
@@ -195,4 +195,4 @@ Reconcile Lines with write-off::
|
||||
>>> writeoff_line2.account == expense
|
||||
True
|
||||
>>> writeoff_line2.debit
|
||||
Decimal('3.0')
|
||||
Decimal('3')
|
||||
|
||||
@@ -313,7 +313,7 @@ class AEAT303(AEATReport):
|
||||
"computed code %s already defined" % code)
|
||||
amounts['46'] = amounts['27'] - amounts['45']
|
||||
amounts['64'] = amounts['46'] + amounts['58'] + amounts['76']
|
||||
amounts['66'] = amounts['64'] * Decimal(amounts['65']) / Decimal(100.0)
|
||||
amounts['66'] = amounts['64'] * Decimal(amounts['65']) / Decimal(100)
|
||||
amounts['110'] = amounts['78'] = amount_to_compensate
|
||||
amounts['87'] = amounts['110'] - amounts['78']
|
||||
amounts['69'] = (amounts['66'] + amounts['77'] - amounts['78']
|
||||
|
||||
@@ -618,9 +618,9 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
||||
pool = Pool()
|
||||
InvoiceTax = pool.get('account.invoice.tax')
|
||||
|
||||
self.untaxed_amount = Decimal('0.0')
|
||||
self.tax_amount = Decimal('0.0')
|
||||
self.total_amount = Decimal('0.0')
|
||||
self.untaxed_amount = Decimal(0)
|
||||
self.tax_amount = Decimal(0)
|
||||
self.total_amount = Decimal(0)
|
||||
computed_taxes = {}
|
||||
|
||||
if self.lines:
|
||||
@@ -632,13 +632,13 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
||||
if self.currency:
|
||||
return self.currency.is_zero(amount)
|
||||
else:
|
||||
return amount == Decimal('0.0')
|
||||
return amount == Decimal(0)
|
||||
|
||||
tax_keys = []
|
||||
taxes = list(self.taxes or [])
|
||||
for tax in (self.taxes or []):
|
||||
if tax.manual:
|
||||
self.tax_amount += tax.amount or Decimal('0.0')
|
||||
self.tax_amount += tax.amount or Decimal(0)
|
||||
continue
|
||||
key = tax._key
|
||||
if (key not in computed_taxes) or (key in tax_keys):
|
||||
@@ -646,12 +646,12 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
||||
continue
|
||||
tax_keys.append(key)
|
||||
if not is_zero(computed_taxes[key]['base']
|
||||
- (tax.base or Decimal('0.0'))):
|
||||
- (tax.base or Decimal(0))):
|
||||
self.tax_amount += computed_taxes[key]['amount']
|
||||
tax.amount = computed_taxes[key]['amount']
|
||||
tax.base = computed_taxes[key]['base']
|
||||
else:
|
||||
self.tax_amount += tax.amount or Decimal('0.0')
|
||||
self.tax_amount += tax.amount or Decimal(0)
|
||||
for key in computed_taxes:
|
||||
if key not in tax_keys:
|
||||
self.tax_amount += computed_taxes[key]['amount']
|
||||
@@ -2403,8 +2403,8 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
if self.type == 'line':
|
||||
currency = (self.invoice.currency if self.invoice
|
||||
else self.currency)
|
||||
amount = (Decimal(str(self.quantity or '0.0'))
|
||||
* (self.unit_price or Decimal('0.0')))
|
||||
amount = (Decimal(str(self.quantity or 0))
|
||||
* (self.unit_price or Decimal(0)))
|
||||
invoice_type = (
|
||||
self.invoice.type if self.invoice else self.invoice_type)
|
||||
if (invoice_type == 'in'
|
||||
@@ -2419,7 +2419,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
if currency:
|
||||
return currency.round(amount)
|
||||
return amount
|
||||
return Decimal('0.0')
|
||||
return Decimal(0)
|
||||
|
||||
def get_amount(self, name):
|
||||
if self.type == 'line':
|
||||
@@ -2898,11 +2898,11 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
|
||||
|
||||
@staticmethod
|
||||
def default_base():
|
||||
return Decimal('0.0')
|
||||
return Decimal(0)
|
||||
|
||||
@staticmethod
|
||||
def default_amount():
|
||||
return Decimal('0.0')
|
||||
return Decimal(0)
|
||||
|
||||
@staticmethod
|
||||
def default_manual():
|
||||
@@ -3359,7 +3359,7 @@ class PayInvoiceAsk(ModelView):
|
||||
@fields.depends(
|
||||
'lines', 'amount', 'currency', 'invoice', 'payment_lines', 'company')
|
||||
def on_change_lines(self):
|
||||
self.amount_writeoff = Decimal('0.0')
|
||||
self.amount_writeoff = Decimal(0)
|
||||
if not self.invoice:
|
||||
return
|
||||
|
||||
@@ -3436,7 +3436,7 @@ class PayInvoice(Wizard):
|
||||
currency = self.start.currency
|
||||
_, remainder = self.get_reconcile_lines_for_amount(
|
||||
invoice, amount, currency)
|
||||
if remainder == Decimal('0.0') and amount <= invoice.amount_to_pay:
|
||||
if remainder == Decimal(0) and amount <= invoice.amount_to_pay:
|
||||
return 'pay'
|
||||
return 'ask'
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class PaymentTerm(DeactivableMixin, ModelSQL, ModelView):
|
||||
"""
|
||||
# TODO implement business_days
|
||||
# http://pypi.python.org/pypi/BusinessHours/
|
||||
sign = 1 if amount >= Decimal('0.0') else -1
|
||||
sign = 1 if amount >= Decimal(0) else -1
|
||||
res = []
|
||||
remainder = amount
|
||||
for line in self.lines:
|
||||
@@ -62,7 +62,7 @@ class PaymentTerm(DeactivableMixin, ModelSQL, ModelView):
|
||||
value_date = line.get_date(date)
|
||||
if value is None or not value_date:
|
||||
continue
|
||||
if ((remainder - value) * sign) < Decimal('0.0'):
|
||||
if ((remainder - value) * sign) < Decimal(0):
|
||||
res.append((value_date, remainder))
|
||||
break
|
||||
if value:
|
||||
@@ -133,16 +133,16 @@ class PaymentTermLine(sequence_ordered(), ModelSQL, ModelView):
|
||||
@fields.depends('type')
|
||||
def on_change_type(self):
|
||||
if self.type != 'fixed':
|
||||
self.amount = Decimal('0.0')
|
||||
self.amount = Decimal(0)
|
||||
self.currency = None
|
||||
if self.type not in ('percent', 'percent_on_total'):
|
||||
self.ratio = Decimal('0.0')
|
||||
self.divisor = Decimal('0.0')
|
||||
self.ratio = Decimal(0)
|
||||
self.divisor = Decimal(0)
|
||||
|
||||
@fields.depends('ratio')
|
||||
def on_change_ratio(self):
|
||||
if not self.ratio:
|
||||
self.divisor = Decimal('0.0')
|
||||
self.divisor = Decimal(0)
|
||||
else:
|
||||
self.divisor = self.round(1 / self.ratio,
|
||||
self.__class__.divisor.digits[1])
|
||||
@@ -150,7 +150,7 @@ class PaymentTermLine(sequence_ordered(), ModelSQL, ModelView):
|
||||
@fields.depends('divisor')
|
||||
def on_change_divisor(self):
|
||||
if not self.divisor:
|
||||
self.ratio = Decimal('0.0')
|
||||
self.ratio = Decimal(0)
|
||||
else:
|
||||
self.ratio = self.round(1 / self.divisor,
|
||||
self.__class__.ratio.digits[1])
|
||||
|
||||
@@ -830,7 +830,7 @@ class Line(origin_mixin(_states), sequence_ordered(), ModelSQL, ModelView):
|
||||
if self.party:
|
||||
if self.amount:
|
||||
with Transaction().set_context(date=self.date):
|
||||
if self.amount > Decimal("0.0"):
|
||||
if self.amount > Decimal(0):
|
||||
self.account = self.party.account_receivable_used
|
||||
else:
|
||||
self.account = self.party.account_payable_used
|
||||
@@ -856,7 +856,7 @@ class Line(origin_mixin(_states), sequence_ordered(), ModelSQL, ModelView):
|
||||
# The user has entered a non-default value, we keep it.
|
||||
pass
|
||||
elif self.amount:
|
||||
if self.amount > Decimal("0.0"):
|
||||
if self.amount > Decimal(0):
|
||||
self.account = self.party.account_receivable_used
|
||||
else:
|
||||
self.account = self.party.account_payable_used
|
||||
|
||||
@@ -344,7 +344,7 @@ class StatementRuleLine(sequence_ordered(), ModelSQL, ModelView):
|
||||
account = related_to_account
|
||||
elif party:
|
||||
with Transaction().set_context(date=origin.date):
|
||||
if amount > Decimal('0.0'):
|
||||
if amount > Decimal(0):
|
||||
account = party.account_receivable_used
|
||||
else:
|
||||
account = party.account_payable_used
|
||||
|
||||
@@ -31,10 +31,10 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
|
||||
if type_.startswith('in_'):
|
||||
move_line.debit = amount
|
||||
move_line.credit = Decimal('0.0')
|
||||
move_line.credit = Decimal(0)
|
||||
move_line.account = self.product.account_stock_in_used
|
||||
else:
|
||||
move_line.debit = Decimal('0.0')
|
||||
move_line.debit = Decimal(0)
|
||||
move_line.credit = amount
|
||||
move_line.account = self.product.account_stock_out_used
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ class Move(metaclass=PoolMeta):
|
||||
unit, quantity, product.default_uom, round=False)
|
||||
|
||||
as_qty_field = _get_field(type_)
|
||||
cost = Decimal('0.0')
|
||||
cost = Decimal(0)
|
||||
consumed_qty = 0.0
|
||||
for move, move_qty, move_cost_price in cls._get_anglo_saxon_move(
|
||||
moves, total_qty, type_):
|
||||
|
||||
@@ -37,12 +37,12 @@ class Move(metaclass=PoolMeta):
|
||||
Decimal(str(self.quantity)) * unit_price)
|
||||
|
||||
if type_.startswith('in_'):
|
||||
move_line.debit = Decimal('0.0')
|
||||
move_line.debit = Decimal(0)
|
||||
move_line.credit = amount
|
||||
move_line.account = self.product.account_stock_in_used
|
||||
else:
|
||||
move_line.debit = amount
|
||||
move_line.credit = Decimal('0.0')
|
||||
move_line.credit = Decimal(0)
|
||||
move_line.account = self.product.account_stock_out_used
|
||||
|
||||
return [move_line]
|
||||
@@ -58,12 +58,12 @@ class Move(metaclass=PoolMeta):
|
||||
)
|
||||
if not amount:
|
||||
return
|
||||
if amount >= Decimal('0.0'):
|
||||
move_line.debit = Decimal('0.0')
|
||||
if amount >= Decimal(0):
|
||||
move_line.debit = Decimal(0)
|
||||
move_line.credit = amount
|
||||
else:
|
||||
move_line.debit = - amount
|
||||
move_line.credit = Decimal('0.0')
|
||||
move_line.credit = Decimal(0)
|
||||
return move_line
|
||||
|
||||
def _get_account_stock_move_type(self):
|
||||
@@ -141,7 +141,7 @@ class Move(metaclass=PoolMeta):
|
||||
else:
|
||||
account_move_lines = self._get_account_stock_move_lines(type_)
|
||||
|
||||
amount = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
for line in account_move_lines:
|
||||
amount += line.debit - line.credit
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ class Account(
|
||||
for name in names:
|
||||
if name not in ('credit', 'debit'):
|
||||
raise Exception('Bad argument')
|
||||
result[name] = {}.fromkeys(ids, Decimal('0.0'))
|
||||
result[name] = {}.fromkeys(ids, Decimal(0))
|
||||
|
||||
id2account = {}
|
||||
for account in accounts:
|
||||
|
||||
@@ -120,7 +120,7 @@ class Currency(
|
||||
def on_change_with_rate(self):
|
||||
now = datetime.date.today()
|
||||
closer = datetime.date.min
|
||||
res = Decimal('0.0')
|
||||
res = Decimal(0)
|
||||
for rate in self.rates or []:
|
||||
date = getattr(rate, 'date', None) or now
|
||||
if date <= now and date > closer:
|
||||
|
||||
@@ -83,7 +83,7 @@ class Move(metaclass=PoolMeta):
|
||||
with Transaction().set_context(company=self.company.id):
|
||||
fifo_moves = self.product.get_fifo_move(total_qty)
|
||||
|
||||
cost_price = Decimal("0.0")
|
||||
cost_price = Decimal(0)
|
||||
consumed_qty = 0.0
|
||||
to_save = []
|
||||
for move, move_qty in fifo_moves:
|
||||
|
||||
@@ -468,9 +468,9 @@ class Purchase(
|
||||
|
||||
@fields.depends('lines', 'currency', methods=['get_tax_amount'])
|
||||
def on_change_lines(self):
|
||||
self.untaxed_amount = Decimal('0.0')
|
||||
self.tax_amount = Decimal('0.0')
|
||||
self.total_amount = Decimal('0.0')
|
||||
self.untaxed_amount = Decimal(0)
|
||||
self.tax_amount = Decimal(0)
|
||||
self.total_amount = Decimal(0)
|
||||
if self.lines:
|
||||
for line in self.lines:
|
||||
self.untaxed_amount += getattr(line, 'amount', None) or 0
|
||||
@@ -1533,7 +1533,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
|
||||
if self.type == 'line':
|
||||
return self.on_change_with_amount()
|
||||
elif self.type == 'subtotal':
|
||||
amount = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
for line2 in self.purchase.lines:
|
||||
if line2.type == 'line':
|
||||
amount += line2.purchase.currency.round(
|
||||
@@ -1541,7 +1541,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
|
||||
elif line2.type == 'subtotal':
|
||||
if self == line2:
|
||||
break
|
||||
amount = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
return amount
|
||||
|
||||
@fields.depends('purchase', '_parent_purchase.warehouse')
|
||||
|
||||
@@ -568,8 +568,8 @@ class BlanketAgreementLine(ModelSQL, ModelView):
|
||||
'_parent_blanket_agreement.currency')
|
||||
def on_change_with_amount(self, name=None):
|
||||
amount = (
|
||||
Decimal(str(self.quantity or '0.0'))
|
||||
* (self.unit_price or Decimal('0.0')))
|
||||
Decimal(str(self.quantity or 0))
|
||||
* (self.unit_price or Decimal(0)))
|
||||
|
||||
if self.blanket_agreement and self.blanket_agreement.currency:
|
||||
return self.blanket_agreement.currency.round(amount)
|
||||
|
||||
@@ -234,7 +234,7 @@ class PurchaseRequisition(Workflow, ModelSQL, ModelView):
|
||||
|
||||
@fields.depends('lines', 'currency')
|
||||
def on_change_with_total_amount(self):
|
||||
self.total_amount = Decimal('0.0')
|
||||
self.total_amount = Decimal(0)
|
||||
if self.lines:
|
||||
for line in self.lines:
|
||||
self.total_amount += getattr(line, 'amount', None) or 0
|
||||
|
||||
@@ -528,9 +528,9 @@ class Sale(
|
||||
|
||||
@fields.depends('lines', 'currency', methods=['get_tax_amount'])
|
||||
def on_change_lines(self):
|
||||
self.untaxed_amount = Decimal('0.0')
|
||||
self.tax_amount = Decimal('0.0')
|
||||
self.total_amount = Decimal('0.0')
|
||||
self.untaxed_amount = Decimal(0)
|
||||
self.tax_amount = Decimal(0)
|
||||
self.total_amount = Decimal(0)
|
||||
|
||||
if self.lines:
|
||||
for line in self.lines:
|
||||
@@ -1583,18 +1583,18 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
|
||||
def on_change_with_amount(self):
|
||||
if self.type == 'line':
|
||||
currency = self.sale.currency if self.sale else None
|
||||
amount = Decimal(str(self.quantity or '0.0')) * \
|
||||
(self.unit_price or Decimal('0.0'))
|
||||
amount = Decimal(str(self.quantity or 0)) * \
|
||||
(self.unit_price or Decimal(0))
|
||||
if currency:
|
||||
return currency.round(amount)
|
||||
return amount
|
||||
return Decimal('0.0')
|
||||
return Decimal(0)
|
||||
|
||||
def get_amount(self, name):
|
||||
if self.type == 'line':
|
||||
return self.on_change_with_amount()
|
||||
elif self.type == 'subtotal':
|
||||
amount = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
for line2 in self.sale.lines:
|
||||
if line2.type == 'line':
|
||||
amount += line2.sale.currency.round(
|
||||
@@ -1602,9 +1602,9 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
|
||||
elif line2.type == 'subtotal':
|
||||
if self == line2:
|
||||
break
|
||||
amount = Decimal('0.0')
|
||||
amount = Decimal(0)
|
||||
return amount
|
||||
return Decimal('0.0')
|
||||
return Decimal(0)
|
||||
|
||||
@fields.depends('sale', '_parent_sale.warehouse')
|
||||
def on_change_with_warehouse(self, name=None):
|
||||
|
||||
@@ -521,8 +521,8 @@ class BlanketAgreementLine(ModelSQL, ModelView):
|
||||
'_parent_blanket_agreement.currency')
|
||||
def on_change_with_amount(self, name=None):
|
||||
amount = (
|
||||
Decimal(str(self.quantity or '0.0'))
|
||||
* (self.unit_price or Decimal('0.0')))
|
||||
Decimal(str(self.quantity or 0))
|
||||
* (self.unit_price or Decimal(0)))
|
||||
|
||||
if self.blanket_agreement and self.blanket_agreement.currency:
|
||||
return self.blanket_agreement.currency.round(amount)
|
||||
|
||||
Reference in New Issue
Block a user