diff --git a/beesdoo_base/__manifest__.py b/beesdoo_base/__manifest__.py
index dd0c497..2ad0665 100644
--- a/beesdoo_base/__manifest__.py
+++ b/beesdoo_base/__manifest__.py
@@ -34,5 +34,6 @@
'installable': True,
'demo': [
'demo/cooperators.xml',
+ 'demo/eaters.xml',
]
}
diff --git a/beesdoo_base/demo/eaters.xml b/beesdoo_base/demo/eaters.xml
new file mode 100644
index 0000000..13dc5f3
--- /dev/null
+++ b/beesdoo_base/demo/eaters.xml
@@ -0,0 +1,43 @@
+
+
+
+
+ Gilles Eaterbeek
+ Gilles
+ Eaterbeek
+ eater
+
+
+
+
+
+ Constant Eateration
+ Constant
+ Eateration
+ eater
+
+
+
+
+
+ Alexander G. Eaterphone
+ Alexander G.
+ Eaterphone
+ eater
+
+
+
+
+
+ Tim Eaternet
+ Tim
+ Eaternet
+ eater
+
+
+
+
+
diff --git a/beesdoo_base/models/partner.py b/beesdoo_base/models/partner.py
index 5e6470a..e96fbac 100644
--- a/beesdoo_base/models/partner.py
+++ b/beesdoo_base/models/partner.py
@@ -12,45 +12,29 @@ class Partner(models.Model):
barcode = fields.Char(compute="_get_bar_code", string='Barcode', store=True)
parent_barcode = fields.Char(compute="_get_bar_code", string='Parent Barcode', store=True)
member_card_ids = fields.One2many('member.card', 'partner_id')
- country_id = fields.Many2one(required=True, default=lambda self: self.env.ref('base.be'))
member_card_to_be_printed = fields.Boolean('Print BEES card?')
last_printed = fields.Datetime('Last printed on')
- cooperator_type = fields.Selection([('share_a', 'Share A'), ('share_b', 'Share B'), ('share_c', 'Share C')], store=True, compute=None)
-
- @api.one
@api.depends('parent_eater_id', 'parent_eater_id.barcode', 'eater', 'member_card_ids')
def _get_bar_code(self):
- if self.eater == 'eater':
- self.parent_barcode = self.parent_eater_id.barcode
- elif self.member_card_ids:
- for c in self.member_card_ids:
- if c.valid:
- self.barcode = c.barcode
-
- @api.one
- @api.constrains('child_eater_ids', 'parent_eater_id')
- def _check_number_of_eaters(self):
- """The owner of an A share can have a maximum of two eaters but
- the owner of a B share can have a maximum of three eaters.
- """
- # Get the default_code of the share for the current eater and his parent
- share_type_code = self.cooperator_type
- parent_share_type_code = self.parent_eater_id.cooperator_type
- # Raise exception
- if share_type_code == 'share_b' or parent_share_type_code == 'share_b':
- if len(self.child_eater_ids) > 3 or len(self.parent_eater_id.child_eater_ids) > 3:
- raise ValidationError(_('You can only set three additional eaters per worker'))
- else:
- if len(self.child_eater_ids) > 2 or len(self.parent_eater_id.child_eater_ids) > 2:
- raise ValidationError(_('You can only set two additional eaters per worker'))
-
+ for rec in self:
+ if rec.eater == 'eater':
+ rec.parent_barcode = rec.parent_eater_id.barcode
+ elif rec.member_card_ids:
+ for c in rec.member_card_ids:
+ if c.valid:
+ rec.barcode = c.barcode
@api.multi
def write(self, values):
- if values.get('parent_eater_id') and self.parent_eater_id:
- raise ValidationError(_('You try to assign a eater to a worker but this easer is alread assign to %s please remove it before') % self.parent_eater_id.name)
+ for rec in self:
+ if (
+ values.get('parent_eater_id')
+ and rec.parent_eater_id
+ and rec.parent_eater_id.id != values.get("parent_eater_id")
+ ):
+ raise ValidationError(_('You try to assign a eater to a worker but this eater is already assign to %s please remove it before') % rec.parent_eater_id.name)
# replace many2many command when writing on child_eater_ids to just remove the link
if 'child_eater_ids' in values:
for command in values['child_eater_ids']:
@@ -58,8 +42,8 @@ class Partner(models.Model):
command[0] = 3
return super(Partner, self).write(values)
- @api.one
def _deactivate_active_cards(self):
+ self.ensure_one()
for card in self.member_card_ids.filtered('valid'):
card.valid = False
card.end_date = fields.Date.today()
diff --git a/beesdoo_base/views/partner.xml b/beesdoo_base/views/partner.xml
index efa8d96..6a2c6a7 100644
--- a/beesdoo_base/views/partner.xml
+++ b/beesdoo_base/views/partner.xml
@@ -19,19 +19,12 @@
res.partner
-
-
-
-
- {'invisible':
- [('cooperator_type', '=', 'share_a')]}
-
@@ -87,19 +80,6 @@
-
- beesdoo.partner.search.view
- res.partner
-
-
-
-
-
-
-
-
-
-
diff --git a/beesdoo_easy_my_coop/__init__.py b/beesdoo_easy_my_coop/__init__.py
new file mode 100644
index 0000000..4ba7940
--- /dev/null
+++ b/beesdoo_easy_my_coop/__init__.py
@@ -0,0 +1,3 @@
+from . import models
+from . import wizards
+from . import controllers
diff --git a/beesdoo_easy_my_coop/__manifest__.py b/beesdoo_easy_my_coop/__manifest__.py
new file mode 100644
index 0000000..c3e3ad4
--- /dev/null
+++ b/beesdoo_easy_my_coop/__manifest__.py
@@ -0,0 +1,35 @@
+{
+ 'name': "Beescoop link with easy my coop",
+
+ 'summary': """
+ Module that made the link between beesdoo customization
+ and easy_my_coop
+ """,
+
+ 'description': """
+ """,
+
+ 'author': "BEES coop, Coop IT Easy",
+ 'website': "https://github.com/beescoop/Obeesdoo",
+
+ 'category': 'Cooperative management',
+ 'version': '12.0.1.0.0',
+
+ 'depends': ['beesdoo_base',
+ 'beesdoo_shift',
+ 'easy_my_coop',
+ 'easy_my_coop_website',
+ 'partner_age',
+ ],
+
+ 'data': [
+ 'views/res_company.xml',
+ 'views/subscription_request.xml',
+ 'views/subscription_templates.xml',
+ 'views/product.xml'
+ ],
+ 'demo': [
+ 'demo/product_share.xml',
+ ],
+ 'auto_install': True,
+}
diff --git a/beesdoo_easy_my_coop/controllers/__init__.py b/beesdoo_easy_my_coop/controllers/__init__.py
new file mode 100644
index 0000000..12a7e52
--- /dev/null
+++ b/beesdoo_easy_my_coop/controllers/__init__.py
@@ -0,0 +1 @@
+from . import main
diff --git a/beesdoo_easy_my_coop/controllers/main.py b/beesdoo_easy_my_coop/controllers/main.py
new file mode 100644
index 0000000..5e1cff4
--- /dev/null
+++ b/beesdoo_easy_my_coop/controllers/main.py
@@ -0,0 +1,19 @@
+from odoo import http
+from odoo.http import request
+
+from odoo.addons.easy_my_coop_website.controllers.main import WebsiteSubscription as Base
+
+class WebsiteSubscription(Base):
+
+ def fill_values(self, values, is_company, logged, load_from_user=False):
+ values = super(WebsiteSubscription, self).fill_values(values,
+ is_company,
+ logged,
+ load_from_user)
+ cmp = request.env['res.company']._company_default_get()
+ values.update({
+ 'display_info_session': cmp.display_info_session_confirmation,
+ 'info_session_required': cmp.info_session_confirmation_required,
+ 'info_session_text': cmp.info_session_confirmation_text,
+ })
+ return values
diff --git a/beesdoo_easy_my_coop/demo/product_share.xml b/beesdoo_easy_my_coop/demo/product_share.xml
new file mode 100644
index 0000000..9e8ab6e
--- /dev/null
+++ b/beesdoo_easy_my_coop/demo/product_share.xml
@@ -0,0 +1,77 @@
+
+
+
+
+ Acquisition de parts A de Beescoop scrl
+ share_a
+
+
+
+ 3
+
+
+
+ Acquisition de parts B de Beescoop scrl
+ share_b
+
+
+
+ 2
+
+
+
+ Acquisition de parts C de Beescoop scrl
+ share_c
+
+
+
+ -1
+
+
+
+
+
+
+ 2
+ 2020-01-01
+
+
+
+
+
+
+ share_a
+
+
+
+
+ 4
+ 2020-01-01
+
+
+
+
+
+
+ share_b
+
+
+
+
+ 6
+ 2020-01-01
+
+
+
+
+
+
+ share_c
+
+
diff --git a/beesdoo_easy_my_coop/models/__init__.py b/beesdoo_easy_my_coop/models/__init__.py
new file mode 100644
index 0000000..bb81dfc
--- /dev/null
+++ b/beesdoo_easy_my_coop/models/__init__.py
@@ -0,0 +1,5 @@
+from . import res_partner
+from . import subscription_request
+from . import res_company
+from . import product
+from . import coop
diff --git a/beesdoo_easy_my_coop/models/coop.py b/beesdoo_easy_my_coop/models/coop.py
new file mode 100644
index 0000000..2a422a0
--- /dev/null
+++ b/beesdoo_easy_my_coop/models/coop.py
@@ -0,0 +1,31 @@
+from odoo import api, models
+
+
+class SubscriptionRequest(models.Model):
+ _inherit = "subscription.request"
+
+ _majority = 18
+
+ def get_eater_vals(self, partner, share_product_id):
+ vals = {}
+ eater = share_product_id.eater
+
+ if partner.is_company or partner.age < self._majority:
+ eater = "eater"
+
+ vals["eater"] = eater
+
+ return vals
+
+ @api.one
+ def validate_subscription_request(self):
+
+ invoice = super(
+ SubscriptionRequest, self
+ ).validate_subscription_request()[0]
+ partner = invoice.partner_id
+
+ vals = self.get_eater_vals(partner, self.share_product_id)
+ partner.write(vals)
+
+ return invoice
diff --git a/beesdoo_easy_my_coop/models/product.py b/beesdoo_easy_my_coop/models/product.py
new file mode 100644
index 0000000..f8828e9
--- /dev/null
+++ b/beesdoo_easy_my_coop/models/product.py
@@ -0,0 +1,30 @@
+from odoo import models, fields
+
+
+class ProductTemplate(models.Model):
+
+ _inherit = 'product.template'
+
+ max_nb_eater_allowed = fields.Integer(
+ string="Max number of eater allowed",
+ default=-1,
+ help=(
+ "Maximum number of eater allowed for the owner of the share. "
+ "A negative value means no maximum."
+ )
+ )
+ allow_working = fields.Boolean(
+ string="Allow owner to work?",
+ help=(
+ "Owner of this type of share are allowed to participate to the "
+ "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_company.py b/beesdoo_easy_my_coop/models/res_company.py
new file mode 100644
index 0000000..7be05ce
--- /dev/null
+++ b/beesdoo_easy_my_coop/models/res_company.py
@@ -0,0 +1,35 @@
+# Copyright 2019 Coop IT Easy SCRLfs
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models, _
+
+
+class ResCompany(models.Model):
+
+ _inherit = 'res.company'
+ display_info_session_confirmation = fields.Boolean(
+ help="Choose to display a info session checkbox on the cooperator"
+ " website form."
+ )
+ info_session_confirmation_required = fields.Boolean(
+ string="Is info session confirmation required?"
+ )
+ info_session_confirmation_text = fields.Html(
+ translate=True,
+ help="Text to display aside the checkbox to confirm"
+ " participation to an info session."
+ )
+
+ @api.onchange('info_session_confirmation_required')
+ def onchange_info_session_confirmatio_required(self):
+ if self.info_session_confirmation_required:
+ self.display_info_session_confirmation = True
+
+ _sql_constraints = [(
+ 'info_session_approval_constraint',
+ """CHECK ((info_session_confirmation_required=FALSE
+ AND display_info_session_confirmation=FALSE)
+ OR display_info_session_confirmation=TRUE)
+ """,
+ "Approval can't be mandatory and not displayed."
+ )]
diff --git a/beesdoo_easy_my_coop/models/res_partner.py b/beesdoo_easy_my_coop/models/res_partner.py
new file mode 100644
index 0000000..de69114
--- /dev/null
+++ b/beesdoo_easy_my_coop/models/res_partner.py
@@ -0,0 +1,124 @@
+# Copyright 2019-2020 Coop IT Easy SCRLfs
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import models, fields, api, _
+from odoo.exceptions import ValidationError
+
+
+class Partner(models.Model):
+ _inherit = 'res.partner'
+
+ info_session_confirmed = fields.Boolean(
+ string="Confirmed presence to info session",
+ default=False,
+ )
+ is_worker = fields.Boolean(
+ compute="_is_worker",
+ search="_search_worker",
+ readonly=True,
+ 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',
+ 'share_ids.share_product_id.default_code',
+ 'share_ids.share_number',
+ )
+ def _is_worker(self):
+ """
+ Return True if the partner can participate tho the shift system.
+ This is defined on the share type.
+ """
+ for rec in self:
+ share_type = rec._cooperator_share_type()
+ if share_type:
+ rec.is_worker = share_type.allow_working
+ rec.worker_store = share_type.allow_working
+ else:
+ rec.is_worker = False
+ rec.worker_store = False
+
+ def _search_worker(self, operator, value):
+ return [('worker_store', operator, value)]
+
+ @api.depends(
+ "cooperative_status_ids",
+ "cooperative_status_ids.status",
+ "cooperative_status_ids.can_shop",
+ "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.is_worker and rec.cooperative_status_ids
+ else share_type.allow_shopping
+ )
+ else:
+ rec.can_shop = (
+ rec.cooperative_status_ids.can_shop
+ if rec.is_worker and rec.cooperative_status_ids else False
+ )
+
+ @api.constrains('parent_eater_id')
+ def _check_max_parent_eaters(self):
+ """
+ Check that the parent_eater_id in parnter in self doesn't exceed
+ the maximum eater limit.
+ See also: _check_max_child_eaters()
+ """
+ for rec in self:
+ if rec.parent_eater_id:
+ share_type = rec.parent_eater_id._cooperator_share_type()
+ if (
+ share_type
+ and share_type.max_nb_eater_allowed >= 0
+ and len(
+ rec.parent_eater_id.child_eater_ids
+ ) > share_type.max_nb_eater_allowed
+ ):
+ raise ValidationError(
+ _('You can only set %d additional eaters per worker')
+ % share_type.max_nb_eater_allowed
+ )
+
+ @api.constrains('child_eater_ids')
+ def _check_max_child_eaters(self):
+ """
+ Check the maximum number of eaters that can be assigned to a
+ share owner.
+ See also: _check_max_parent_eaters()
+ """
+ for rec in self:
+ share_type = rec._cooperator_share_type()
+ if (
+ share_type
+ and share_type.max_nb_eater_allowed >= 0
+ and len(rec.child_eater_ids) > share_type.max_nb_eater_allowed
+ ):
+ raise ValidationError(
+ _('You can only set %d additional eaters per worker')
+ % share_type.max_nb_eater_allowed
+ )
diff --git a/beesdoo_easy_my_coop/models/subscription_request.py b/beesdoo_easy_my_coop/models/subscription_request.py
new file mode 100644
index 0000000..8c4b734
--- /dev/null
+++ b/beesdoo_easy_my_coop/models/subscription_request.py
@@ -0,0 +1,26 @@
+# Copyright 2019 Coop IT Easy SCRLfs
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models, _
+
+
+class SubscriptionRequest(models.Model):
+
+ _inherit = 'subscription.request'
+
+ info_session_confirmed = fields.Boolean(
+ string="Confirmed Info Session",
+ default=False,
+ )
+
+ def get_partner_vals(self):
+ partner_vals = super(SubscriptionRequest, self).get_partner_vals()
+ partner_vals['info_session_confirmed'] = self.info_session_confirmed
+ return partner_vals
+
+ def get_required_field(self):
+ required_fields = super(SubscriptionRequest, self).get_required_field()
+ company = self.env['res.company']._company_default_get()
+ if company.info_session_confirmation_required:
+ required_fields.append('info_session_confirmed')
+ return required_fields
diff --git a/beesdoo_easy_my_coop/tests/__init__.py b/beesdoo_easy_my_coop/tests/__init__.py
new file mode 100644
index 0000000..d57d215
--- /dev/null
+++ b/beesdoo_easy_my_coop/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_res_partner
diff --git a/beesdoo_easy_my_coop/tests/test_res_partner.py b/beesdoo_easy_my_coop/tests/test_res_partner.py
new file mode 100644
index 0000000..742c487
--- /dev/null
+++ b/beesdoo_easy_my_coop/tests/test_res_partner.py
@@ -0,0 +1,205 @@
+# Copyright 2020 Coop IT Easy SCRLfs ()
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
+
+from odoo import exceptions
+from odoo.exceptions import ValidationError
+from odoo.tests.common import TransactionCase
+
+
+class TestResPartner(TransactionCase):
+ def setUp(self):
+ super().setUp()
+ self.eater1 = self.env.ref("beesdoo_base.eater1")
+ self.eater2 = self.env.ref("beesdoo_base.eater2")
+ self.eater3 = self.env.ref("beesdoo_base.eater3")
+ self.eater4 = self.env.ref("beesdoo_base.eater4")
+
+ def test_max_eater_assignment_share_a(self):
+ """
+ Test adding eater to a cooperator and raise when max is
+ reached.
+ """
+ coop1 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_1_demo"
+ )
+ coop1.write({"child_eater_ids": [(4, self.eater1.id)]})
+ self.assertEqual(len(coop1.child_eater_ids), 1)
+ coop1.write({"child_eater_ids": [(4, self.eater2.id)]})
+ self.assertEqual(len(coop1.child_eater_ids), 2)
+ coop1.write({"child_eater_ids": [(4, self.eater3.id)]})
+ self.assertEqual(len(coop1.child_eater_ids), 3)
+ with self.assertRaises(ValidationError) as econtext:
+ coop1.write({"child_eater_ids": [(4, self.eater4.id)]})
+ self.assertIn("can only set", str(econtext.exception))
+ # Reset
+ coop1.write({"child_eater_ids": [(5, None, None)]})
+ self.assertEqual(len(coop1.child_eater_ids), 0)
+ # Test by editing parent_eater_id
+ self.eater1.write({"parent_eater_id": coop1.id})
+ self.assertEqual(len(coop1.child_eater_ids), 1)
+ self.eater2.write({"parent_eater_id": coop1.id})
+ self.assertEqual(len(coop1.child_eater_ids), 2)
+ self.eater3.write({"parent_eater_id": coop1.id})
+ self.assertEqual(len(coop1.child_eater_ids), 3)
+ with self.assertRaises(ValidationError) as econtext:
+ self.eater4.write({"parent_eater_id": coop1.id})
+ self.assertIn("can only set", str(econtext.exception))
+
+ def test_max_eater_assignment_share_b(self):
+ """
+ Test adding eater to a cooperator and raise when max is
+ reached.
+ """
+ coop2 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_2_demo"
+ )
+ coop2.write({"child_eater_ids": [(4, self.eater1.id)]})
+ self.assertEqual(len(coop2.child_eater_ids), 1)
+ coop2.write({"child_eater_ids": [(4, self.eater2.id)]})
+ self.assertEqual(len(coop2.child_eater_ids), 2)
+ with self.assertRaises(ValidationError) as econtext:
+ coop2.write({"child_eater_ids": [(4, self.eater3.id)]})
+ self.assertIn("can only set", str(econtext.exception))
+ # Reset
+ coop2.write({"child_eater_ids": [(5, None, None)]})
+ self.assertEqual(len(coop2.child_eater_ids), 0)
+ # Test by editing parent_eater_id
+ self.eater1.write({"parent_eater_id": coop2.id})
+ self.assertEqual(len(coop2.child_eater_ids), 1)
+ self.eater2.write({"parent_eater_id": coop2.id})
+ self.assertEqual(len(coop2.child_eater_ids), 2)
+ with self.assertRaises(ValidationError) as econtext:
+ self.eater3.write({"parent_eater_id": coop2.id})
+ self.assertIn("can only set", str(econtext.exception))
+
+ def test_unlimited_eater_assignment_share_c(self):
+ """
+ Test that share_c can have an unlimited number of eater.
+ """
+ coop3 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_3_demo"
+ )
+ coop3.write({"child_eater_ids": [(4, self.eater1.id)]})
+ self.assertEqual(len(coop3.child_eater_ids), 1)
+ coop3.write({"child_eater_ids": [(4, self.eater2.id)]})
+ self.assertEqual(len(coop3.child_eater_ids), 2)
+ coop3.write({"child_eater_ids": [(4, self.eater3.id)]})
+ self.assertEqual(len(coop3.child_eater_ids), 3)
+ coop3.write({"child_eater_ids": [(4, self.eater4.id)]})
+ self.assertEqual(len(coop3.child_eater_ids), 4)
+
+ def test_share_with_no_eater_assignment_allowed(self):
+ """
+ Test that share that doesn't allow eater assignment.
+ """
+ share_c = self.env.ref("beesdoo_easy_my_coop.share_c")
+ share_c.max_nb_eater_allowed = 0
+ coop3 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_3_demo"
+ )
+ with self.assertRaises(ValidationError) as econtext:
+ coop3.write({"child_eater_ids": [(4, self.eater3.id)]})
+ self.assertIn("can only set", str(econtext.exception))
+ with self.assertRaises(ValidationError) as econtext:
+ self.eater1.write({"parent_eater_id": coop3.id})
+ self.assertIn("can only set", str(econtext.exception))
+
+ def test_multiple_eater_assignement_share_a(self):
+ """
+ Test adding multiple eater in one write.
+ """
+ coop1 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_1_demo"
+ )
+ coop1.write(
+ {
+ "child_eater_ids": [
+ (4, self.eater1.id),
+ (4, self.eater2.id),
+ (4, self.eater3.id),
+ ]
+ }
+ )
+ self.assertEqual(len(coop1.child_eater_ids), 3)
+
+ def test_parent_assignement_to_eater(self):
+ """
+ Test adding a parent to multiple eater in one write from the eater.
+ """
+ coop1 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_1_demo"
+ )
+ eaters = self.eater1
+ eaters |= self.eater2
+ eaters |= self.eater3
+ eaters.write({"parent_eater_id": coop1.id})
+ self.assertEqual(len(coop1.child_eater_ids), 3)
+
+ def test_is_worker_share_a(self):
+ """
+ Test that a cooperator is a worker based on his share type.
+ """
+ coop1 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_1_demo"
+ )
+ # Run computed field
+ coop1._is_worker()
+ self.assertEqual(coop1.is_worker, True)
+
+ def test_is_worker_share_b(self):
+ """
+ Test that a cooperator is a worker based on his share type.
+ """
+ coop2 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_2_demo"
+ )
+ # Run computed field
+ coop2._is_worker()
+ self.assertEqual(coop2.is_worker, False)
+
+ def test_search_worker(self):
+ """
+ Test that the search function returns worker based on the
+ 'is_worker' field.
+ """
+ coop1 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_1_demo"
+ )
+ coop2 = self.env.ref(
+ "beesdoo_base.res_partner_cooperator_2_demo"
+ )
+ # Run computed field
+ coop1._is_worker()
+ coop2._is_worker()
+ workers = self.env["res.partner"].search([("is_worker", "=", True)])
+ self.assertIn(coop1, workers)
+ self.assertNotIn(coop2, workers)
+ 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)
+ # Now unsubscribe the coop
+ coop1.cooperative_status_ids.status = 'resigning'
+ self.assertEqual(coop1.cooperative_status_ids.can_shop, False)
+ self.assertEqual(coop1.can_shop, False)
+
+ 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
new file mode 100644
index 0000000..0cb48e1
--- /dev/null
+++ b/beesdoo_easy_my_coop/views/product.xml
@@ -0,0 +1,18 @@
+
+
+
+ product.template.share.form
+ product.template
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/beesdoo_easy_my_coop/views/res_company.xml b/beesdoo_easy_my_coop/views/res_company.xml
new file mode 100644
index 0000000..daa8557
--- /dev/null
+++ b/beesdoo_easy_my_coop/views/res_company.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+ res.company.form (in beesdoo_easy_my_coop)
+ res.company
+
+
+
+
+
+
+
+
+
+
+
diff --git a/beesdoo_easy_my_coop/views/subscription_request.xml b/beesdoo_easy_my_coop/views/subscription_request.xml
new file mode 100644
index 0000000..1b75719
--- /dev/null
+++ b/beesdoo_easy_my_coop/views/subscription_request.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ subscription.request.form (in beesdoo_easy_my_coop)
+ subscription.request
+
+
+
+
+
+
+
+
+
diff --git a/beesdoo_easy_my_coop/views/subscription_templates.xml b/beesdoo_easy_my_coop/views/subscription_templates.xml
new file mode 100644
index 0000000..44fd0e8
--- /dev/null
+++ b/beesdoo_easy_my_coop/views/subscription_templates.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/beesdoo_easy_my_coop/wizards/__init__.py b/beesdoo_easy_my_coop/wizards/__init__.py
new file mode 100644
index 0000000..eb54c76
--- /dev/null
+++ b/beesdoo_easy_my_coop/wizards/__init__.py
@@ -0,0 +1 @@
+from . import beesdoo_shift_subscribe
diff --git a/beesdoo_easy_my_coop/wizards/beesdoo_shift_subscribe.py b/beesdoo_easy_my_coop/wizards/beesdoo_shift_subscribe.py
new file mode 100644
index 0000000..7cc79f5
--- /dev/null
+++ b/beesdoo_easy_my_coop/wizards/beesdoo_shift_subscribe.py
@@ -0,0 +1,24 @@
+# Copyright 2019 Coop IT Easy SCRLfs
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models, _
+
+
+class Subscribe(models.TransientModel):
+
+ _inherit = 'beesdoo.shift.subscribe'
+
+ def _get_info_session_followed(self):
+ """
+ Check if the user has checked the info_session_confirmed in the
+ form to become new cooperator.
+ """
+ followed = super(Subscribe, self)._get_info_session_followed()
+ if not followed:
+ return (self.env['res.partner']
+ .browse(self._context.get('active_id'))
+ .info_session_confirmed)
+ return followed
+
+ info_session = fields.Boolean(default=_get_info_session_followed)
+
diff --git a/beesdoo_shift/__manifest__.py b/beesdoo_shift/__manifest__.py
index 368e210..08db04f 100644
--- a/beesdoo_shift/__manifest__.py
+++ b/beesdoo_shift/__manifest__.py
@@ -40,5 +40,6 @@
],
'demo': [
"demo/templates.xml",
+ "demo/workers.xml",
]
}
diff --git a/beesdoo_worker_status/demo/workers.xml b/beesdoo_shift/demo/workers.xml
similarity index 67%
rename from beesdoo_worker_status/demo/workers.xml
rename to beesdoo_shift/demo/workers.xml
index 13edb20..b9880c2 100644
--- a/beesdoo_worker_status/demo/workers.xml
+++ b/beesdoo_shift/demo/workers.xml
@@ -4,7 +4,8 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
-
+
+
@@ -15,9 +16,11 @@
regular
+
+
-
+
2
@@ -27,9 +30,11 @@
irregular
+
+
-
+
@@ -39,9 +44,11 @@
regular
+
+
-
+
2
irregular
@@ -50,9 +57,11 @@
irregular
+
+
-
+
2
regular
@@ -60,9 +69,11 @@
regular
+
+
-
+
@@ -72,6 +83,8 @@
regular
+
+
diff --git a/beesdoo_shift/models/__init__.py b/beesdoo_shift/models/__init__.py
index ddc930b..7b98f32 100644
--- a/beesdoo_shift/models/__init__.py
+++ b/beesdoo_shift/models/__init__.py
@@ -2,3 +2,4 @@
from . import task
from . import planning
from . import cooperative_status
+from . import res_partner
diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py
index 9f369bf..d9e1514 100644
--- a/beesdoo_shift/models/cooperative_status.py
+++ b/beesdoo_shift/models/cooperative_status.py
@@ -312,81 +312,3 @@ class ShiftCronJournal(models.Model):
if not self.user_has_groups('beesdoo_shift.group_cooperative_admin'):
raise ValidationError(_("You don't have the access to perform this action"))
self.sudo().env['cooperative.status']._cron_compute_counter_irregular(today=self.date)
-
-class ResPartner(models.Model):
- """
- One2many relationship with CooperativeStatus should
- be replaced by inheritance.
- """
- _inherit = 'res.partner'
-
- worker_store = fields.Boolean(default=False)
- is_worker = fields.Boolean(related="worker_store", string="Worker", readonly=False)
- 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)
- info_session_date = fields.Date(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True)
- working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True)
- exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True)
- state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True)
- 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.multi
- def coop_subscribe(self):
- return {
- 'name': _('Subscribe Cooperator'),
- 'type': 'ir.actions.act_window',
- 'view_type': 'form',
- 'view_mode': 'form',
- 'res_model': 'beesdoo.shift.subscribe',
- 'target': 'new',
- }
-
- @api.multi
- def coop_unsubscribe(self):
- res = self.coop_subscribe()
- res['context'] = {'default_unsubscribed': True}
- return res
-
- @api.multi
- def manual_extension(self):
- return {
- 'name': _('Manual Extension'),
- 'type': 'ir.actions.act_window',
- 'view_type': 'form',
- 'view_mode': 'form',
- 'res_model': 'beesdoo.shift.extension',
- 'target': 'new',
- }
-
- @api.multi
- def auto_extension(self):
- res = self.manual_extension()
- res['context'] = {'default_auto': True}
- res['name'] = _('Trigger Grace Delay')
- return res
-
- @api.multi
- def register_holiday(self):
- return {
- 'name': _('Register Holiday'),
- 'type': 'ir.actions.act_window',
- 'view_type': 'form',
- 'view_mode': 'form',
- 'res_model': 'beesdoo.shift.holiday',
- 'target': 'new',
- }
-
- @api.multi
- def temporary_exempt(self):
- return {
- 'name': _('Temporary Exemption'),
- 'type': 'ir.actions.act_window',
- 'view_type': 'form',
- 'view_mode': 'form',
- 'res_model': 'beesdoo.shift.temporary_exemption',
- 'target': 'new',
- }
-
- #TODO access right + vue on res.partner
diff --git a/beesdoo_shift/models/res_partner.py b/beesdoo_shift/models/res_partner.py
new file mode 100644
index 0000000..7cefcbe
--- /dev/null
+++ b/beesdoo_shift/models/res_partner.py
@@ -0,0 +1,98 @@
+from odoo import models, fields, api, _
+from odoo.exceptions import ValidationError, UserError
+
+from datetime import timedelta, datetime
+import logging
+
+
+class ResPartner(models.Model):
+ """
+ One2many relationship with CooperativeStatus should
+ be replaced by inheritance.
+ """
+ _inherit = 'res.partner'
+
+ 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)
+ info_session_date = fields.Date(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True)
+ working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True)
+ exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True)
+ state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True)
+ 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 {
+ 'name': _('Subscribe Cooperator'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'beesdoo.shift.subscribe',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def coop_unsubscribe(self):
+ res = self.coop_subscribe()
+ res['context'] = {'default_unsubscribed': True}
+ return res
+
+ @api.multi
+ def manual_extension(self):
+ return {
+ 'name': _('Manual Extension'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'beesdoo.shift.extension',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def auto_extension(self):
+ res = self.manual_extension()
+ res['context'] = {'default_auto': True}
+ res['name'] = _('Trigger Grace Delay')
+ return res
+
+ @api.multi
+ def register_holiday(self):
+ return {
+ 'name': _('Register Holiday'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'beesdoo.shift.holiday',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def temporary_exempt(self):
+ return {
+ 'name': _('Temporary Exemption'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'beesdoo.shift.temporary_exemption',
+ 'target': 'new',
+ }
+
+ #TODO access right + vue on res.partner
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 @@
+