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.

62 lines
2.3 KiB

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