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.

50 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, api, fields
  3. class PurchaseOrder(models.Model):
  4. _inherit = "purchase.order"
  5. manual_date_planned = fields.Datetime(
  6. string="Scheduled Date", required=True
  7. )
  8. def init(self,cr):
  9. cr.execute(
  10. """
  11. UPDATE purchase_order
  12. SET manual_date_planned = (SELECT date_planned
  13. FROM purchase_order_line
  14. WHERE purchase_order_line.order_id = purchase_order.id
  15. AND purchase_order_line.date_planned IS NOT NULL
  16. LIMIT 1)
  17. """
  18. )
  19. cr.execute(
  20. """
  21. ALTER TABLE purchase_order ALTER COLUMN manual_date_planned SET NOT NULL
  22. """
  23. )
  24. @api.onchange("order_line", "order_line.date_planned")
  25. def _on_change_manual_date_planned(self):
  26. """
  27. Since we don't see the date planned on the line anymore
  28. give an idea of the user by setting the first date planned of the lines
  29. """
  30. for line in self.order_line:
  31. if line.date_planned and not self.manual_date_planned:
  32. self.manual_date_planned = line.date_planned
  33. break
  34. @api.multi
  35. def button_confirm(self):
  36. """
  37. Since we hide the button to set the date planned on all line and we
  38. hide them, we call the method to set the date planned on the line at the confirmation
  39. """
  40. self.ensure_one()
  41. self.with_context(
  42. date_planned=self.manual_date_planned
  43. ).action_set_date_planned()
  44. return super(PurchaseOrder, self).button_confirm()