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.

64 lines
2.3 KiB

  1. # Copyright 2017 LasLabs Inc.
  2. # Copyright 2018 ACSONE SA/NV.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class ContractLine(models.Model):
  6. _inherit = 'contract.line'
  7. _rec_name = 'display_name'
  8. sale_order_line_id = fields.Many2one(
  9. comodel_name="sale.order.line",
  10. string="Sale Order Line",
  11. required=False,
  12. copy=False,
  13. )
  14. display_name = fields.Char(compute='_compute_display_name_2')
  15. @api.multi
  16. def _prepare_invoice_line(self, invoice_id=False):
  17. res = super(ContractLine, self)._prepare_invoice_line(
  18. invoice_id=invoice_id
  19. )
  20. if self.sale_order_line_id and res:
  21. res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])]
  22. return res
  23. @api.multi
  24. def _get_auto_renew_rule_type(self):
  25. """monthly last day don't make sense for auto_renew_rule_type"""
  26. self.ensure_one()
  27. if self.recurring_rule_type == "monthlylastday":
  28. return "monthly"
  29. return self.recurring_rule_type
  30. @api.onchange('product_id')
  31. def _onchange_product_id_recurring_info(self):
  32. for rec in self:
  33. rec.date_start = fields.Date.today()
  34. if rec.product_id.is_contract:
  35. rec.recurring_rule_type = rec.product_id.recurring_rule_type
  36. rec.recurring_invoicing_type = (
  37. rec.product_id.recurring_invoicing_type
  38. )
  39. rec.recurring_interval = 1
  40. rec.is_auto_renew = rec.product_id.is_auto_renew
  41. rec.auto_renew_interval = rec.product_id.default_qty
  42. rec.auto_renew_rule_type = rec._get_auto_renew_rule_type()
  43. rec.termination_notice_interval = (
  44. rec.product_id.termination_notice_interval
  45. )
  46. rec.termination_notice_rule_type = (
  47. rec.product_id.termination_notice_rule_type
  48. )
  49. @api.depends('name', 'date_start')
  50. def _compute_display_name_2(self):
  51. # FIXME: _compute_display_name depends on rec_name (display_name)
  52. # and this trigger a WARNING : display_name depends on itself;
  53. # please fix its decorator
  54. for rec in self:
  55. rec.display_name = ("%s - %s") % (rec.date_start, rec.name)