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.

43 lines
1.3 KiB

5 years ago
5 years ago
  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. qty_type = fields.Selection(
  9. selection=[
  10. ('fixed', 'Fixed quantity'),
  11. ('variable', 'Variable quantity'),
  12. ],
  13. required=False,
  14. default='fixed',
  15. string="Qty. type",
  16. )
  17. qty_formula_id = fields.Many2one(
  18. comodel_name="contract.line.qty.formula", string="Qty. formula"
  19. )
  20. @api.onchange('product_id')
  21. def onchange_product(self):
  22. res = super(SaleOrderLine, self).onchange_product()
  23. for rec in self:
  24. if rec.product_id.is_contract:
  25. rec.qty_type = rec.product_id.qty_type
  26. rec.qty_formula_id = rec.product_id.qty_formula_id
  27. return res
  28. @api.multi
  29. def _prepare_contract_line_values(
  30. self, contract, predecessor_contract_line=False
  31. ):
  32. values = super(SaleOrderLine, self)._prepare_contract_line_values(
  33. contract, predecessor_contract_line
  34. )
  35. values['qty_type'] = self.qty_type
  36. values['qty_formula_id'] = self.qty_formula_id.id
  37. return values