Browse Source

Merge pull request #134 from beescoop/12.0-mig-obeesdoo_beesdoo_easy_my_coop

[12.0] [MIG] beesdoo_easy_my_coop
pull/153/head
Rémy Taymans 5 years ago
committed by GitHub
parent
commit
d681fa5d1a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      beesdoo_base/__manifest__.py
  2. 43
      beesdoo_base/demo/eaters.xml
  3. 44
      beesdoo_base/models/partner.py
  4. 20
      beesdoo_base/views/partner.xml
  5. 3
      beesdoo_easy_my_coop/__init__.py
  6. 35
      beesdoo_easy_my_coop/__manifest__.py
  7. 1
      beesdoo_easy_my_coop/controllers/__init__.py
  8. 19
      beesdoo_easy_my_coop/controllers/main.py
  9. 77
      beesdoo_easy_my_coop/demo/product_share.xml
  10. 5
      beesdoo_easy_my_coop/models/__init__.py
  11. 31
      beesdoo_easy_my_coop/models/coop.py
  12. 30
      beesdoo_easy_my_coop/models/product.py
  13. 35
      beesdoo_easy_my_coop/models/res_company.py
  14. 124
      beesdoo_easy_my_coop/models/res_partner.py
  15. 26
      beesdoo_easy_my_coop/models/subscription_request.py
  16. 1
      beesdoo_easy_my_coop/tests/__init__.py
  17. 205
      beesdoo_easy_my_coop/tests/test_res_partner.py
  18. 18
      beesdoo_easy_my_coop/views/product.xml
  19. 20
      beesdoo_easy_my_coop/views/res_company.xml
  20. 18
      beesdoo_easy_my_coop/views/subscription_request.xml
  21. 28
      beesdoo_easy_my_coop/views/subscription_templates.xml
  22. 1
      beesdoo_easy_my_coop/wizards/__init__.py
  23. 24
      beesdoo_easy_my_coop/wizards/beesdoo_shift_subscribe.py
  24. 1
      beesdoo_shift/__manifest__.py
  25. 25
      beesdoo_shift/demo/workers.xml
  26. 1
      beesdoo_shift/models/__init__.py
  27. 78
      beesdoo_shift/models/cooperative_status.py
  28. 98
      beesdoo_shift/models/res_partner.py
  29. 1
      beesdoo_shift/views/cooperative_status.xml
  30. 1
      beesdoo_worker_status/__manifest__.py
  31. 19
      beesdoo_worker_status/models/cooperative_status.py

1
beesdoo_base/__manifest__.py

@ -34,5 +34,6 @@
'installable': True, 'installable': True,
'demo': [ 'demo': [
'demo/cooperators.xml', 'demo/cooperators.xml',
'demo/eaters.xml',
] ]
} }

43
beesdoo_base/demo/eaters.xml

@ -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>

44
beesdoo_base/models/partner.py

@ -12,45 +12,29 @@ class Partner(models.Model):
barcode = fields.Char(compute="_get_bar_code", string='Barcode', store=True) barcode = fields.Char(compute="_get_bar_code", string='Barcode', store=True)
parent_barcode = fields.Char(compute="_get_bar_code", string='Parent 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') 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?') member_card_to_be_printed = fields.Boolean('Print BEES card?')
last_printed = fields.Datetime('Last printed on') 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') @api.depends('parent_eater_id', 'parent_eater_id.barcode', 'eater', 'member_card_ids')
def _get_bar_code(self): 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:
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: 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'))
rec.barcode = c.barcode
@api.multi @api.multi
def write(self, values): 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 # replace many2many command when writing on child_eater_ids to just remove the link
if 'child_eater_ids' in values: if 'child_eater_ids' in values:
for command in values['child_eater_ids']: for command in values['child_eater_ids']:
@ -58,8 +42,8 @@ class Partner(models.Model):
command[0] = 3 command[0] = 3
return super(Partner, self).write(values) return super(Partner, self).write(values)
@api.one
def _deactivate_active_cards(self): def _deactivate_active_cards(self):
self.ensure_one()
for card in self.member_card_ids.filtered('valid'): for card in self.member_card_ids.filtered('valid'):
card.valid = False card.valid = False
card.end_date = fields.Date.today() card.end_date = fields.Date.today()

20
beesdoo_base/views/partner.xml

