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.

45 lines
1.6 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.onchange('product_id')
  21. def _onchange_product_id_recurring_info(self):
  22. for rec in self:
  23. rec.date_start = fields.Date.today()
  24. if rec.product_id.is_contract:
  25. rec.recurring_rule_type = rec.product_id.recurring_rule_type
  26. rec.recurring_invoicing_type = (
  27. rec.product_id.recurring_invoicing_type
  28. )
  29. rec.recurring_interval = 1
  30. rec.is_auto_renew = rec.product_id.is_auto_renew
  31. rec.auto_renew_interval = rec.product_id.default_qty
  32. rec.auto_renew_rule_type = rec.product_id.recurring_rule_type
  33. rec.termination_notice_interval = (
  34. rec.product_id.termination_notice_interval
  35. )
  36. rec.termination_notice_rule_type = (
  37. rec.product_id.termination_notice_rule_type
  38. )