Browse Source

Merge pull request #67 from coopiteasy/12.0-fix-share-transaction

[FIX] emc: share transaction: product type and send functions
pull/74/head
Manuel Claeys Bouuaert 5 years ago
committed by GitHub
parent
commit
ffd0cf10b1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 179
      easy_my_coop/models/operation_request.py
  2. 1
      easy_my_coop/security/ir.model.access.csv
  3. 1
      easy_my_coop/views/operation_request_view.xml
  4. 11
      easy_my_coop/views/product_view.xml

179
easy_my_coop/models/operation_request.py

@ -122,7 +122,7 @@ class operation_request(models.Model):
def get_total_share_dic(self, partner):
total_share_dic = {}
share_products = self.env['product.template'].search([('is_share', '=', True)])
share_products = self.env['product.product'].search([('is_share', '=', True)])
for share_product in share_products:
total_share_dic[share_product.id] = 0
@ -214,13 +214,13 @@ class operation_request(models.Model):
return self.env.ref('easy_my_coop.email_template_share_update',
False)
def send_share_trans_mail(self, sub_register_line):
def send_share_trans_mail(self, sub_register_line): # Unused argument is used in synergie project. Do not remove.
cert_email_template = self.get_share_trans_mail_template()
cert_email_template.send_mail(rec.partner_id_to.id, False)
cert_email_template.send_mail(self.partner_id_to.id, False)
def send_share_update_mail(self, sub_register_line):
def send_share_update_mail(self, sub_register_line): # Unused argument is used in synergie project. Do not remove.
cert_email_template = self.get_share_update_mail_template()
cert_email_template.send_mail(rec.partner_id.id, False)
cert_email_template.send_mail(self.partner_id.id, False)
def get_subscription_register_vals(self, effective_date):
return {
@ -238,89 +238,88 @@ class operation_request(models.Model):
effective_date = self.get_date_now()
sub_request = self.env['subscription.request']
for rec in self:
rec.validate()
if rec.state != 'approved':
raise ValidationError(_("This operation must be approved"
" before to be executed"))
values = rec.get_subscription_register_vals(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':
amount_to_convert = rec.share_unit_price * rec.quantity
convert_quant = int(amount_to_convert / rec.share_to_product_id.list_price)
remainder = amount_to_convert % rec.share_to_product_id.list_price
if convert_quant > 0 and remainder == 0:
share_ids = rec.partner_id.share_ids
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,
'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':
sequence_id = self.env.ref('easy_my_coop.sequence_subscription', False)
partner_vals = {'member': True}
if rec.receiver_not_member:
partner = rec.subscription_request.create_coop_partner()
# get cooperator number
sub_reg_num = int(sequence_id.next_by_id())
partner_vals = sub_request.get_eater_vals(partner, rec.share_product_id)
partner_vals['cooperator_register_number'] = sub_reg_num
partner.write(partner_vals)
rec.partner_id_to = partner
else:
# means an old member or cooperator candidate
if not rec.partner_id_to.member:
if rec.partner_id_to.cooperator_register_number == 0:
sub_reg_num = int(sequence_id.next_by_id())
partner_vals['cooperator_register_number'] = sub_reg_num
partner_vals = sub_request.get_eater_vals(
rec.partner_id_to,
rec.share_product_id)
partner_vals['old_member'] = False
rec.partner_id_to.write(partner_vals)
# remove the parts to the giver
self.hand_share_over(rec.partner_id,
rec.share_product_id,
rec.quantity)
# give the share to the receiver
self.env['share.line'].create({
'share_number': rec.quantity,
'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})
values['partner_id_to'] = rec.partner_id_to.id
self.validate()
if self.state != 'approved':
raise ValidationError(_("This operation must be approved"
" before to be executed"))
values = self.get_subscription_register_vals(effective_date)
if self.operation_type == 'sell_back':
self.hand_share_over(self.partner_id, self.share_product_id,
self.quantity)
elif self.operation_type == 'convert':
amount_to_convert = self.share_unit_price * self.quantity
convert_quant = int(amount_to_convert / self.share_to_product_id.list_price)
remainder = amount_to_convert % self.share_to_product_id.list_price
if convert_quant > 0 and remainder == 0:
share_ids = self.partner_id.share_ids
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': self.share_to_product_id.id,
'share_unit_price': self.share_to_unit_price,
'share_short_name': self.share_to_short_name
})
values['share_to_product_id'] = self.share_to_product_id.id
values['quantity_to'] = convert_quant
else:
raise ValidationError(_("This operation is not yet"
" implemented."))
sequence_operation = self.env.ref('easy_my_coop.sequence_register_operation', False) #noqa
sub_reg_operation = sequence_operation.next_by_id()
values['name'] = sub_reg_operation
values['register_number_operation'] = int(sub_reg_operation)
rec.write({'state': 'done'})
# send mail to the receiver
if rec.operation_type == 'transfer':
self.send_share_trans_mail(sub_register_line)
sub_register_line = self.env['subscription.register'].create(values)
self.send_share_update_mail(sub_register_line)
raise ValidationError(_("Converting just part of the"
" shares is not yet implemented"))
elif self.operation_type == 'transfer':
sequence_id = self.env.ref('easy_my_coop.sequence_subscription', False)
partner_vals = {'member': True}
if self.receiver_not_member:
partner = self.subscription_request.create_coop_partner()
# get cooperator number
sub_reg_num = int(sequence_id.next_by_id())
partner_vals = sub_request.get_eater_vals(partner, self.share_product_id)
partner_vals['cooperator_register_number'] = sub_reg_num
partner.write(partner_vals)
self.partner_id_to = partner
else:
# means an old member or cooperator candidate
if not self.partner_id_to.member:
if self.partner_id_to.cooperator_register_number == 0:
sub_reg_num = int(sequence_id.next_by_id())
partner_vals['cooperator_register_number'] = sub_reg_num
partner_vals = sub_request.get_eater_vals(
self.partner_id_to,
self.share_product_id)
partner_vals['old_member'] = False
self.partner_id_to.write(partner_vals)
# remove the parts to the giver
self.hand_share_over(self.partner_id,
self.share_product_id,
self.quantity)
# give the share to the receiver
self.env['share.line'].create({
'share_number': self.quantity,
'partner_id': self.partner_id_to.id,
'share_product_id': self.share_product_id.id,
'share_unit_price': self.share_unit_price,
'effective_date': effective_date})
values['partner_id_to'] = self.partner_id_to.id
else:
raise ValidationError(_("This operation is not yet"
" implemented."))
sequence_operation = self.env.ref('easy_my_coop.sequence_register_operation', False) #noqa
sub_reg_operation = sequence_operation.next_by_id()
values['name'] = sub_reg_operation
values['register_number_operation'] = int(sub_reg_operation)
self.write({'state': 'done'})
sub_register_line = self.env['subscription.register'].create(values)
# send mail to the receiver
if self.operation_type == 'transfer':
self.send_share_trans_mail(sub_register_line)
self.send_share_update_mail(sub_register_line)

1
easy_my_coop/security/ir.model.access.csv

@ -8,6 +8,7 @@ access_subscription_request_easy_my_coop_user,access_subscription_request_easy_m
access_subscription_request_easy_my_coop_manager,access_subscription_request_easy_my_coop_manager,model_subscription_request,group_easy_my_coop_manager,1,1,1,1
access_share_line_user,access_share_line_user,model_share_line,base.group_user,1,0,0,0
access_share_line_easy_my_coop_user,access_share_line_easy_my_coop_user,model_share_line,group_easy_my_coop_user,1,1,1,0
access_share_line_easy_my_coop_manager,access_share_line_easy_my_coop_manager,model_share_line,group_easy_my_coop_manager,1,1,1,1
access_res_partner_easy_my_coop_user,access_res_partner_easy_my_coop_user,base.model_res_partner,group_easy_my_coop_user,1,1,1,0
access_account_invoice_easy_my_coop_user,access_account_invoice_easy_my_coop_user,model_account_invoice,group_easy_my_coop_user,1,1,1,0
access_subscription_register_easy_my_coop_user,access_subscription_register_easy_my_coop_user,model_subscription_register,group_easy_my_coop_user,1,1,1,0

1
easy_my_coop/views/operation_request_view.xml

@ -32,7 +32,6 @@
<sheet>
<group>
<group>
<field name="state"/>
<field name="request_date" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="operation_type" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="receiver_not_member" attrs="{'invisible':[('operation_type','!=','transfer')]}"/>

11
easy_my_coop/views/product_view.xml

@ -49,6 +49,17 @@
</field>
</record>
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<field name="default_code" position="attributes">
<attribute name="attrs">{'required': [('is_share', '=', True)]}</attribute>
</field>
</field>
</record>
<record id="share_product_action" model="ir.actions.act_window">
<field name="name">Share type</field>
<field name="type">ir.actions.act_window</field>

Loading…
Cancel
Save