Browse Source

[IMP] handle case where the amount subscription is not totally eligible

to the tax shelter
pull/1/head
houssine 7 years ago
parent
commit
8412b05163
  1. 25
      easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py
  2. 3
      easy_my_coop_taxshelter_report/views/tax_shelter_declaration_view.xml

25
easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py

@ -48,7 +48,8 @@ class TaxShelterDeclaration(models.Model):
capital_after_sub = ongoing_capital_sub + entry.total_amount_line capital_after_sub = ongoing_capital_sub + entry.total_amount_line
line_vals['capital_before_sub'] = ongoing_capital_sub line_vals['capital_before_sub'] = ongoing_capital_sub
line_vals['capital_after_sub'] = capital_after_sub line_vals['capital_after_sub'] = capital_after_sub
if capital_after_sub <= self.tax_shelter_capital_limit:
line_vals['capital_limit'] = self.tax_shelter_capital_limit
if ongoing_capital_sub <= self.tax_shelter_capital_limit:
line_vals['tax_shelter'] = True line_vals['tax_shelter'] = True
return line_vals return line_vals
@ -68,7 +69,7 @@ class TaxShelterDeclaration(models.Model):
line_vals = self._prepare_line(certificate, entry, ongoing_capital_sub) line_vals = self._prepare_line(certificate, entry, ongoing_capital_sub)
certificate.write({'lines': [(0, 0, line_vals)]}) certificate.write({'lines': [(0, 0, line_vals)]})
if entry.type == 'subscription' and entry.date >= self.date_from:
#if entry.type == 'subscription' and entry.date >= self.date_from:
ongoing_capital_sub += entry.total_amount_line ongoing_capital_sub += entry.total_amount_line
return partner_certificate return partner_certificate
@ -123,6 +124,7 @@ class TaxShelterCertificate(models.Model):
transfered_lines = fields.One2many(compute='_compute_certificate_lines', comodel_name='certificate.line', string='Shares transfered', 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 previously subscribed') total_amount_previously_subscribed = fields.Float(compute='_compute_amounts', string='Total previously subscribed')
total_amount_subscribed = fields.Float(compute='_compute_amounts', string='Total subscribed') total_amount_subscribed = fields.Float(compute='_compute_amounts', string='Total subscribed')
total_amount_eligible = fields.Float(compute='_compute_amounts', string='Total amount eligible To Tax shelter')
total_amount_resold = fields.Float(compute='_compute_amounts', string='Total resold') total_amount_resold = fields.Float(compute='_compute_amounts', string='Total resold')
total_amount_transfered = fields.Float(compute='_compute_amounts', string='Total transfered') total_amount_transfered = fields.Float(compute='_compute_amounts', string='Total transfered')
total_amount = fields.Float(compute='_compute_amounts', string='Total', readonly=True) total_amount = fields.Float(compute='_compute_amounts', string='Total', readonly=True)
@ -166,9 +168,11 @@ class TaxShelterCertificate(models.Model):
@api.multi @api.multi
def _compute_amounts(self): def _compute_amounts(self):
for certificate in self: for certificate in self:
total_amount_previously_subscribed = 0 total_amount_previously_subscribed = 0
total_amount_subscribed = 0 total_amount_subscribed = 0
total_amount_elligible = 0
total_amount_transfered = 0 total_amount_transfered = 0
total_amount_resold = 0 total_amount_resold = 0
@ -176,6 +180,10 @@ class TaxShelterCertificate(models.Model):
total_amount_subscribed += line.amount_subscribed total_amount_subscribed += line.amount_subscribed
certificate.total_amount_subscribed = total_amount_subscribed certificate.total_amount_subscribed = total_amount_subscribed
for line in certificate.subscribed_lines:
total_amount_elligible += line.amount_subscribed_eligible
certificate.total_amount_eligible = total_amount_elligible
for line in certificate.previously_subscribed_lines: for line in certificate.previously_subscribed_lines:
total_amount_previously_subscribed += line.amount_subscribed total_amount_previously_subscribed += line.amount_subscribed
certificate.total_amount_previously_subscribed = total_amount_previously_subscribed certificate.total_amount_previously_subscribed = total_amount_previously_subscribed
@ -208,29 +216,40 @@ class TaxShelterCertificate(models.Model):
class TaxShelterCertificateLine(models.Model): class TaxShelterCertificateLine(models.Model):
_name= "certificate.line" _name= "certificate.line"
declaration_id = fields.Many2one(related='tax_shelter_certificate.declaration_id', string="Declaration")
tax_shelter_certificate = fields.Many2one('tax.shelter.certificate', string="Tax shelter certificate", ondelete='cascade', required=True) tax_shelter_certificate = fields.Many2one('tax.shelter.certificate', string="Tax shelter certificate", ondelete='cascade', required=True)
share_type = fields.Many2one('product.product', string='Share type', required=True, readonly=True) share_type = fields.Many2one('product.product', string='Share type', required=True, readonly=True)
share_unit_price = fields.Float(string='Share price', required=True, readonly=True) share_unit_price = fields.Float(string='Share price', required=True, readonly=True)
quantity = fields.Integer(string='Number of shares', required=True, readonly=True) quantity = fields.Integer(string='Number of shares', required=True, readonly=True)
transaction_date = fields.Date(string="Transaction date") transaction_date = fields.Date(string="Transaction date")
tax_shelter = fields.Boolean(string="Tax shelter", readonly=True)
tax_shelter = fields.Boolean(string="Tax shelter eligible", readonly=True)
type = fields.Selection([('subscribed','Subscribed'), type = fields.Selection([('subscribed','Subscribed'),
('resold','Resold'), ('resold','Resold'),
('transfered','Transfered'), ('transfered','Transfered'),
('kept','Kept')], required=True, readonly=True) ('kept','Kept')], required=True, readonly=True)
amount_subscribed = fields.Float(compute='_compute_totals', string='Amount subscribed',store=True) amount_subscribed = fields.Float(compute='_compute_totals', string='Amount subscribed',store=True)
amount_subscribed_eligible = fields.Float(compute='_compute_totals', string='Amount subscribed eligible',store=True)
amount_resold = fields.Float(compute='_compute_totals', string='Amount resold',store=True) amount_resold = fields.Float(compute='_compute_totals', string='Amount resold',store=True)
amount_transfered = fields.Float(compute='_compute_totals', string='Amount transfered',store=True) amount_transfered = fields.Float(compute='_compute_totals', string='Amount transfered',store=True)
share_short_name = fields.Char(string='Share type name', readonly=True) share_short_name = fields.Char(string='Share type name', readonly=True)
capital_before_sub = fields.Float(string="Capital before subscription", readonly=True) capital_before_sub = fields.Float(string="Capital before subscription", readonly=True)
capital_after_sub = fields.Float(string="Capital after subscription", readonly=True) capital_after_sub = fields.Float(string="Capital after subscription", readonly=True)
capital_limit = fields.Float(string="Capital limit", readonly=True)
@api.multi @api.multi
@api.depends('quantity','share_unit_price') @api.depends('quantity','share_unit_price')
def _compute_totals(self): def _compute_totals(self):
for line in self: for line in self:
#limit = line.declaration_id.tax_shelter_capital_limit
if line.type == 'subscribed': if line.type == 'subscribed':
line.amount_subscribed = line.share_unit_price * line.quantity line.amount_subscribed = line.share_unit_price * line.quantity
if line.type == 'subscribed' and line.tax_shelter:
if line.capital_before_sub < line.capital_limit and line.capital_after_sub >= line.capital_limit:
line.amount_subscribed_eligible = line.capital_limit - line.capital_before_sub
elif line.capital_before_sub < line.capital_limit and line.capital_after_sub <= line.capital_limit:
line.amount_subscribed_eligible = line.share_unit_price * line.quantity
elif line.capital_before_sub >= line.capital_limit:
line.amount_subscribed_eligible = 0
if line.type == 'resold': if line.type == 'resold':
line.amount_resold = line.share_unit_price * -(line.quantity) line.amount_resold = line.share_unit_price * -(line.quantity)
if line.type == 'transfered': if line.type == 'transfered':

3
easy_my_coop_taxshelter_report/views/tax_shelter_declaration_view.xml

@ -93,6 +93,7 @@
<group> <group>
<field name="total_amount_previously_subscribed"/> <field name="total_amount_previously_subscribed"/>
<field name="total_amount_subscribed"/> <field name="total_amount_subscribed"/>
<field name="total_amount_eligible"/>
<field name="total_amount_resold"/> <field name="total_amount_resold"/>
<field name="total_amount_transfered"/> <field name="total_amount_transfered"/>
<field name="total_amount"/> <field name="total_amount"/>
@ -112,6 +113,7 @@
<field name="share_unit_price"/> <field name="share_unit_price"/>
<field name="type"/> <field name="type"/>
<field name="amount_subscribed"/> <field name="amount_subscribed"/>
<field name="amount_subscribed_eligible"/>
</tree> </tree>
</field> </field>
</page> </page>
@ -172,6 +174,7 @@
<field name="partner_id"/> <field name="partner_id"/>
<field name="cooperator_number"/> <field name="cooperator_number"/>
<field name="total_amount_subscribed"/> <field name="total_amount_subscribed"/>
<field name="total_amount_eligible"/>
<field name="total_amount_resold"/> <field name="total_amount_resold"/>
<field name="total_amount_transfered"/> <field name="total_amount_transfered"/>
<field name="total_amount"/> <field name="total_amount"/>

Loading…
Cancel
Save