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.

48 lines
1.6 KiB

6 years ago
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models, _
  3. from openerp.exceptions import UserError
  4. class PartnerUpdateInfo(models.TransientModel):
  5. _name = "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(string="effective date",
  15. required=True,
  16. default=_get_effective_date)
  17. cooperator = fields.Many2one(related='share_line.partner_id',
  18. string="Cooperator")
  19. share_line = fields.Many2one('share.line',
  20. string="Share line",
  21. default=_get_share_line)
  22. @api.multi
  23. def update(self):
  24. line = self.share_line
  25. cooperator = line.partner_id
  26. sub_reg = self.env['subscription.register'].search(
  27. [('partner_id', '=', cooperator.id),
  28. ('share_product_id', '=', line.share_product_id.id),
  29. ('quantity', '=', line.share_number),
  30. ('date', '=', line.effective_date)])
  31. if sub_reg:
  32. if len(sub_reg) > 1:
  33. raise UserError(_("Error the update return more than one"
  34. " subscription register lines."))
  35. else:
  36. line.effective_date = self.effective_date
  37. sub_reg.date = self.effective_date
  38. return True