Skip to content

Commit

Permalink
[MIG] cooperator_worker: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkeunen committed Oct 12, 2023
1 parent 0218e6e commit 854ed16
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 104 deletions.
2 changes: 1 addition & 1 deletion cooperator_worker/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "BEES coop, Coop IT Easy SC",
"website": "https://github.com/beescoop/Obeesdoo",
"category": "Cooperative management",
"version": "12.0.2.0.1",
"version": "16.0.1.0.0",
"depends": [
"shift",
"cooperator",
Expand Down
21 changes: 2 additions & 19 deletions cooperator_worker/demo/product_share.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Share products -->
<record id="share_a" model="product.product">
<field name="name">Share A</field>
<field name="default_code">share_a</field>
<field name="customer" eval="True" />
<record id="cooperator.product_template_share_type_1_demo" model="product.template">
<field name="allow_working" eval="True" />
<field name="allow_shopping" eval="True" />
<field name="is_share" eval="True" />
</record>
<record id="share_b" model="product.product">
<field name="name">Share B</field>
<field name="default_code">share_b</field>
<field name="customer" eval="True" />
<record id="cooperator.product_template_share_type_2_demo" model="product.template">
<field name="allow_working" eval="False" />
<field name="allow_shopping" eval="True" />
<field name="is_share" eval="True" />
</record>
<record id="share_c" model="product.product">
<field name="name">Share C</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="is_share" eval="True" />
</record>

</odoo>
1 change: 1 addition & 0 deletions cooperator_worker/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _compute_is_worker(self):
"""
for rec in self:
share_type = rec._cooperator_share_type()
# rec.is_worker = share_type and share_type.allow_working
if share_type:
rec.is_worker = share_type.allow_working
else:
Expand Down
82 changes: 19 additions & 63 deletions cooperator_worker/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,43 @@
# Copyright 2020 Coop IT Easy SCRLfs (<http://www.coopiteasy.be>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from datetime import date

from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase

from odoo.addons.cooperator.tests.cooperator_test_mixin import CooperatorTestMixin

class TestWorkerBase(SavepointCase):

class TestWorkerBase(TransactionCase, CooperatorTestMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.set_up_cooperator_test_data()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
product_product_obj = cls.env["product.product"]
share_line_obj = cls.env["share.line"]

cls.share_x = product_product_obj.create(
cls.share_x.write(
{
"name": "Share X",
"default_code": "share_x",
"customer": True,
"allow_working": True,
"allow_shopping": True,
"is_share": True,
}
)
cls.share_y = product_product_obj.create(
cls.share_y.write(
{
"name": "Share Y",
"default_code": "share_y",
"customer": True,
"allow_working": False,
"allow_shopping": True,
"is_share": True,
}
)
cls.share_z = product_product_obj.create(
{
"name": "Share C",
"default_code": "share_z",
"customer": True,
"allow_working": False,
"allow_shopping": False,
"is_share": True,
}
)

cls.cooperator_x = cls.env["res.partner"].create(
{
"name": "cooperator 1",
}
)
cls.cooperator_y = cls.env["res.partner"].create(
{
"name": "cooperator 2",
}
)
cls.cooperator_z = cls.env["res.partner"].create(
{
"name": "cooperator 3",
}
cls.cooperator_x = cls.env["res.partner"].create({"name": "cooperator y"})
sr_share_x_vals = cls.get_dummy_subscription_requests_vals(
partner_id=cls.cooperator_x.id,
share_product_id=cls.share_x.id,
)
sr_share_x = cls.env["subscription.request"].create(sr_share_x_vals)
cls.validate_subscription_request_and_pay(sr_share_x)

cls.share_line_coop_1 = share_line_obj.create(
{
"share_product_id": cls.share_x.id,
"share_number": 2,
"effective_date": date(2020, 1, 1),
"partner_id": cls.cooperator_x.id,
}
)
cls.share_line_coop_2 = share_line_obj.create(
{
"share_product_id": cls.share_y.id,
"share_number": 4,
"effective_date": date(2020, 1, 1),
"partner_id": cls.cooperator_y.id,
}
)
cls.share_line_coop_3 = share_line_obj.create(
{
"share_product_id": cls.share_z.id,
"share_number": 6,
"effective_date": date(2020, 1, 1),
"partner_id": cls.cooperator_z.id,
}
cls.cooperator_y = cls.env["res.partner"].create({"name": "cooperator y"})
sr_share_y_vals = cls.get_dummy_subscription_requests_vals(
partner_id=cls.cooperator_y.id,
share_product_id=cls.share_y.id,
)
sr_share_y = cls.env["subscription.request"].create(sr_share_y_vals)
cls.validate_subscription_request_and_pay(sr_share_y)
11 changes: 0 additions & 11 deletions cooperator_worker/tests/test_workers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2020 Coop IT Easy SCRLfs (<http://www.coopiteasy.be>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


from . import test_base


Expand Down Expand Up @@ -47,19 +46,9 @@ def test_compute_can_shop_share_x(self):
"sr": 2,
}
)
# fixme why is cooperative_status_ids not set automatically by Odoo's ORM ?
self.assertFalse(self.cooperator_x.cooperative_status_ids)
self.cooperator_x.cooperative_status_ids = cooperative_status
self.assertTrue(self.cooperator_x.cooperative_status_ids)
self.assertEqual(self.cooperator_x.can_shop, True)

# Now unsubscribe the coop
cooperative_status.status = "resigning"
self.assertEqual(cooperative_status.can_shop, False)
self.assertEqual(self.cooperator_x.can_shop, False)

def test_compute_can_shop_share_z(self):
"""
Test that a cooperator can shop based on his share type.
"""
self.assertEqual(self.cooperator_z.can_shop, False)
22 changes: 12 additions & 10 deletions cooperator_worker/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
<field name="model">product.template</field>
<field name="inherit_id" ref="cooperator.product_template_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>
<group name="configuration" position="after">
<group name="shifts" string="Shift">
<field
name="allow_working"
attrs="{'invisible':[('is_share','=',False)]}"
/>
<field
name="allow_shopping"
attrs="{'invisible':[('is_share','=',False)]}"
/>
</group>
</group>
</field>
</record>
</odoo>

0 comments on commit 854ed16

Please sign in to comment.