Browse Source

[ADD] b_shift,b_emc: can_shop status on res_partner

pull/134/head
Rémy Taymans 5 years ago
parent
commit
0b93dd1cf6
  1. 5
      beesdoo_easy_my_coop/demo/product_share.xml
  2. 4
      beesdoo_easy_my_coop/models/product.py
  3. 45
      beesdoo_easy_my_coop/models/res_partner.py
  4. 22
      beesdoo_easy_my_coop/tests/test_res_partner.py
  5. 1
      beesdoo_easy_my_coop/views/product.xml
  6. 14
      beesdoo_shift/models/res_partner.py
  7. 1
      beesdoo_shift/views/cooperative_status.xml

5
beesdoo_easy_my_coop/demo/product_share.xml

@ -6,6 +6,7 @@
<field name="default_code">share_a</field>
<field name="customer" eval="True" />
<field name="allow_working" eval="True" />
<field name="allow_shopping" eval="True" />
<field name="max_nb_eater_allowed">3</field>
<field name="is_share" eval="True" />
</record>
@ -14,14 +15,16 @@
<field name="default_code">share_b</field>
<field name="customer" eval="True" />
<field name="allow_working" eval="False" />
<field name="allow_shopping" eval="True" />
<field name="max_nb_eater_allowed">2</field>
<field name="is_share" eval="True" />
</record>
<record id="share_c" model="product.product" >
<field name="name">Acquisition de parts C de Beescoop scrl</field>
<field name="default_code">share_c</field>
<field name="customer" eval="False" />
<field name="customer" eval="True" />
<field name="allow_working" eval="False" />
<field name="allow_shopping" eval="False" />
<field name="max_nb_eater_allowed">-1</field>
<field name="is_share" eval="True" />
</record>

4
beesdoo_easy_my_coop/models/product.py

@ -20,6 +20,10 @@ class ProductTemplate(models.Model):
"shift system."
)
)
allow_shopping = fields.Boolean(
string="Allow owner to shop?",
help="Owner of this type of share are allowed to shop.",
)
eater = fields.Selection(
[("eater", "Eater"), ("worker_eater", "Worker and Eater")],
string="Eater/Worker",

45
beesdoo_easy_my_coop/models/res_partner.py

@ -19,6 +19,19 @@ class Partner(models.Model):
related=""
)
def _cooperator_share_type(self):
"""
Return the share.type that correspond to the cooperator_type.
"""
self.ensure_one()
share_type = None
if self.cooperator_type:
share_type = (
self.env['product.template']
.search([('default_code', '=', self.cooperator_type)])
)[0]
return share_type
@api.depends(
'share_ids',
'share_ids.share_product_id',
@ -31,12 +44,7 @@ class Partner(models.Model):
This is defined on the share type.
"""
for rec in self:
share_type = None
if rec.cooperator_type:
share_type = (
self.env['product.template']
.search([('default_code', '=', rec.cooperator_type)])
)[0]
share_type = rec._cooperator_share_type()
if share_type:
rec.is_worker = share_type.allow_working
rec.worker_store = share_type.allow_working
@ -47,6 +55,31 @@ class Partner(models.Model):
def _search_worker(self, operator, value):
return [('worker_store', operator, value)]
@api.depends(
"cooperative_status_ids",
"share_ids",
"share_ids.share_product_id",
"share_ids.share_product_id.default_code",
"share_ids.share_number",
)
def _compute_can_shop(self):
"""
Overwrite default behavior to take the owned share into account.
"""
for rec in self:
share_type = rec._cooperator_share_type()
if share_type:
rec.can_shop = (
rec.cooperative_status_ids.can_shop
if rec.cooperative_status_ids
else share_type.allow_shopping
)
else:
rec.can_shop = (
rec.cooperative_status_ids.can_shop
if rec.cooperative_status_ids else False
)
@api.constrains('child_eater_ids', 'parent_eater_id')
def _check_number_of_eaters(self):
"""

22
beesdoo_easy_my_coop/tests/test_res_partner.py

@ -150,3 +150,25 @@ class TestResPartner(TransactionCase):
workers = self.env["res.partner"].search([("is_worker", "=", False)])
self.assertNotIn(coop1, workers)
self.assertIn(coop2, workers)
def test_compute_can_shop_share_a(self):
"""
Test that a cooperator can shop based on his share type.
"""
coop1 = self.env.ref(
"beesdoo_base.res_partner_cooperator_1_demo"
)
# Run computed field
coop1._compute_can_shop()
self.assertEqual(coop1.can_shop, True)
def test_compute_can_shop_share_c(self):
"""
Test that a cooperator can shop based on his share type.
"""
coop3 = self.env.ref(
"beesdoo_base.res_partner_cooperator_3_demo"
)
# Run computed field
coop3._compute_can_shop()
self.assertEqual(coop3.can_shop, False)

1
beesdoo_easy_my_coop/views/product.xml

@ -7,6 +7,7 @@
<field name="arch" type="xml">
<field name="customer" position="after">
<field name="allow_working" attrs="{'invisible':[('is_share','=',False)]}"/>
<field name="allow_shopping" attrs="{'invisible':[('is_share','=',False)]}"/>
<field name="max_nb_eater_allowed" attrs="{'invisible':[('is_share','=',False)]}"/>
</field>
<field name="minimum_quantity" position="after">

14
beesdoo_shift/models/res_partner.py

@ -14,6 +14,7 @@ class ResPartner(models.Model):
worker_store = fields.Boolean(default=False)
is_worker = fields.Boolean(related="worker_store", string="Worker", readonly=False)
can_shop = fields.Boolean(string="Is worker allowed to shop?", compute="_compute_can_shop", store=True)
cooperative_status_ids = fields.One2many('cooperative.status', 'cooperator_id', readonly=True)
super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True)
info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True)
@ -24,6 +25,19 @@ class ResPartner(models.Model):
extension_start_time = fields.Date(related='cooperative_status_ids.extension_start_time', string="Extension Start Day", readonly=True, store=True)
subscribed_shift_ids = fields.Many2many('beesdoo.shift.template')
@api.depends("cooperative_status_ids")
def _compute_can_shop(self):
"""
Shopping authorisation may vary on the can_shop status of the
cooperative.status but also other parameters.
Overwrite this function to change the default behavior.
"""
for rec in self:
if rec.cooperative_status_ids:
rec.can_shop = rec.cooperative_status_ids.can_shop
else:
rec.can_shop = True
@api.multi
def coop_subscribe(self):
return {

1
beesdoo_shift/views/cooperative_status.xml

@ -38,6 +38,7 @@
</xpath>
<xpath expr="//field[@name='type']" position="before">
<field name="is_worker"/>
<field name="can_shop"/>
</xpath>
<xpath expr="//notebook" position="inside">
<page string="Worker information"

Loading…
Cancel
Save