diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 9127d64cad3..c7bcf7a635d 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -529,7 +529,7 @@ class account_invoice(osv.osv): if company_id and type: if type in ('out_invoice'): journal_type = 'sale' - elif type in ('out_refund'): + elif type in ('out_refund'): journal_type = 'sale_refund' elif type in ('in_refund'): journal_type = 'purchase_refund' @@ -802,6 +802,17 @@ class account_invoice(osv.osv): if inv.type in ('in_invoice', 'in_refund') and abs(inv.check_total - inv.amount_total) >= (inv.currency_id.rounding/2.0): raise osv.except_osv(_('Bad total !'), _('Please verify the price of the invoice !\nThe real total does not match the computed total.')) + if inv.payment_term: + total_fixed = total_percent = 0 + for line in inv.payment_term.line_ids: + if line.value == 'fixed': + total_fixed += line.value_amount + if line.value == 'procent': + total_percent += line.value_amount + total_fixed = (total_fixed * 100) / inv.amount_total + if (total_fixed + total_percent) > 100: + raise osv.except_osv(_('Error !'), _("You cannot create an invoice !\nAs you have defined payment term and so the total of invoice should be greater than the computed amount for journal entries using payment term")) + # one move line per tax line iml += ait_obj.move_line_get(cr, uid, inv.id) @@ -912,7 +923,6 @@ class account_invoice(osv.osv): # account move reference when creating the same invoice after a cancelled one: self.pool.get('account.move').post(cr, uid, [move_id], context={'invoice':inv}) self._log_event(cr, uid, ids) - return True def line_get_convert(self, cr, uid, x, part, date, context=None):