You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import api, exceptions, fields, models, _
  5. class SaleOrder(models.Model):
  6. _inherit = 'sale.order'
  7. invoice_amount = fields.Monetary(
  8. compute='_compute_invoice_amount', store=True)
  9. invoice_pending_amount = fields.Monetary(
  10. compute='_compute_invoice_amount', store=True)
  11. @api.multi
  12. @api.depends('state', 'order_line.invoice_lines.invoice_id.amount_total')
  13. def _compute_invoice_amount(self):
  14. for order in self.filtered(lambda x: x.state == 'sale'):
  15. order.invoice_amount = sum(
  16. order.invoice_ids.mapped('amount_total'))
  17. order.invoice_pending_amount = (
  18. order.amount_total - order.invoice_amount)
  19. @api.multi
  20. def action_confirm(self):
  21. partner = self.partner_id
  22. if partner.risk_exception:
  23. raise exceptions.Warning(_(
  24. "Financial risk exceeded.\n"
  25. "You can not confirm this sale order"
  26. ))
  27. elif partner.risk_sale_order_include and (
  28. (partner.risk_total + self.amount_total) >
  29. partner.credit_limit):
  30. raise exceptions.Warning(_(
  31. "This sale order exceeds the financial risk.\n"
  32. "You can not confirm this sale order"
  33. ))
  34. return super(SaleOrder, self).action_confirm()