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.

85 lines
4.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. from openerp import api, fields, models, _
  4. class account_invoice(models.Model):
  5. _inherit = 'account.invoice'
  6. subscription_request = fields.Many2one('subscription.request', string='Subscription request')
  7. release_capital_request = fields.Boolean(string='Release of capital request')
  8. @api.model
  9. def _prepare_refund(self, invoice, date_invoice=None, date=None, description=None, journal_id=None):
  10. values = super(account_invoice, self)._prepare_refund(invoice, date_invoice, date, description, journal_id)
  11. values['release_capital_request'] = self.release_capital_request
  12. return values
  13. def set_cooperator_effective(self, effective_date):
  14. # flag the partner as a effective member
  15. obj_sequence = self.env['ir.sequence']
  16. mail_template_name = 'Payment Received Confirmation - Send By Email'
  17. # if not yet cooperator we generate a cooperator number
  18. if self.partner_id.member == False and self.partner_id.old_number == False:
  19. sequence_id = obj_sequence.search([('name','=','Subscription Register')])[0]
  20. sub_reg_num = sequence_id.next_by_id()
  21. self.partner_id.write({'member':True,'old_member':False,
  22. 'cooperator_register_number':int(sub_reg_num)})
  23. else:
  24. mail_template_name = 'Share Increase - Payment Received Confirmation - Send By Email'
  25. sequence_operation = obj_sequence.search([('name','=','Register Operation')])[0]
  26. sub_reg_operation = sequence_operation.next_by_id()
  27. for line in self.invoice_line_ids:
  28. sub_reg = self.env['subscription.register'].create(
  29. {'name':sub_reg_operation,
  30. 'register_number_operation':int(sub_reg_operation),
  31. 'partner_id':self.partner_id.id,
  32. 'quantity':line.quantity,
  33. 'share_product_id':line.product_id.id,
  34. 'share_unit_price':line.price_unit,
  35. 'date':effective_date,
  36. 'type':'subscription'})
  37. self.env['share.line'].create({'share_number':line.quantity,
  38. 'share_product_id':line.product_id.id,
  39. 'partner_id':self.partner_id.id,
  40. 'share_unit_price':line.price_unit,
  41. 'effective_date':effective_date})
  42. email_template_obj = self.env['mail.template']
  43. certificat_email_template = email_template_obj.search([('name', '=', mail_template_name)])[0]
  44. # we send the email with the certificat in attachment
  45. certificat_email_template.send_mail(self.partner_id.id, False)
  46. return True
  47. def post_process_confirm_paid(self, effective_date):
  48. self.set_cooperator_effective(effective_date)
  49. return True
  50. @api.multi
  51. def confirm_paid(self):
  52. for invoice in self:
  53. super(account_invoice, invoice).confirm_paid()
  54. if invoice.partner_id.cooperator and invoice.release_capital_request and invoice.type == 'out_invoice':
  55. effective_date = datetime.now().strftime("%d/%m/%Y")
  56. #take the effective date from the payment. by default the confirmation date is the payment date
  57. if invoice.payment_move_line_ids :
  58. move_line = invoice.payment_move_line_ids[0]
  59. effective_date = move_line.date
  60. invoice.subscription_request.state = 'paid'
  61. invoice.post_process_confirm_paid(effective_date)
  62. return True
  63. @api.multi
  64. def invoice_print(self):
  65. """ Print the invoice and mark it as sent, so that we can see more
  66. easily the next step of the workflow
  67. """
  68. self.ensure_one()
  69. self.sent = True
  70. return self.env['report'].get_action(self, 'easy_my_coop.report_sexy_invoice')