@ -19,19 +19,12 @@
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="point_of_sale.view_partner_property_form" /> <field name="inherit_id" ref="point_of_sale.view_partner_property_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="type" position="before">
<field name="cooperator_type"/>
</field>
<field name="website" position="after"> <field name="website" position="after">
<field name="eater" <field name="eater"
attrs="{'invisible': [('customer', '=', False)]}" /> attrs="{'invisible': [('customer', '=', False)]}" />
<field name="parent_eater_id" <field name="parent_eater_id"
attrs="{'invisible' : [('eater', '!=', 'eater')]}" /> attrs="{'invisible' : [('eater', '!=', 'eater')]}" />
</field> </field>
<xpath expr="//notebook/page[1]" position="attributes">
<attribute name="attrs">{'invisible':
[('cooperator_type', '=', 'share_a')]}</attribute>
</xpath>
<xpath expr="//notebook" position="inside"> <xpath expr="//notebook" position="inside">
<page string="Member Card" <page string="Member Card"
attrs="{'invisible': ['|', ('customer', '=', False), ('eater', 'not in', ('worker_eater', 'eater'))]}"> attrs="{'invisible': ['|', ('customer', '=', False), ('eater', 'not in', ('worker_eater', 'eater'))]}">
@ -87,19 +80,6 @@
</field> </field>
</record> </record>
<record model="ir.ui.view" id="beesdoo_partner_search_view">
<field name="name">beesdoo.partner.search.view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter name="type_person" position="after">
<filter name="type_a" string="Cooperator type A" domain="[('cooperator_type', '=', 'share_a')]" />
<filter name="type_b" string="Cooperator type B" domain="[('cooperator_type', '=', 'share_b')]" />
<filter name="type_c" string="Cooperator type C" domain="[('cooperator_type', '=', 'share_c')]" />
</filter>
</field>
</record>
<!-- S022 : By default a supplier should be a company --> <!-- S022 : By default a supplier should be a company -->
<record id="base.action_partner_supplier_form" model="ir.actions.act_window"> <record id="base.action_partner_supplier_form" model="ir.actions.act_window">

3
beesdoo_easy_my_coop/__init__.py

@ -0,0 +1,3 @@
from . import models
from . import wizards
from . import controllers

35
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,
}

1
beesdoo_easy_my_coop/controllers/__init__.py

@ -0,0 +1 @@
from . import main

19
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

77
beesdoo_easy_my_coop/demo/product_share.xml

@ -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>

5
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

31
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

30
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",
)

35
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."
)]

124
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
)

26
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

1
beesdoo_easy_my_coop/tests/__init__.py

@ -0,0 +1 @@
from . import test_res_partner

205
beesdoo_easy_my_coop/tests/test_res_partner.py

@ -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)

18
beesdoo_easy_my_coop/views/product.xml

@ -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>

20
beesdoo_easy_my_coop/views/res_company.xml

@ -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>

18
beesdoo_easy_my_coop/views/subscription_request.xml

@ -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>

28
beesdoo_easy_my_coop/views/subscription_templates.xml

@ -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>

1
beesdoo_easy_my_coop/wizards/__init__.py

@ -0,0 +1 @@
from . import beesdoo_shift_subscribe

24
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)

1
beesdoo_shift/__manifest__.py

@ -40,5 +40,6 @@
], ],
'demo': [ 'demo': [
"demo/templates.xml", "demo/templates.xml",
"demo/workers.xml",
] ]
} }

25
beesdoo_worker_status/demo/workers.xml → beesdoo_shift/demo/workers.xml

