Browse Source

[IMP] implement share conversion

pull/1/head
houssine 6 years ago
parent
commit
93fe42f5a5
  1. 4
      easy_my_coop/models/coop.py
  2. 38
      easy_my_coop/models/operation_request.py
  3. 15
      easy_my_coop/view/cooperator_register_view.xml

4
easy_my_coop/models/coop.py

@ -396,6 +396,10 @@ class subscription_register(models.Model):
total_amount_line = fields.Float(compute='_compute_total_line', string='Total amount line')
share_product_id = fields.Many2one('product.product', string='Share type', required=True, readonly=True, domain=[('is_share','=',True)])
share_short_name = fields.Char(related='share_product_id.short_name', string='Share type name', readonly=True)
share_to_product_id = fields.Many2one('product.product', string='Share to type', readonly=True, domain=[('is_share','=',True)])
share_to_short_name = fields.Char(related='share_to_product_id.short_name', string='Share to type name', readonly=True)
quantity_to = fields.Integer(string='Number of share to', readonly=True)
share_to_unit_price = fields.Float(string='Share to price', readonly=True)
type = fields.Selection([('subscription','Subscription'),
('transfer','Transfer'),
('sell_back','Sell Back'),

38
easy_my_coop/models/operation_request.py

@ -29,6 +29,7 @@ class operation_request(models.Model):
share_short_name = fields.Char(related='share_product_id.short_name', string='Share type name')
share_to_short_name = fields.Char(related='share_to_product_id.short_name', string='Share to type name')
share_unit_price = fields.Float(related='share_product_id.list_price', string='Share price')
share_to_unit_price = fields.Float(related='share_to_product_id.list_price', string='Share to price')
subscription_amount = fields.Float(compute='_compute_subscription_amount', string='Operation amount')
quantity = fields.Integer(string='Number of share', required=True)
state = fields.Selection([('draft','Draft'),
@ -123,8 +124,6 @@ class operation_request(models.Model):
def validate(self):
if not self.has_share_type() and self.operation_type in ['sell_back', 'transfer']:
raise ValidationError(_("The cooperator doesn't own this share type. Please choose the appropriate share type."))
if self.state != 'approved':
raise ValidationError(_("This operation must be approved before to be executed"))
if self.operation_type in ['sell_back','convert','transfer']:
total_share_dic = self.get_total_share_dic(self.partner_id)
@ -150,10 +149,20 @@ class operation_request(models.Model):
ir_sequence = self.env['ir.sequence']
sub_request = self.env['subscription.request']
email_template_obj = self.env['mail.template']
for rec in self:
rec.validate()
if rec.state != 'approved':
raise ValidationError(_("This operation must be approved before to be executed"))
values = {
'partner_id':rec.partner_id.id, 'quantity':rec.quantity,
'share_product_id':rec.share_product_id.id, 'type':rec.operation_type,
'share_unit_price': rec.share_unit_price, 'date':effective_date,
}
if rec.operation_type == 'sell_back':
self.hand_share_over(rec.partner_id, rec.share_product_id, rec.quantity)
elif rec.operation_type == 'convert':
@ -167,7 +176,14 @@ class operation_request(models.Model):
line = share_ids[0]
if len(share_ids) > 1:
share_ids[1:len(share_ids)].unlink()
line.write({'share_number':convert_quant, 'share_product_id':rec.share_to_product_id.id})
line.write({
'share_number':convert_quant,
'share_product_id':rec.share_to_product_id.id,
'share_unit_price': rec.share_to_unit_price,
'share_short_name': rec.share_to_short_name
})
values['share_to_product_id'] = rec.share_to_product_id.id
values['quantity_to'] = convert_quant
else:
raise ValidationError(_("Converting just part of the shares is not yet implemented"))
elif rec.operation_type == 'transfer':
@ -194,7 +210,8 @@ class operation_request(models.Model):
'partner_id':rec.partner_id_to.id,
'share_product_id':rec.share_product_id.id,
'share_unit_price':rec.share_unit_price,
'effective_date':effective_date})
'effective_date':effective_date})
values['partner_id_to'] = rec.partner_id_to.id
else:
raise ValidationError(_("This operation is not yet implemented."))
@ -202,16 +219,13 @@ class operation_request(models.Model):
sequence_operation = self.env.ref('easy_my_coop.sequence_register_operation', False)
sub_reg_operation = sequence_operation.next_by_id()
values = {'name':sub_reg_operation,'register_number_operation':int(sub_reg_operation),
'partner_id':rec.partner_id.id, 'quantity':rec.quantity,
'share_product_id':rec.share_product_id.id, 'type':rec.operation_type,
'share_unit_price': rec.share_unit_price, 'date':effective_date,
}
values['name'] = sub_reg_operation
values['register_number_operation'] = int(sub_reg_operation)
rec.write({'state':'done'})
# send mail and to the receiver
if rec.operation_type == 'transfer':
values['partner_id_to'] = rec.partner_id_to.id
certificat_email_template = self.env.ref('easy_my_coop.email_template_share_transfer', False)
certificat_email_template.send_mail(rec.partner_id_to.id, False)

15
easy_my_coop/view/cooperator_register_view.xml

@ -26,17 +26,20 @@
<group>
<field name="register_number_operation"/>
<field name="date"/>
<field name="share_short_name"/>
<field name="partner_id"/>
<field name="partner_id_to" attrs="{'invisible':[('type','!=','transfer')]}"/>
<field name="user_id" invisible="True"/>
</group>
<group>
<field name="type"/>
<field name="share_short_name"/>
<field name="quantity"/>
<field name="share_unit_price"/>
<field name="total_amount_line"/>
</group>
<group>
<field name="partner_id_to" attrs="{'invisible':[('type','!=','transfer')]}"/>
<field name="type"/>
<field name="share_to_short_name"/>
<field name="quantity_to"/>
<field name="share_to_unit_price"/>
<field name="user_id" invisible="True"/>
</group>
</group>
</form>
</field>

Loading…
Cancel
Save