Browse Source
Merge pull request #134 from beescoop/12.0-mig-obeesdoo_beesdoo_easy_my_coop
Merge pull request #134 from beescoop/12.0-mig-obeesdoo_beesdoo_easy_my_coop
[12.0] [MIG] beesdoo_easy_my_cooppull/153/head
Rémy Taymans
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 880 additions and 155 deletions
-
1beesdoo_base/__manifest__.py
-
43beesdoo_base/demo/eaters.xml
-
44beesdoo_base/models/partner.py
-
20beesdoo_base/views/partner.xml
-
3beesdoo_easy_my_coop/__init__.py
-
35beesdoo_easy_my_coop/__manifest__.py
-
1beesdoo_easy_my_coop/controllers/__init__.py
-
19beesdoo_easy_my_coop/controllers/main.py
-
77beesdoo_easy_my_coop/demo/product_share.xml
-
5beesdoo_easy_my_coop/models/__init__.py
-
31beesdoo_easy_my_coop/models/coop.py
-
30beesdoo_easy_my_coop/models/product.py
-
35beesdoo_easy_my_coop/models/res_company.py
-
124beesdoo_easy_my_coop/models/res_partner.py
-
26beesdoo_easy_my_coop/models/subscription_request.py
-
1beesdoo_easy_my_coop/tests/__init__.py
-
205beesdoo_easy_my_coop/tests/test_res_partner.py
-
18beesdoo_easy_my_coop/views/product.xml
-
20beesdoo_easy_my_coop/views/res_company.xml
-
18beesdoo_easy_my_coop/views/subscription_request.xml
-
28beesdoo_easy_my_coop/views/subscription_templates.xml
-
1beesdoo_easy_my_coop/wizards/__init__.py
-
24beesdoo_easy_my_coop/wizards/beesdoo_shift_subscribe.py
-
1beesdoo_shift/__manifest__.py
-
25beesdoo_shift/demo/workers.xml
-
1beesdoo_shift/models/__init__.py
-
78beesdoo_shift/models/cooperative_status.py
-
98beesdoo_shift/models/res_partner.py
-
1beesdoo_shift/views/cooperative_status.xml
-
1beesdoo_worker_status/__manifest__.py
-
19beesdoo_worker_status/models/cooperative_status.py
@ -0,0 +1,43 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- |
|||
Copyright 2019 Coop IT Easy |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
--> |
|||
<odoo> |
|||
<record id="eater1" model="res.partner"> |
|||
<field name="name">Gilles Eaterbeek</field> |
|||
<field name="firstname">Gilles</field> |
|||
<field name="lastname">Eaterbeek</field> |
|||
<field name="eater">eater</field> |
|||
<field name="is_company" eval="False"/> |
|||
<field name="customer" eval="True"/> |
|||
</record> |
|||
|
|||
<record id="eater2" model="res.partner"> |
|||
<field name="name">Constant Eateration</field> |
|||
<field name="firstname">Constant</field> |
|||
<field name="lastname">Eateration</field> |
|||
<field name="eater">eater</field> |
|||
<field name="is_company" eval="False"/> |
|||
<field name="customer" eval="True"/> |
|||
</record> |
|||
|
|||
<record id="eater3" model="res.partner"> |
|||
<field name="name">Alexander G. Eaterphone</field> |
|||
<field name="firstname">Alexander G.</field> |
|||
<field name="lastname">Eaterphone</field> |
|||
<field name="eater">eater</field> |
|||
<field name="is_company" eval="False"/> |
|||
<field name="customer" eval="True"/> |
|||
</record> |
|||
|
|||
<record id="eater4" model="res.partner"> |
|||
<field name="name">Tim Eaternet</field> |
|||
<field name="firstname">Tim</field> |
|||
<field name="lastname">Eaternet</field> |
|||
<field name="eater">eater</field> |
|||
<field name="is_company" eval="False"/> |
|||
<field name="customer" eval="True"/> |
|||
</record> |
|||
</odoo> |
|||
|
@ -0,0 +1,3 @@ |
|||
from . import models |
|||
from . import wizards |
|||
from . import controllers |
@ -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, |
|||
} |
@ -0,0 +1 @@ |
|||
from . import main |
@ -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 |
@ -0,0 +1,77 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!-- Share products --> |
|||
<record id="share_a" model="product.product" > |
|||
<field name="name">Acquisition de parts A de Beescoop scrl</field> |
|||
<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> |
|||
<record id="share_b" model="product.product" > |
|||
<field name="name">Acquisition de parts B de Beescoop scrl</field> |
|||
<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="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> |
|||
|
|||
<!-- Share lines --> |
|||
<record id="shareline_coop_1" model="share.line"> |
|||
<field name="share_product_id" ref="share_a"/> |
|||
<field name="share_number">2</field> |
|||
<field name="effective_date">2020-01-01</field> |
|||
<field name="partner_id" |
|||
ref="beesdoo_base.res_partner_cooperator_1_demo"/> |
|||
</record> |
|||
<record id="beesdoo_base.res_partner_cooperator_1_demo" |
|||
model="res.partner"> |
|||
<field name="cooperator" eval="True"/> |
|||
<field name="member" eval="True"/> |
|||
<field name="share_ids" eval="[(4, ref('shareline_coop_1'))]"/> |
|||
<field name="cooperator_type">share_a</field> |
|||
</record> |
|||
|
|||
<record id="shareline_coop_2" model="share.line"> |
|||
<field name="share_product_id" ref="share_b"/> |
|||
<field name="share_number">4</field> |
|||
<field name="effective_date">2020-01-01</field> |
|||
<field name="partner_id" |
|||
ref="beesdoo_base.res_partner_cooperator_2_demo"/> |
|||
</record> |
|||
<record id="beesdoo_base.res_partner_cooperator_2_demo" |
|||
model="res.partner"> |
|||
<field name="cooperator" eval="True"/> |
|||
<field name="member" eval="True"/> |
|||
<field name="share_ids" eval="[(4, ref('shareline_coop_2'))]"/> |
|||
<field name="cooperator_type">share_b</field> |
|||
</record> |
|||
|
|||
<record id="shareline_coop_3" model="share.line"> |
|||
<field name="share_product_id" ref="share_c"/> |
|||
<field name="share_number">6</field> |
|||
<field name="effective_date">2020-01-01</field> |
|||
<field name="partner_id" |
|||
ref="beesdoo_base.res_partner_cooperator_3_demo"/> |
|||
</record> |
|||
<record id="beesdoo_base.res_partner_cooperator_3_demo" |
|||
model="res.partner"> |
|||
<field name="cooperator" eval="True"/> |
|||
<field name="member" eval="True"/> |
|||
<field name="share_ids" eval="[(4, ref('shareline_coop_3'))]"/> |
|||
<field name="cooperator_type">share_c</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,5 @@ |
|||
from . import res_partner |
|||
from . import subscription_request |
|||
from . import res_company |
|||
from . import product |
|||
from . import coop |
@ -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 |
@ -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", |
|||
) |
@ -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." |
|||
)] |
@ -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 |
|||
) |
@ -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 |
@ -0,0 +1 @@ |
|||
from . import test_res_partner |
@ -0,0 +1,205 @@ |
|||
# Copyright 2020 Coop IT Easy SCRLfs (<http://www.coopiteasy.be>) |
|||
# 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) |
@ -0,0 +1,18 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<odoo> |
|||
<record id="product_template_share_form_view_beesdoo_emc" model="ir.ui.view"> |
|||
<field name="name">product.template.share.form</field> |
|||
<field name="model">product.template</field> |
|||
<field name="inherit_id" ref="easy_my_coop.product_template_share_form_view"/> |
|||
<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"> |
|||
<field name="eater" attrs="{'invisible':[('is_share','=',False)]}"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,20 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2019 Coop IT Easy SCRLfs |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<odoo> |
|||
|
|||
<record model="ir.ui.view" id="res_company_form_view"> |
|||
<field name="name">res.company.form (in beesdoo_easy_my_coop)</field> |
|||
<field name="model">res.company</field> |
|||
<field name="inherit_id" ref="easy_my_coop.view_company_inherit_form2"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//group[@name='coop_grp']//field[@name='display_data_policy_approval']" position="before"> |
|||
<field name="display_info_session_confirmation"/> |
|||
<field name="info_session_confirmation_required"/> |
|||
<field name="info_session_confirmation_text"/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
@ -0,0 +1,18 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2019 Coop IT Easy SCRLfs |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<odoo> |
|||
|
|||
<record model="ir.ui.view" id="subscription_request_form_view"> |
|||
<field name="name">subscription.request.form (in beesdoo_easy_my_coop)</field> |
|||
<field name="model">subscription.request</field> |
|||
<field name="inherit_id" ref="easy_my_coop.subscription_request_form"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="data_policy_approved" position="before"> |
|||
<field name="info_session_confirmed"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2019 Coop IT Easy SCRLfs |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<odoo> |
|||
|
|||
<template id="beesdoo_easy_my_coop.becomecooperator" |
|||
name="Become Cooperator (in beesdoo_easy_my_coop)" |
|||
inherit_id="easy_my_coop_website.becomecooperator"> |
|||
<xpath expr="//div[@id='data_policy_approved']" position="before"> |
|||
<div id="info_session_confirmed" t-if="display_info_session" t-attf-class="form-group" > |
|||
<label class="col-md-3 col-sm-4 control-label" for="info_session_confirmed">Info Session</label> |
|||
<div class="col-md-9 col-sm-8"> |
|||
<div class="checkbox"> |
|||
<label for="info_session_confirmed"> |
|||
<input type="checkbox" |
|||
name="info_session_confirmed" |
|||
t-att="{'required': 'required'} if info_session_required else {}" |
|||
t-attf-value="#{data_policy_approved or ''}"/> |
|||
<t t-raw="info_session_text"/> |
|||
</label> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</xpath> |
|||
</template> |
|||
|
|||
</odoo> |
@ -0,0 +1 @@ |
|||
from . import beesdoo_shift_subscribe |
@ -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) |
|||
|
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue