Browse Source

[IMP] last dev on the modules.

pull/1/head
houssine 8 years ago
parent
commit
184f0a3b9f
  1. 5
      easy_my_coop_taxshelter_report/models/mail_template.py
  2. 89
      easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py
  3. 26
      easy_my_coop_taxshelter_report/views/tax_shelter_declaration_view.xml

5
easy_my_coop_taxshelter_report/models/mail_template.py

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from openerp import api, fields, models, _
class MailTemplate(models.Model):
"Templates for sending email"
_name = "mail.template"
_inherit = "mail.template"
@api.multi
def send_mail_with_multiple_attachments(self, res_id, additional_attachments, force_send=False, raise_exception=False):

89
easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py

@ -9,7 +9,8 @@ TYPE_MAP = {
'transfer':'transfered',
'sell_back':'resold'
}
REPORT_DIC = {'subscription':('easy_my_coop_taxshelter_report.tax_shelter_subscription_report','Tax Shelter Subscription'),
'shares':('easy_my_coop_taxshelter_report.tax_shelter_shares_report','Tax Shelter Shares')}
class TaxShelterDeclaration(models.Model):
_name = "tax.shelter.declaration"
@ -55,27 +56,28 @@ class TaxShelterDeclaration(models.Model):
certificate = self.env['tax.shelter.certificate'].create(cert_vals)
partner_certificate[entry.partner_id.id] = certificate
line_vals = self._prepare_line(certificate, entry)
self.env['certificate.line'].create(line_vals)
certificate.write({'lines': [(0, 0, line_vals)]})
#self.env['certificate.line'].create(line_vals)
return partner_certificate
@api.one
def compute_declaration(self):
entries = self.env['subscription.register'].search([('date','>=',self.date_from),
partner_certificate = {}
entries = self.env['subscription.register'].search([('partner_id.is_company','=',False),
('date','<=',self.date_to),
('type','=','subscription')])
partner_certificate = self._compute_certificates(entries, partner_certificate = {})
partner_certificate = self._compute_certificates(entries, partner_certificate)
entries = self.env['subscription.register'].search([('date','<=',self.date_to),
entries = self.env['subscription.register'].search([('partner_id.is_company','=',False),
('date','<=',self.date_to),
('type','in',['sell_back','transfer'])])
partner_certificate = self._compute_certificates(entries, partner_certificate)
self.state = 'computed'
@api.one
def generate_attachments(self):
self.tax_shelter_certificates.generate_certificates_report()
self.state = 'computed'
@api.one
def validate_declaration(self):
self.tax_shelter_certificates.write({'state':'validated'})
self.state = 'validated'
@api.one
@ -83,9 +85,7 @@ class TaxShelterDeclaration(models.Model):
if not self.state == 'validated':
certificate_ids = self.tax_shelter_certificates.ids
self.tax_shelter_certificates.unlink()
certificate_attchments = self.env['ir.attachment'].search([('res_model','=','tax.shelter.certificate'),
('res_id','in',certificate_ids)])
certificate_attchments.unlink
self.state = 'draft'
class TaxShelterCertificate(models.Model):
_name = "tax.shelter.certificate"
@ -100,37 +100,42 @@ class TaxShelterCertificate(models.Model):
string='State',required=True, default="draft")
declaration_id = fields.Many2one('tax.shelter.declaration', string='Declaration', required=True, readonly=True)
lines = fields.One2many('certificate.line','tax_shelter_certificate', string='Certificate lines', readonly=True)
previously_subscribed_lines = fields.One2many(compute='_compute_certificate_lines', comodel_name='certificate.line', string='Previously Subscribed lines', readonly=True)
subscribed_lines = fields.One2many(compute='_compute_certificate_lines', comodel_name='certificate.line', string='Shares subscribed', readonly=True)
resold_lines = fields.One2many(compute='_compute_certificate_lines', comodel_name='certificate.line', string='Shares resold', readonly=True)
transfered_lines = fields.One2many(compute='_compute_certificate_lines', comodel_name='certificate.line', string='Shares transfered', readonly=True)
total_amount_previously_subscribed = fields.Float(compute='_compute_amounts', string='Total subscribed')
total_amount_subscribed = fields.Float(compute='_compute_amounts', string='Total subscribed')
total_amount_resold = fields.Float(compute='_compute_amounts', string='Total resold')
total_amount_transfered = fields.Float(compute='_compute_amounts', string='Total transfered')
total_amount = fields.Float(compute='_compute_amounts', string='Total', readonly=True)
company_id = fields.Many2one(related="declaration_id.company_id", string="Company")
def attach_to_certificate(self, report, report_name):
attachment_data = {
'name': report_name,
'datas_fname': report_name,
'datas': report,
'res_model': 'tax.shelter.certificate',
'res_id': self.id,
}
self.env['ir.attachment'].create(attachment_data)
def generate_pdf_report(self,report_type):
report_action, name = REPORT_DIC[report_type]
report = self.env['report'].get_pdf(self, report_action)
report = base64.b64encode(report)
report_name = self.partner_id.name + ' ' + name + ' ' + self.declaration_id.name + '.pdf'
@api.multi
def generate_certificates_report(self):
report_dic = {'easy_my_coop_taxshelter_report.tax_shelter_subscription_report':'Tax Shelter Subscription',
'easy_my_coop_taxshelter_report.tax_shelter_shares_report':'Tax Shelter Shares'}
return (report_name, report)
for certificate in self:
for report_action, name in report_dic.items():
report = self.env['report'].get_pdf(certificate, report_action)
report = base64.b64encode(report)
report_name = certificate.partner_id.name + ' ' + name + ' ' + certificate.declaration_id.name + '.pdf'
def generate_certificates_report(self):
attachments = []
if self.total_amount_subscribed > 0:
if self.total_amount_resold == 0 and self.total_amount_transfered == 0:
attachments.append(self.generate_pdf_report('subscription'))
if self.total_amount_previously_subscribed > 0:
attachments.append(self.generate_pdf_report('shares'))
#if self.total_amount_resold > 0 or self.total_amount_transfered > 0:
# TODO
return attachments
certificate.attach_to_certificate(report, report_name)
@api.one
def send_certificates(self):
attachments = self.generate_certificates_report()
if len(attachments) > 0:
confirmation_mail_template = self.env['mail.template'].search([('name', '=', 'Tax Shelter Certificate - Send By Email')])[0]
confirmation_mail_template.send_mail_with_multiple_attachments(self.id, attachments,True)
@api.multi
def print_subscription_certificate(self):
@ -145,6 +150,7 @@ class TaxShelterCertificate(models.Model):
@api.multi
def _compute_amounts(self):
for certificate in self:
total_amount_previously_subscribed = 0
total_amount_subscribed = 0
total_amount_transfered = 0
total_amount_resold = 0
@ -153,6 +159,10 @@ class TaxShelterCertificate(models.Model):
total_amount_subscribed += line.amount_subscribed
certificate.total_amount_subscribed = total_amount_subscribed
for line in certificate.previously_subscribed_lines:
total_amount_previously_subscribed += line.amount_subscribed
certificate.total_amount_previously_subscribed = total_amount_previously_subscribed
for line in certificate.transfered_lines:
total_amount_transfered += line.amount_transfered
certificate.total_amount_transfered = total_amount_transfered
@ -160,14 +170,23 @@ class TaxShelterCertificate(models.Model):
for line in certificate.resold_lines:
total_amount_resold += line.amount_resold
certificate.total_amount_resold = total_amount_resold
certificate.total_amount = certificate.total_amount_subscribed + certificate.total_amount_resold + certificate.total_amount_transfered
certificate.total_amount = certificate.total_amount_previously_subscribed + certificate.total_amount_subscribed + certificate.total_amount_resold + certificate.total_amount_transfered
@api.multi
def _compute_certificate_lines(self):
for certificate in self:
certificate.subscribed_lines = certificate.lines.filtered(lambda r: r.type == 'subscribed')
certificate.resold_lines = certificate.lines.filtered(lambda r: r.type == 'resold')
certificate.transfered_lines = certificate.lines.filtered(lambda r: r.type == 'transfered')
certificate.previously_subscribed_lines = certificate.lines.filtered(lambda r: r.type == 'subscribed' and r.transaction_date < certificate.declaration_id.date_from)
certificate.subscribed_lines = certificate.lines.filtered(lambda r: r.type == 'subscribed' and r.transaction_date >= certificate.declaration_id.date_from and r.transaction_date <= certificate.declaration_id.date_to)
certificate.resold_lines = certificate.lines.filtered(lambda r: r.type == 'resold' and r.transaction_date >= certificate.declaration_id.date_from and r.transaction_date <= certificate.declaration_id.date_to)
certificate.transfered_lines = certificate.lines.filtered(lambda r: r.type == 'transfered' and r.transaction_date >= certificate.declaration_id.date_from and r.transaction_date <= certificate.declaration_id.date_to)
@api.model
def batch_send_tax_shelter_certificate(self):
certificates = self.search([('state','=','validated')],limit=40)
for certificate in certificates:
certificate.send_certificates()
certificate.state = 'sent'
self.env.cr.commit()
class TaxShelterCertificateLine(models.Model):
_name= "certificate.line"

26
easy_my_coop_taxshelter_report/views/tax_shelter_declaration_view.xml

@ -9,10 +9,9 @@
<field name="arch" type="xml">
<form string="Tax shelter declaration">
<header>
<button name="compute_declaration" string="Process Declaration" type="object" class="oe_highlight" groups="easy_my_coop.group_energiris_manager"/>
<button name="compute_declaration" string="Process Declaration" type="object" states="draft" class="oe_highlight" groups="easy_my_coop.group_energiris_manager"/>
<button name="validate_declaration" string="Validate Declaration" type="object" states="computed" groups="easy_my_coop.group_energiris_manager"/>
<button name="generate_attachments" string="Generate Attachments" type="object" states="computed" groups="easy_my_coop.group_energiris_manager"/>
<button name="reset_declaration" string="Reset Declaration" type="object" groups="easy_my_coop.group_energiris_manager"/>
<button name="reset_declaration" string="Reset Declaration" type="object" states="computed" groups="easy_my_coop.group_energiris_manager"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
@ -38,9 +37,7 @@
<field name="cooperator_number"/>
<field name="total_amount"/>
<field name="state"/>
<button type="object" name="print_subscription_certificate" icon="STOCK_MEDIA_PLAY" />
<button type="object" name="print_shares_certificate" icon="STOCK_MEDIA_PLAY" />
<button type="object" name="generate_certificates_report" icon="STOCK_MEDIA_PLAY" />
<button type="object" name="send_certificates" icon="STOCK_MEDIA_PLAY" string="Send Certificates"/>
</tree>
</field>
</page>
@ -80,6 +77,9 @@
<field name="arch" type="xml">
<form string="Tax shelter certificate">
<header>
<button type="object" name="print_subscription_certificate" string="Print Subscription Certificate" />
<button type="object" name="print_shares_certificate" string="Print Shares Certificate" />
<button type="object" name="send_certificates" string="Send Certificates"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
@ -136,6 +136,19 @@
</tree>
</field>
</page>
<page string="Previously subscribed">
<field name="previously_subscribed_lines">
<tree>
<field name="transaction_date"/>
<field name="share_type"/>
<field name="share_short_name"/>
<field name="quantity"/>
<field name="share_unit_price"/>
<field name="type"/>
<field name="amount_subscribed"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
@ -147,6 +160,7 @@
<field name="model">tax.shelter.certificate</field>
<field name="arch" type="xml">
<tree string="Tax shelter certificates">
<field name="declaration_id"/>
<field name="partner_id"/>
<field name="cooperator_number"/>
<field name="total_amount_subscribed"/>

Loading…
Cancel
Save