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.

46 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. @api.model
  6. def _get_share_line(self):
  7. active_id = self.env.context.get('active_id')
  8. return self.env['share.line'].browse(active_id)
  9. @api.model
  10. def _get_effective_date(self):
  11. share_line = self._get_share_line()
  12. return share_line.effective_date
  13. effective_date = fields.Date(string="effective date",
  14. required=True,
  15. default=_get_effective_date)
  16. cooperator = fields.Many2one(related='share_line.partner_id',
  17. string="Cooperator")
  18. share_line = fields.Many2one('share.line',
  19. string="Share line",
  20. default=_get_share_line)
  21. @api.multi
  22. def update(self):
  23. line = self.share_line
  24. cooperator = line.partner_id
  25. sub_reg = self.env['subscription.register'].search(
  26. [('partner_id', '=', cooperator.id),
  27. ('share_product_id', '=', line.share_product_id.id),
  28. ('quantity', '=', line.share_number),
  29. ('date', '=', line.effective_date)])
  30. if sub_reg:
  31. if len(sub_reg) > 1:
  32. raise UserError(_("Error the update return more than one"
  33. " subscription register lines."))
  34. else:
  35. line.effective_date = self.effective_date
  36. sub_reg.date = self.effective_date
  37. return True