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.

77 lines
2.5 KiB

  1. # Copyright 2019 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. from odoo.addons import decimal_precision as dp
  5. class ContractLineForecastPeriod(models.Model):
  6. _name = "contract.line.forecast.period"
  7. _description = "Contract Line Forecast Period"
  8. _order = "date_invoice, sequence"
  9. name = fields.Char(string="Name", required=True, readonly=True)
  10. sequence = fields.Integer(
  11. string="Sequence", related="contract_line_id.sequence", store=True
  12. )
  13. contract_id = fields.Many2one(
  14. comodel_name="contract.contract",
  15. string="Contract",
  16. required=True,
  17. readonly=True,
  18. ondelete="cascade",
  19. related="contract_line_id.contract_id",
  20. store=True,
  21. index=True,
  22. )
  23. contract_line_id = fields.Many2one(
  24. comodel_name="contract.line",
  25. string="Contract Line",
  26. required=True,
  27. readonly=True,
  28. ondelete="cascade",
  29. index=True,
  30. )
  31. product_id = fields.Many2one(
  32. comodel_name="product.product",
  33. string="Product",
  34. required=True,
  35. readonly=True,
  36. related="contract_line_id.product_id",
  37. store=True,
  38. index=True,
  39. )
  40. date_start = fields.Date(string="Date Start", required=True, readonly=True)
  41. date_end = fields.Date(string="Date End", required=True, readonly=True)
  42. date_invoice = fields.Date(
  43. string="Invoice Date", required=True, readonly=True
  44. )
  45. quantity = fields.Float(default=1.0, required=True)
  46. price_unit = fields.Float(string='Unit Price')
  47. price_subtotal = fields.Float(
  48. digits=dp.get_precision("Account"),
  49. string="Amount Untaxed",
  50. compute='_compute_price_subtotal',
  51. store=True
  52. )
  53. discount = fields.Float(
  54. string='Discount (%)',
  55. digits=dp.get_precision('Discount'),
  56. help='Discount that is applied in generated invoices.'
  57. ' It should be less or equal to 100',
  58. )
  59. company_id = fields.Many2one(comodel_name="res.company", string="Company")
  60. @api.multi
  61. @api.depends('quantity', 'price_unit', 'discount')
  62. def _compute_price_subtotal(self):
  63. for line in self:
  64. subtotal = line.quantity * line.price_unit
  65. discount = line.discount / 100
  66. subtotal *= 1 - discount
  67. if line.contract_id.pricelist_id:
  68. cur = line.contract_id.pricelist_id.currency_id
  69. line.price_subtotal = cur.round(subtotal)
  70. else:
  71. line.price_subtotal = subtotal