@ -4,7 +4,8 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<odoo> <odoo>
<record id="beesdoo_shift_cooperative_status_1_demo" model="cooperative.status">
<record id="cooperative_status_1_demo" model="cooperative.status">
<field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_1_demo" /> <field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_1_demo" />
<field name="info_session" eval="True" /> <field name="info_session" eval="True" />
<field name="info_session_date" eval="datetime.now() - timedelta(days=58)" /> <field name="info_session_date" eval="datetime.now() - timedelta(days=58)" />
@ -15,9 +16,11 @@
<record id="beesdoo_base.res_partner_cooperator_1_demo" model="res.partner"> <record id="beesdoo_base.res_partner_cooperator_1_demo" model="res.partner">
<field name="working_mode">regular</field> <field name="working_mode">regular</field>
<field name="is_worker" eval="True"/>
<field name="cooperative_status_ids" eval="[(6, 0, [ref('beesdoo_shift.cooperative_status_1_demo')])]"/>
</record> </record>
<record id="beesdoo_shift_cooperative_status_2_demo" model="cooperative.status">
<record id="cooperative_status_2_demo" model="cooperative.status">
<field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_2_demo" /> <field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_2_demo" />
<field name="info_session" eval="False" /> <field name="info_session" eval="False" />
<field name="sr">2</field> <field name="sr">2</field>
@ -27,9 +30,11 @@
<record id="beesdoo_base.res_partner_cooperator_2_demo" model="res.partner"> <record id="beesdoo_base.res_partner_cooperator_2_demo" model="res.partner">
<field name="working_mode">irregular</field> <field name="working_mode">irregular</field>
<field name="is_worker" eval="True"/>
<field name="cooperative_status_ids" eval="[(6, 0, [ref('beesdoo_shift.cooperative_status_2_demo')])]"/>
</record> </record>
<record id="beesdoo_shift_cooperative_status_3_demo" model="cooperative.status">
<record id="cooperative_status_3_demo" model="cooperative.status">
<field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_3_demo" /> <field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_3_demo" />
<field name="info_session" eval="True" /> <field name="info_session" eval="True" />
<field name="info_session_date" eval="datetime.now() - timedelta(days=98)" /> <field name="info_session_date" eval="datetime.now() - timedelta(days=98)" />
@ -39,9 +44,11 @@
<record id="beesdoo_base.res_partner_cooperator_3_demo" model="res.partner"> <record id="beesdoo_base.res_partner_cooperator_3_demo" model="res.partner">
<field name="working_mode">regular</field> <field name="working_mode">regular</field>
<field name="is_worker" eval="True"/>
<field name="cooperative_status_ids" eval="[(6, 0, [ref('beesdoo_shift.cooperative_status_3_demo')])]"/>
</record> </record>
<record id="beesdoo_shift_cooperative_status_4_demo" model="cooperative.status">
<record id="cooperative_status_4_demo" model="cooperative.status">
<field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_4_demo" /> <field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_4_demo" />
<field name="sr">2</field> <field name="sr">2</field>
<field name="working_mode">irregular</field> <field name="working_mode">irregular</field>
@ -50,9 +57,11 @@
<record id="beesdoo_base.res_partner_cooperator_4_demo" model="res.partner"> <record id="beesdoo_base.res_partner_cooperator_4_demo" model="res.partner">
<field name="working_mode">irregular</field> <field name="working_mode">irregular</field>
<field name="is_worker" eval="True"/>
<field name="cooperative_status_ids" eval="[(6, 0, [ref('beesdoo_shift.cooperative_status_4_demo')])]"/>
</record> </record>
<record id="beesdoo_shift_cooperative_status_5_demo" model="cooperative.status">
<record id="cooperative_status_5_demo" model="cooperative.status">
<field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_5_demo" /> <field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_5_demo" />
<field name="sr">2</field> <field name="sr">2</field>
<field name="working_mode">regular</field> <field name="working_mode">regular</field>
@ -60,9 +69,11 @@
<record id="beesdoo_base.res_partner_cooperator_5_demo" model="res.partner"> <record id="beesdoo_base.res_partner_cooperator_5_demo" model="res.partner">
<field name="working_mode">regular</field> <field name="working_mode">regular</field>
<field name="is_worker" eval="True"/>
<field name="cooperative_status_ids" eval="[(6, 0, [ref('beesdoo_shift.cooperative_status_5_demo')])]"/>
</record> </record>
<record id="beesdoo_shift_cooperative_status_6_demo" model="cooperative.status">
<record id="cooperative_status_6_demo" model="cooperative.status">
<field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_6_demo" /> <field name="cooperator_id" ref="beesdoo_base.res_partner_cooperator_6_demo" />
<field name="info_session" eval="True" /> <field name="info_session" eval="True" />
<field name="info_session_date" eval="datetime.now() - timedelta(days=36)" /> <field name="info_session_date" eval="datetime.now() - timedelta(days=36)" />
@ -72,6 +83,8 @@
<record id="beesdoo_base.res_partner_cooperator_6_demo" model="res.partner"> <record id="beesdoo_base.res_partner_cooperator_6_demo" model="res.partner">
<field name="working_mode">regular</field> <field name="working_mode">regular</field>
<field name="is_worker" eval="True"/>
<field name="cooperative_status_ids" eval="[(6, 0, [ref('beesdoo_shift.cooperative_status_6_demo')])]"/>
</record> </record>
</odoo> </odoo>

1
beesdoo_shift/models/__init__.py

@ -2,3 +2,4 @@
from . import task from . import task
from . import planning from . import planning
from . import cooperative_status from . import cooperative_status
from . import res_partner

78
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'): if not self.user_has_groups('beesdoo_shift.group_cooperative_admin'):
raise ValidationError(_("You don't have the access to perform this action")) raise ValidationError(_("You don't have the access to perform this action"))
self.sudo().env['cooperative.status']._cron_compute_counter_irregular(today=self.date) 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

98
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

1
beesdoo_shift/views/cooperative_status.xml

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

1
beesdoo_worker_status/__manifest__.py

@ -23,7 +23,6 @@
], ],
'demo': [ 'demo': [
"demo/cooperators.xml", "demo/cooperators.xml",
"demo/workers.xml",
"demo/tasks.xml", "demo/tasks.xml",
] ]
} }

19
beesdoo_worker_status/models/cooperative_status.py

@ -263,22 +263,3 @@ class CooperativeStatus(models.Model):
if not delta % self._period: if not delta % self._period:
return today return today
return add_days_delta(today, self._period - (delta % self._period)) return add_days_delta(today, self._period - (delta % self._period))
class ResPartner(models.Model):
_inherit = 'res.partner'
"""
Override is_worker definition
You need have subscribe to a A Share
"""
is_worker = fields.Boolean(compute="_is_worker", search="_search_worker", readonly=True, related="")
def _is_worker(self):
for rec in self:
rec.is_worker = rec.cooperator_type == 'share_a'
def _search_worker(self, operator, value):
if (operator == '=' and value) or (operator == '!=' and not value):
return [('cooperator_type', '=', 'share_a')]
else:
return [('cooperator_type', '!=', 'share_a')]
Loading…
Cancel
Save