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.

53 lines
1.9 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. sale_order_line_id = fields.Many2one(
  7. comodel_name="sale.order.line",
  8. string="Sale Order Line",
  9. required=False,
  10. copy=False,
  11. )
  12. @api.multi
  13. def _prepare_invoice_line(self, invoice_id=False):
  14. res = super(AccountAnalyticInvoiceLine, self)._prepare_invoice_line(
  15. invoice_id=invoice_id
  16. )
  17. if self.sale_order_line_id and res:
  18. res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])]
  19. return res
  20. @api.multi
  21. def _get_auto_renew_rule_type(self):
  22. """monthly last day don't make sense for auto_renew_rule_type"""
  23. self.ensure_one()
  24. if self.recurring_rule_type == "monthlylastday":
  25. return "monthly"
  26. return self.recurring_rule_type
  27. @api.onchange('product_id')
  28. def _onchange_product_id_recurring_info(self):
  29. for rec in self:
  30. rec.date_start = fields.Date.today()
  31. if rec.product_id.is_contract:
  32. rec.recurring_rule_type = rec.product_id.recurring_rule_type
  33. rec.recurring_invoicing_type = (
  34. rec.product_id.recurring_invoicing_type
  35. )
  36. rec.recurring_interval = 1
  37. rec.is_auto_renew = rec.product_id.is_auto_renew
  38. rec.auto_renew_interval = rec.product_id.default_qty
  39. rec.auto_renew_rule_type = rec._get_auto_renew_rule_type()
  40. rec.termination_notice_interval = (
  41. rec.product_id.termination_notice_interval
  42. )
  43. rec.termination_notice_rule_type = (
  44. rec.product_id.termination_notice_rule_type
  45. )