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.

57 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # Copyright 2017 ACSONE SA/NV.
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import api, fields, models
  6. class SaleOrderLine(models.Model):
  7. _inherit = 'sale.order.line'
  8. is_contract = fields.Boolean(
  9. string='Is a contract', related="product_id.is_contract"
  10. )
  11. contract_id = fields.Many2one(
  12. comodel_name='account.analytic.account', string='Contract'
  13. )
  14. recurring_rule_type = fields.Selection(
  15. [
  16. ('daily', 'Day(s)'),
  17. ('weekly', 'Week(s)'),
  18. ('monthly', 'Month(s)'),
  19. ('monthlylastday', 'Month(s) last day'),
  20. ('yearly', 'Year(s)'),
  21. ],
  22. default='monthly',
  23. string='Recurrence',
  24. help="Specify Interval for automatic invoice generation.",
  25. copy=False,
  26. )
  27. recurring_invoicing_type = fields.Selection(
  28. [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')],
  29. default='pre-paid',
  30. string='Invoicing type',
  31. help="Specify if process date is 'from' or 'to' invoicing date",
  32. copy=False,
  33. )
  34. recurring_interval = fields.Integer(
  35. default=1,
  36. string='Repeat Every',
  37. help="Repeat every (Days/Week/Month/Year)",
  38. copy=False,
  39. )
  40. date_start = fields.Date(string='Date Start', default=fields.Date.today())
  41. date_end = fields.Date(string='Date End', index=True)
  42. recurring_next_date = fields.Date(
  43. default=fields.Date.today(), copy=False, string='Date of Next Invoice'
  44. )
  45. @api.onchange('product_id')
  46. def onchange_product(self):
  47. if self.product_id.is_contract:
  48. self.recurring_rule_type = self.product_id.recurring_rule_type
  49. self.recurring_invoicing_type = (
  50. self.product_id.recurring_invoicing_type
  51. )
  52. self.recurring_interval = self.product_id.recurring_interval