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.

62 lines
2.0 KiB

  1. # Copyright 2016 Tecnativa - Pedro M. Baeza
  2. # Copyright 2018 Tecnativa - Carlos Dauden
  3. # Copyright 2018 ACSONE SA/NV
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import api, models
  6. from odoo.tools import float_is_zero
  7. from odoo.tools.safe_eval import safe_eval
  8. class AccountAnalyticInvoiceLine(models.Model):
  9. _inherit = 'contract.line'
  10. @api.multi
  11. def _get_quantity_to_invoice(
  12. self, period_first_date, period_last_date, invoice_date
  13. ):
  14. quantity = super(
  15. AccountAnalyticInvoiceLine, self
  16. )._get_quantity_to_invoice(
  17. period_first_date, period_last_date, invoice_date
  18. )
  19. if not period_first_date or not period_last_date or not invoice_date:
  20. return quantity
  21. if self.qty_type == 'variable':
  22. eval_context = {
  23. 'env': self.env,
  24. 'context': self.env.context,
  25. 'user': self.env.user,
  26. 'line': self,
  27. 'quantity': quantity,
  28. 'period_first_date': period_first_date,
  29. 'period_last_date': period_last_date,
  30. 'invoice_date': invoice_date,
  31. 'contract': self.contract_id,
  32. }
  33. safe_eval(
  34. self.qty_formula_id.code.strip(),
  35. eval_context,
  36. mode="exec",
  37. nocopy=True,
  38. ) # nocopy for returning result
  39. quantity = eval_context.get('result', 0)
  40. return quantity
  41. @api.multi
  42. def _prepare_invoice_line(self, invoice_id=False):
  43. vals = super(AccountAnalyticInvoiceLine, self)._prepare_invoice_line(
  44. invoice_id=invoice_id
  45. )
  46. if (
  47. 'quantity' in vals
  48. and self.contract_id.skip_zero_qty
  49. and float_is_zero(
  50. vals['quantity'],
  51. self.env['decimal.precision'].precision_get(
  52. 'Product Unit of Measure'
  53. ),
  54. )
  55. ):
  56. vals = {}
  57. return vals