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.

55 lines
1.6 KiB

  1. from odoo import _, api, fields, models
  2. from odoo.exceptions import UserError
  3. class ShareLineUpdateInfo(models.TransientModel):
  4. _name = "share.line.update.info"
  5. _description = "Share line update info"
  6. @api.model
  7. def _get_share_line(self):
  8. active_id = self.env.context.get("active_id")
  9. return self.env["share.line"].browse(active_id)
  10. @api.model
  11. def _get_effective_date(self):
  12. share_line = self._get_share_line()
  13. return share_line.effective_date
  14. effective_date = fields.Date(
  15. string="effective date", required=True, default=_get_effective_date
  16. )
  17. cooperator = fields.Many2one(
  18. related="share_line.partner_id", string="Cooperator"
  19. )
  20. share_line = fields.Many2one(
  21. "share.line", string="Share line", default=_get_share_line
  22. )
  23. @api.multi
  24. def update(self):
  25. line = self.share_line
  26. cooperator = line.partner_id
  27. sub_reg = self.env["subscription.register"].search(
  28. [
  29. ("partner_id", "=", cooperator.id),
  30. ("share_product_id", "=", line.share_product_id.id),
  31. ("quantity", "=", line.share_number),
  32. ("date", "=", line.effective_date),
  33. ]
  34. )
  35. if sub_reg:
  36. if len(sub_reg) > 1:
  37. raise UserError(
  38. _(
  39. "Error the update return more than one"
  40. " subscription register lines."
  41. )
  42. )
  43. else:
  44. line.effective_date = self.effective_date
  45. sub_reg.date = self.effective_date
  46. return True