Compare commits

...

1 Commits

Author SHA1 Message Date
Vincent Van Rossem 8c4e8089d7 [FIX] b_shift,b_emc,macavrac_base: is_worker computed field 5 years ago
  1. 3
      beesdoo_easy_my_coop/__manifest__.py
  2. 18
      beesdoo_easy_my_coop/models/res_partner.py
  3. 8
      beesdoo_easy_my_coop/tests/test_res_partner.py
  4. 16
      beesdoo_easy_my_coop/views/res_partner.xml
  5. 7
      beesdoo_shift/models/res_partner.py
  6. 3
      beesdoo_shift/views/cooperative_status.xml
  7. 8
      macavrac_base/models/res_partner.py

3
beesdoo_easy_my_coop/__manifest__.py

@ -26,7 +26,8 @@
'views/res_company.xml', 'views/res_company.xml',
'views/subscription_request.xml', 'views/subscription_request.xml',
'views/subscription_templates.xml', 'views/subscription_templates.xml',
'views/product.xml'
'views/product.xml',
'views/res_partner.xml'
], ],
'demo': [ 'demo': [
'demo/product_share.xml', 'demo/product_share.xml',

18
beesdoo_easy_my_coop/models/res_partner.py

@ -12,12 +12,6 @@ class Partner(models.Model):
string="Confirmed presence to info session", string="Confirmed presence to info session",
default=False, default=False,
) )
is_worker = fields.Boolean(
compute="_is_worker",
search="_search_worker",
readonly=True,
related=""
)
def _cooperator_share_type(self): def _cooperator_share_type(self):
""" """
@ -33,12 +27,9 @@ class Partner(models.Model):
return share_type return share_type
@api.depends( @api.depends(
'share_ids',
'share_ids.share_product_id',
'share_ids.share_product_id.default_code',
'share_ids.share_number',
"cooperator_type"
) )
def _is_worker(self):
def _compute_is_worker(self):
""" """
Return True if the partner can participate tho the shift system. Return True if the partner can participate tho the shift system.
This is defined on the share type. This is defined on the share type.
@ -47,13 +38,8 @@ class Partner(models.Model):
share_type = rec._cooperator_share_type() share_type = rec._cooperator_share_type()
if share_type: if share_type:
rec.is_worker = share_type.allow_working rec.is_worker = share_type.allow_working
rec.worker_store = share_type.allow_working
else: else:
rec.is_worker = False rec.is_worker = False
rec.worker_store = False
def _search_worker(self, operator, value):
return [('worker_store', operator, value)]
@api.depends( @api.depends(
"cooperative_status_ids", "cooperative_status_ids",

8
beesdoo_easy_my_coop/tests/test_res_partner.py

@ -143,7 +143,7 @@ class TestResPartner(TransactionCase):
"beesdoo_base.res_partner_cooperator_1_demo" "beesdoo_base.res_partner_cooperator_1_demo"
) )
# Run computed field # Run computed field
coop1._is_worker()
coop1._compute_is_worker()
self.assertEqual(coop1.is_worker, True) self.assertEqual(coop1.is_worker, True)
def test_is_worker_share_b(self): def test_is_worker_share_b(self):
@ -154,7 +154,7 @@ class TestResPartner(TransactionCase):
"beesdoo_base.res_partner_cooperator_2_demo" "beesdoo_base.res_partner_cooperator_2_demo"
) )
# Run computed field # Run computed field
coop2._is_worker()
coop2._compute_is_worker()
self.assertEqual(coop2.is_worker, False) self.assertEqual(coop2.is_worker, False)
def test_search_worker(self): def test_search_worker(self):
@ -169,8 +169,8 @@ class TestResPartner(TransactionCase):
"beesdoo_base.res_partner_cooperator_2_demo" "beesdoo_base.res_partner_cooperator_2_demo"
) )
# Run computed field # Run computed field
coop1._is_worker()
coop2._is_worker()
coop1._compute_is_worker()
coop2._compute_is_worker()
workers = self.env["res.partner"].search([("is_worker", "=", True)]) workers = self.env["res.partner"].search([("is_worker", "=", True)])
self.assertIn(coop1, workers) self.assertIn(coop1, workers)
self.assertNotIn(coop2, workers) self.assertNotIn(coop2, workers)

16
beesdoo_easy_my_coop/views/res_partner.xml

@ -0,0 +1,16 @@
<odoo>
<record model="ir.ui.view" id="super_coop_partner_inherited_view_form">
<field name="name">Partner Super Coop</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="beesdoo_shift.super_coop_partner_inherited_view_form"/>
<field name="priority">50</field>
<field name="arch" type="xml">
<field name="worker_store" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="is_worker" position="attributes">
<attribute name="invisible">0</attribute>
</field>
</field>
</record>
</odoo>

7
beesdoo_shift/models/res_partner.py

@ -13,7 +13,7 @@ class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
worker_store = fields.Boolean(default=False) worker_store = fields.Boolean(default=False)
is_worker = fields.Boolean(related="worker_store", string="Worker", readonly=False)
is_worker = fields.Boolean(string="Worker", compute="_compute_is_worker", store=True)
can_shop = fields.Boolean(string="Is worker allowed to shop?", compute="_compute_can_shop", store=True) 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) 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) super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True)
@ -25,6 +25,11 @@ class ResPartner(models.Model):
extension_start_time = fields.Date(related='cooperative_status_ids.extension_start_time', string="Extension Start Day", 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') subscribed_shift_ids = fields.Many2many('beesdoo.shift.template')
@api.depends("worker_store")
def _compute_is_worker(self):
for rec in self:
rec.is_worker = rec.worker_store
@api.depends("cooperative_status_ids") @api.depends("cooperative_status_ids")
def _compute_can_shop(self): def _compute_can_shop(self):
""" """

3
beesdoo_shift/views/cooperative_status.xml

@ -37,7 +37,8 @@
</header> </header>
</xpath> </xpath>
<xpath expr="//field[@name='type']" position="before"> <xpath expr="//field[@name='type']" position="before">
<field name="is_worker"/>
<field name="worker_store"/>
<field name="is_worker" invisible="1"/>
<field name="can_shop"/> <field name="can_shop"/>
</xpath> </xpath>
<xpath expr="//notebook" position="inside"> <xpath expr="//notebook" position="inside">

8
macavrac_base/models/res_partner.py

@ -28,7 +28,7 @@ class Partner(models.Model):
comment_request = fields.Char(string="Commentaire") comment_request = fields.Char(string="Commentaire")
email_sent = fields.Boolean(string="Email envoyé") email_sent = fields.Boolean(string="Email envoyé")
is_worker = fields.Boolean(compute="_compute_is_worker", search="_search_is_worker", string="is Worker", readonly=True, related="")
is_worker = fields.Boolean(compute="_compute_is_worker", string="is Worker", readonly=True, store=True)
@api.depends('share_qty') @api.depends('share_qty')
@ -41,9 +41,3 @@ class Partner(models.Model):
def _compute_is_worker(self): def _compute_is_worker(self):
for rec in self: for rec in self:
rec.is_worker = rec.cooperator_type == 'share_b' rec.is_worker = rec.cooperator_type == 'share_b'
def _search_is_worker(self, operator, value):
if (operator == '=' and value) or (operator == '!=' and not value):
return [('cooperator_type', '=', 'share_b')]
else:
return [('cooperator_type', '!=', 'share_b')]
Loading…
Cancel
Save