Browse Source

[REFACT] refactor the code make can shop extendable and configurable.

pull/134/head
houssine 4 years ago
committed by Rémy Taymans
parent
commit
a0d2b56def
  1. 40
      beesdoo_easy_my_coop/models/res_partner.py

40
beesdoo_easy_my_coop/models/res_partner.py

@ -1,44 +1,28 @@
from odoo import models, fields, api, _
from odoo import models, fields, api
class Partner(models.Model):
_inherit = 'res.partner'
cooperator_type = fields.Selection(selection='_get_share_type', compute='_compute_share_type', string='Cooperator Type', store=True)
can_shop = fields.Boolean(compute='_can_shop', store=True)
info_session_confirmed = fields.Boolean(
string="Confirmed presence to info session",
default=False,
)
@api.depends('cooperator_type', 'cooperative_status_ids', 'cooperative_status_ids.can_shop')
@api.depends('cooperator_type',
'cooperative_status_ids',
'cooperative_status_ids.can_shop')
def _can_shop(self):
product_obj = self.env['product.template']
can_shop_shares = product_obj.search([('is_share', '=', True),
('can_shop', '=', True)
]).mapped('default_code')
for rec in self:
if rec.cooperator_type == 'share_b':
if rec.cooperator_type in can_shop_shares:
rec.can_shop = True
elif rec.cooperative_status_ids and rec.cooperative_status_ids[0].can_shop:
elif (rec.cooperative_status_ids
and rec.cooperative_status_ids[0].can_shop):
rec.can_shop = True
else:
rec.can_shop = False
@api.multi
@api.depends('share_ids', 'share_ids.share_product_id', 'share_ids.share_product_id.default_code', 'share_ids.share_number')
def _compute_share_type(self):
for rec in self:
if rec.share_ids and rec.share_ids[0].share_number > 0:
rec.cooperator_type = rec.share_ids[0].share_product_id.default_code
else:
rec.cooperator_type = ''
@api.multi
def _get_share_type(self):
share_type_list = [('','')]
for share_type in self.env['product.product'].search([('is_share','=',True)]):
share_type_list.append((share_type.default_code, share_type.short_name))
return share_type_list
@api.noguess
def _auto_init(self, cr, context=None):
cr.execute("ALTER TABLE res_partner DROP COLUMN IF EXISTS cooperator_type")
res = super(Partner, self)._auto_init(cr, context=context)
return res
Loading…
Cancel
Save