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.

56 lines
1.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. from odoo import _, api, fields, models
  2. class StockPicking(models.Model):
  3. _inherit = "stock.picking"
  4. max_shipping_date = fields.Datetime("End Shipping Date")
  5. responsible = fields.Many2one(
  6. "res.partner",
  7. string="Responsible",
  8. default=lambda self: self.env.user.partner_id.id,
  9. )
  10. def _add_follower(self):
  11. if self.responsible:
  12. types = self.env["mail.message.subtype"].search(
  13. [
  14. "|",
  15. ("res_model", "=", "stock.picking"),
  16. ("name", "=", "Discussions"),
  17. ]
  18. )
  19. if not self.env["mail.followers"].search(
  20. [
  21. ("res_id", "=", self.id),
  22. ("res_model", "=", "stock.picking"),
  23. ("partner_id", "=", self.responsible.id),
  24. ]
  25. ):
  26. self.env["mail.followers"].create(
  27. {
  28. "res_model": "stock.picking",
  29. "res_id": self.id,
  30. "partner_id": self.responsible.id,
  31. "subtype_ids": [(6, 0, types.ids)],
  32. }
  33. )
  34. @api.multi
  35. def write(self, values):
  36. res = super(StockPicking, self).write(values)
  37. self._add_follower()
  38. return res
  39. @api.model
  40. def create(self, values):
  41. picking = super(StockPicking, self).create(values)
  42. picking._add_follower()
  43. return picking
  44. @api.multi
  45. def copy_qty(self):
  46. self.ensure_one()
  47. for move_line in self.move_line_ids:
  48. move_line.qty_done = move_line.product_qty
  49. return True