Rémy Taymans
5 years ago
9 changed files with 206 additions and 76 deletions
-
5beesdoo_easy_my_coop/__manifest__.py
-
23beesdoo_easy_my_coop/data/product_share.xml
-
74beesdoo_easy_my_coop/demo/product_share.xml
-
16beesdoo_easy_my_coop/models/product.py
-
50beesdoo_easy_my_coop/models/res_partner.py
-
1beesdoo_easy_my_coop/tests/__init__.py
-
78beesdoo_easy_my_coop/tests/test_res_partner.py
-
30beesdoo_easy_my_coop/views/partner.xml
-
5beesdoo_easy_my_coop/views/product.xml
@ -1,23 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<odoo> |
|
||||
<data noupdate="1"> |
|
||||
<record id="share_a" model="product.template" > |
|
||||
<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="is_share" eval="True" /> |
|
||||
</record> |
|
||||
<record id="share_b" model="product.template" > |
|
||||
<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="is_share" eval="True" /> |
|
||||
</record> |
|
||||
<record id="share_c" model="product.template" > |
|
||||
<field name="name">Acquisition de parts C de Beescoop scrl</field> |
|
||||
<field name="default_code">share_c</field> |
|
||||
<field name="customer" eval="False" /> |
|
||||
<field name="is_share" eval="True" /> |
|
||||
</record> |
|
||||
</data> |
|
||||
</odoo> |
|
@ -0,0 +1,74 @@ |
|||||
|
<?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="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="max_nb_eater_allowed">2</field> |
||||
|
<field name="is_share" eval="True" /> |
||||
|
</record> |
||||
|
<record id="share_c" model="product.product" > |
||||
|
<field name="name">Acquisition de parts C de Beescoop scrl</field> |
||||
|
<field name="default_code">share_c</field> |
||||
|
<field name="customer" eval="False" /> |
||||
|
<field name="allow_working" 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> |
@ -1,28 +1,42 @@ |
|||||
from odoo import models, fields, api |
|
||||
|
from odoo import models, fields, api, _ |
||||
|
from odoo.exceptions import ValidationError |
||||
|
|
||||
|
|
||||
class Partner(models.Model): |
class Partner(models.Model): |
||||
_inherit = 'res.partner' |
_inherit = 'res.partner' |
||||
|
|
||||
can_shop = fields.Boolean(compute='_can_shop', store=True) |
|
||||
info_session_confirmed = fields.Boolean( |
info_session_confirmed = fields.Boolean( |
||||
string="Confirmed presence to info session", |
string="Confirmed presence to info session", |
||||
default=False, |
default=False, |
||||
) |
) |
||||
|
|
||||
@api.depends('cooperator_type', |
|
||||
'cooperative_status_ids', |
|
||||
'cooperative_status_ids.can_shop') |
|
||||
def _can_shop(self): |
|
||||
product_obj = self.env['product.template'] |
|
||||
can_shop_shares = product_obj.search([('is_share', '=', True), |
|
||||
('can_shop', '=', True) |
|
||||
]).mapped('default_code') |
|
||||
for rec in self: |
|
||||
if rec.cooperator_type in can_shop_shares: |
|
||||
rec.can_shop = True |
|
||||
elif (rec.cooperative_status_ids |
|
||||
and rec.cooperative_status_ids[0].can_shop): |
|
||||
rec.can_shop = True |
|
||||
else: |
|
||||
rec.can_shop = False |
|
||||
|
@api.constrains('child_eater_ids', 'parent_eater_id') |
||||
|
def _check_number_of_eaters(self): |
||||
|
""" |
||||
|
Check the maximum number of eaters that can be assigned to a |
||||
|
share owner. |
||||
|
""" |
||||
|
self.ensure_one() |
||||
|
share_type = None |
||||
|
if self.cooperator_type: |
||||
|
share_type = ( |
||||
|
self.env['product.template'] |
||||
|
.search([('default_code', '=', self.cooperator_type)]) |
||||
|
)[0] |
||||
|
# If the current partner owns no share, check his parent. |
||||
|
if not share_type: |
||||
|
share_type = ( |
||||
|
self.env['product.template'] |
||||
|
.search([ |
||||
|
('default_code', '=', self.parent_eater_id.cooperator_type) |
||||
|
]) |
||||
|
)[0] |
||||
|
if ( |
||||
|
share_type |
||||
|
and share_type.max_nb_eater_allowed >= 0 |
||||
|
and len(self.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 @@ |
|||||
|
from . import test_res_partner |
@ -0,0 +1,78 @@ |
|||||
|
# 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)) |
||||
|
|
||||
|
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)) |
||||
|
|
||||
|
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)) |
@ -1,30 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<odoo> |
|
||||
<record model="ir.ui.view" id="beesdoo_partner_form_view_remove_duplicate_cooperator_type"> |
|
||||
<field name="name">beesdoo.partner.form.view.remove_duplicate_cooperator_type</field> |
|
||||
<field name="model">res.partner</field> |
|
||||
<field name="inherit_id" ref="beesdoo_base.beesdoo_partner_form_view" /> |
|
||||
<field name="arch" type="xml"> |
|
||||
<field name="cooperator_type" position="replace" /> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record model="ir.ui.view" id="beesdoo_partner_form_view_remove_duplicate_header"> |
|
||||
<field name="name">beesdoo.partner.form.view.remove_duplicate_header</field> |
|
||||
<field name="model">res.partner</field> |
|
||||
<field name="inherit_id" ref="beesdoo_shift.super_coop_partner_inherited_view_form" /> |
|
||||
<field name="arch" type="xml"> |
|
||||
<xpath expr="header" position="replace" /> |
|
||||
<xpath expr="//field[@name='state']" position="before"> |
|
||||
<button string="Create Subscription" name="%(easy_my_coop.action_view_create_subscription)d" |
|
||||
type="action" context="{'default_active_id': active_id}" groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
<button string="Update info" name="%(easy_my_coop.action_view_update_partner_info)d" |
|
||||
type="action" context="{'default_active_id': active_id}" groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
</xpath> |
|
||||
<xpath expr="//field[@name='info_session']" position="before"> |
|
||||
<field name="can_shop" /> |
|
||||
</xpath> |
|
||||
</field> |
|
||||
<field name="priority">99</field> |
|
||||
</record> |
|
||||
</odoo> |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue