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.

27 lines
995 B

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, models
  5. class SaleOrder(models.Model):
  6. _inherit = 'sale.order'
  7. @api.multi
  8. def action_confirm(self):
  9. """ If we have a contract in the order, set it up """
  10. for rec in self:
  11. order_lines = self.mapped('order_line').filtered(
  12. lambda r: r.product_id.is_contract
  13. )
  14. for line in order_lines:
  15. contract_tmpl = line.product_id.contract_template_id
  16. contract = self.env['account.analytic.account'].create({
  17. 'name': '%s Contract' % rec.name,
  18. 'partner_id': rec.partner_id.id,
  19. 'contract_template_id': contract_tmpl.id,
  20. })
  21. line.contract_id = contract.id
  22. contract.recurring_create_invoice()
  23. return super(SaleOrder, self).action_confirm()