diff --git a/beesdoo_easy_my_coop/demo/product_share.xml b/beesdoo_easy_my_coop/demo/product_share.xml
index cc7eca9..9e8ab6e 100644
--- a/beesdoo_easy_my_coop/demo/product_share.xml
+++ b/beesdoo_easy_my_coop/demo/product_share.xml
@@ -6,6 +6,7 @@
share_a
+
3
@@ -14,14 +15,16 @@
share_b
+
2
Acquisition de parts C de Beescoop scrl
share_c
-
+
+
-1
diff --git a/beesdoo_easy_my_coop/models/product.py b/beesdoo_easy_my_coop/models/product.py
index 46f53a9..f8828e9 100644
--- a/beesdoo_easy_my_coop/models/product.py
+++ b/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",
diff --git a/beesdoo_easy_my_coop/models/res_partner.py b/beesdoo_easy_my_coop/models/res_partner.py
index d683df7..1088674 100644
--- a/beesdoo_easy_my_coop/models/res_partner.py
+++ b/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):
"""
diff --git a/beesdoo_easy_my_coop/tests/test_res_partner.py b/beesdoo_easy_my_coop/tests/test_res_partner.py
index a65b110..66bc5d3 100644
--- a/beesdoo_easy_my_coop/tests/test_res_partner.py
+++ b/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)
diff --git a/beesdoo_easy_my_coop/views/product.xml b/beesdoo_easy_my_coop/views/product.xml
index 0a87d3f..0cb48e1 100644
--- a/beesdoo_easy_my_coop/views/product.xml
+++ b/beesdoo_easy_my_coop/views/product.xml
@@ -7,6 +7,7 @@
+
diff --git a/beesdoo_shift/models/res_partner.py b/beesdoo_shift/models/res_partner.py
index 2d7138c..7cefcbe 100644
--- a/beesdoo_shift/models/res_partner.py
+++ b/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 {
diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml
index 282a7bc..aea4327 100644
--- a/beesdoo_shift/views/cooperative_status.xml
+++ b/beesdoo_shift/views/cooperative_status.xml
@@ -38,6 +38,7 @@
+