Browse Source

[IMP] finished all the calculation processing. still in wip

pull/1/head
houssine 8 years ago
parent
commit
c7c46979d8
  1. 121
      easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py
  2. 50
      easy_my_coop_taxshelter_report/views/tax_shelter_declaration_view.xml

121
easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py

@ -3,45 +3,138 @@ from datetime import datetime
from openerp import api, fields, models, _ from openerp import api, fields, models, _
class TaxShelterCertificate(models.Model):
TYPE_MAP = {
'subscription':'subscribed',
'transfer':'transfered',
'sell_back':'resold'
}
class TaxShelterDeclaration(models.Model):
_name = "tax.shelter.declaration" _name = "tax.shelter.declaration"
declaration_year = fields.Integer(string='Declaration year', required=True)
name = fields.Char(string='Declaration year', required=True)
tax_shelter_certificates = fields.One2many('tax.shelter.certificate','declaration_id', string='Tax shelter certificates', readonly=True) tax_shelter_certificates = fields.One2many('tax.shelter.certificate','declaration_id', string='Tax shelter certificates', readonly=True)
date_from = fields.Date(string='Date from', required=True) date_from = fields.Date(string='Date from', required=True)
date_to = fields.Date(string='Date to', required=True) date_to = fields.Date(string='Date to', required=True)
tax_shelter_percentage = fields.Selection([('30','30%'), tax_shelter_percentage = fields.Selection([('30','30%'),
('45','45%')], ('45','45%')],
string='Tax Shelter percentage', required=True) string='Tax Shelter percentage', required=True)
state = fields.Selection([('draft','Draft'),
('computed','Computed'),
('validated','Validated')],
string='State',required=True, default="draft")
def _prepare_line(self, certificate, entry):
line_vals = {}
line_vals['tax_shelter_certificate'] = certificate.id
line_vals['share_type'] = entry.share_product_id.id
line_vals['share_short_name'] = entry.share_short_name
line_vals['share_unit_price'] = entry.share_unit_price
line_vals['quantity'] = entry.quantity
line_vals['transaction_date'] = entry.date
line_vals['type'] = TYPE_MAP[entry.type]
return line_vals
@api.one
def compute_declaration(self):
entries = self.env['subscription.register'].search([('date','>=',self.date_from),
('date','<=',self.date_to),
('type','in',['subscription','sell_back','transfer'])])
partner_certificate = {}
for entry in entries:
certificate = partner_certificate.get(entry.partner_id.id, False)
if not certificate:
#create a certificate for this cooperator
cert_vals={}
cert_vals['declaration_id'] = self.id
cert_vals['partner_id'] = entry.partner_id.id
cert_vals['cooperator_number'] = entry.partner_id.cooperator_register_number
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)
@api.one
def validate_declaration(self):
self.state = 'validated'
@api.one @api.one
def process_declaration(self):
True
def reset_declaration(self):
if not self.state == 'validated':
self.tax_shelter_certificates.unlink()
class TaxShelterCertificate(models.Model): class TaxShelterCertificate(models.Model):
_name = "tax.shelter.certificate" _name = "tax.shelter.certificate"
_order = "cooperator_number asc"
cooperator_number = fields.Integer(string='Cooperator number', required=True, readonly=True)
partner_id = fields.Many2one('res.partner', string='Cooperator', required=True, readonly=True) partner_id = fields.Many2one('res.partner', string='Cooperator', required=True, readonly=True)
state = fields.Selection([('draft','Draft'),
('validated','Validated'),
('sent','Sent')],
string='State',required=True, default="draft")
declaration_id = fields.Many2one('tax.shelter.declaration', string='Declaration', required=True, readonly=True) declaration_id = fields.Many2one('tax.shelter.declaration', string='Declaration', required=True, readonly=True)
subscribed_lines = fields.One2many('certificate.line','tax_shelter_certificate', string='Certificate lines', readonly=True)
sell_back_lines = fields.One2many('certificate.line','tax_shelter_certificate', string='Shares resold', readonly=True)
total = fields.Float(string='Total')
lines = fields.One2many('certificate.line','tax_shelter_certificate', string='Certificate 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_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)
@api.multi
def _compute_amounts(self):
total_amount_subscribed = 0
total_amount_transfered = 0
total_amount_resold = 0
for certificate in self:
for line in certificate.subscribed_lines:
total_amount_subscribed += line.amount_subscribed
certificate.total_amount_subscribed = total_amount_subscribed
for line in certificate.transfered_lines:
total_amount_transfered += line.amount_transfered
certificate.total_amount_transfered = total_amount_transfered
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
@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')
class TaxShelterCertificateLine(models.Model): class TaxShelterCertificateLine(models.Model):
_name="certificate.line" _name="certificate.line"
tax_shelter_certificate = fields.Many2one('tax.shelter.certificate', string="Tax shelter certificate",required=True)
share_type = fields.Many2one('product.produt', string='Share type', required=True, readonly=True)
share_price = fields.Float(string='Share price', required=True, readonly=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_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")
certificat_type = fields.Selection([('subscribed','Subscribed'),
type = fields.Selection([('subscribed','Subscribed'),
('resold','Resold'), ('resold','Resold'),
('transfered','Transfered'),
('kept','Kept')], required=True, readonly=True) ('kept','Kept')], required=True, readonly=True)
total = fields.Float(compute='_compute_total', string='Sub total')
amount_subscribed = fields.Float(compute='_compute_totals', string='Amount subscribed',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)
share_short_name = fields.Char(string='Share type name', readonly=True)
@api.multi @api.multi
def _compute_total(self):
@api.depends('quantity','share_unit_price')
def _compute_totals(self):
for line in self: for line in self:
total = line.share_price * line.quantity
if line.type == 'subscribed':
line.amount_subscribed = line.share_unit_price * line.quantity
if line.type == 'resold':
line.amount_resold = line.share_unit_price * -(line.quantity)
if line.type == 'transfered':
line.amount_transfered = line.share_unit_price * -(line.quantity)

50
easy_my_coop_taxshelter_report/views/tax_shelter_declaration_view.xml

@ -10,11 +10,14 @@
<form string="Tax shelter declaration"> <form string="Tax shelter declaration">
<header> <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" class="oe_highlight" groups="easy_my_coop.group_energiris_manager"/>
<button name="validate_declaration" string="Validate Declaration" type="object" states="computed" class="oe_highlight" groups="easy_my_coop.group_energiris_manager"/>
<button name="reset_declaration" string="Reset Declaration" type="object" groups="easy_my_coop.group_energiris_manager"/>
<field name="state" widget="statusbar"/>
</header> </header>
<sheet> <sheet>
<group> <group>
<group> <group>
<field name="declaration_year"/>
<field name="name"/>
<field name="tax_shelter_percentage"/> <field name="tax_shelter_percentage"/>
</group> </group>
<group> <group>
@ -27,7 +30,9 @@
<field name="tax_shelter_certificates"> <field name="tax_shelter_certificates">
<tree> <tree>
<field name="partner_id"/> <field name="partner_id"/>
<field name="total"/>
<field name="cooperator_number"/>
<field name="total_amount"/>
<field name="state"/>
</tree> </tree>
</field> </field>
</page> </page>
@ -42,7 +47,7 @@
<field name="model">tax.shelter.declaration</field> <field name="model">tax.shelter.declaration</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Tax shelter declaration"> <tree string="Tax shelter declaration">
<field name="declaration_year"/>
<field name="name"/>
<field name="date_from"/> <field name="date_from"/>
<field name="date_to"/> <field name="date_to"/>
<field name="tax_shelter_percentage"/> <field name="tax_shelter_percentage"/>
@ -65,39 +70,60 @@
<field name="model">tax.shelter.certificate</field> <field name="model">tax.shelter.certificate</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Tax shelter certificate"> <form string="Tax shelter certificate">
<header>
<field name="state" widget="statusbar"/>
</header>
<sheet> <sheet>
<group> <group>
<group> <group>
<field name="cooperator_number"/>
<field name="partner_id"/> <field name="partner_id"/>
<field name="declaration_id"/> <field name="declaration_id"/>
</group> </group>
<group> <group>
<field name="total"/>
<field name="total_amount_subscribed"/>
<field name="total_amount_resold"/>
<field name="total_amount_transfered"/>
<field name="total_amount"/>
</group> </group>
</group> </group>
<notebook> <notebook>
<page string="Subscription"> <page string="Subscription">
<field name="subscribed_lines"> <field name="subscribed_lines">
<tree> <tree>
<field name="transaction_date"/> <field name="transaction_date"/>
<field name="share_type"/> <field name="share_type"/>
<field name="share_short_name"/>
<field name="quantity"/> <field name="quantity"/>
<field name="share_price"/>
<field name="certificat_type"/>
<field name="total"/>
<field name="share_unit_price"/>
<field name="type"/>
<field name="amount_subscribed"/>
</tree> </tree>
</field> </field>
</page> </page>
<page string="Sell back"> <page string="Sell back">
<field name="sell_back_lines">
<field name="resold_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_resold"/>
</tree>
</field>
</page>
<page string="Transfered">
<field name="transfered_lines">
<tree> <tree>
<field name="transaction_date"/> <field name="transaction_date"/>
<field name="share_type"/> <field name="share_type"/>
<field name="share_short_name"/>
<field name="quantity"/> <field name="quantity"/>
<field name="share_price"/>
<field name="certificat_type"/>
<field name="total"/>
<field name="share_unit_price"/>
<field name="type"/>
<field name="amount_transfered"/>
</tree> </tree>
</field> </field>
</page> </page>

Loading…
Cancel
Save