Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16.0 mig cooperator eater #529

Merged
merged 9 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions cooperator_eater/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
==============================
Cooperator Eater Configuration
==============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-beescoop%2FObeesdoo-lightgray.png?logo=github
:target: https://github.com/beescoop/Obeesdoo/tree/12.0/cooperator_eater
:alt: beescoop/Obeesdoo

|badge1| |badge2| |badge3|

- Set new cooperator as eater or worker based on the share configuration
- Add constraint on eaters based on share configuration
- Add eater configuration on share product

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/beescoop/Obeesdoo/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/beescoop/Obeesdoo/issues/new?body=module:%20cooperator_eater%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* BEES coop
* Coop IT Easy SC

Contributors
~~~~~~~~~~~~

* BEES coop
* Coop IT Easy SC

Maintainers
~~~~~~~~~~~

This module is part of the `beescoop/Obeesdoo <https://github.com/beescoop/Obeesdoo/tree/12.0/cooperator_eater>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions cooperator_eater/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions cooperator_eater/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Cooperator Eater Configuration",
"summary": """Eater configuration based on Share product""",
"author": "BEES coop, Coop IT Easy SC",
"website": "https://github.com/beescoop/Obeesdoo",
"category": "Cooperative management",
"version": "16.0.1.0.0",
"depends": [
"eater",
"partner_contact_birthdate",
"cooperator_worker",
],
"data": [
"views/product_template_views.xml",
],
"demo": ["demo/product_share.xml"],
"license": "AGPL-3",
}
10 changes: 10 additions & 0 deletions cooperator_eater/demo/product_share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Share products -->
<record id="cooperator.product_template_share_type_1_demo" model="product.template">
<field name="max_nb_eater_allowed">3</field>
</record>
<record id="cooperator.product_template_share_type_2_demo" model="product.template">
<field name="max_nb_eater_allowed">2</field>
</record>
</odoo>
65 changes: 65 additions & 0 deletions cooperator_eater/i18n/cooperator_eater.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * cooperator_eater
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: cooperator_eater
#: model:ir.model,name:cooperator_eater.model_res_partner
msgid "Contact"
msgstr ""

#. module: cooperator_eater
#: selection:product.template,eater:0
msgid "Eater"
msgstr ""

#. module: cooperator_eater
#: model:ir.model.fields,field_description:cooperator_eater.field_product_product__eater
#: model:ir.model.fields,field_description:cooperator_eater.field_product_template__eater
msgid "Eater/Worker"
msgstr ""

#. module: cooperator_eater
#: model:ir.model.fields,field_description:cooperator_eater.field_product_product__max_nb_eater_allowed
#: model:ir.model.fields,field_description:cooperator_eater.field_product_template__max_nb_eater_allowed
msgid "Max number of eater allowed"
msgstr ""

#. module: cooperator_eater
#: model:ir.model.fields,help:cooperator_eater.field_product_product__max_nb_eater_allowed
#: model:ir.model.fields,help:cooperator_eater.field_product_template__max_nb_eater_allowed
msgid "Maximum number of eater allowed for the owner of the share. A negative value means no maximum."
msgstr ""

#. module: cooperator_eater
#: model:ir.model,name:cooperator_eater.model_product_template
msgid "Product Template"
msgstr ""

#. module: cooperator_eater
#: model:ir.model,name:cooperator_eater.model_subscription_request
msgid "Subscription Request"
msgstr ""

#. module: cooperator_eater
#: selection:product.template,eater:0
msgid "Worker and Eater"
msgstr ""

#. module: cooperator_eater
#: code:addons/cooperator_eater/models/res_partner.py:37
#: code:addons/cooperator_eater/models/res_partner.py:56
#, python-format
msgid "You can only set %d additional eaters per worker"
msgstr ""

72 changes: 72 additions & 0 deletions cooperator_eater/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * cooperator_eater
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.1.1\n"

#. module: cooperator_eater
#: model:ir.model,name:cooperator_eater.model_res_partner
msgid "Contact"
msgstr "Contact"

#. module: cooperator_eater
#: selection:product.template,eater:0
msgid "Eater"
msgstr "Mangeur"

#. module: cooperator_eater
#: model:ir.model.fields,field_description:cooperator_eater.field_product_product__eater
#: model:ir.model.fields,field_description:cooperator_eater.field_product_template__eater
msgid "Eater/Worker"
msgstr "Mangeur/Travailleur"

#. module: cooperator_eater
#: model:ir.model.fields,field_description:cooperator_eater.field_product_product__max_nb_eater_allowed
#: model:ir.model.fields,field_description:cooperator_eater.field_product_template__max_nb_eater_allowed
msgid "Max number of eater allowed"
msgstr "Nombre maximum de mangeurs autorisés"

#. module: cooperator_eater
#: model:ir.model.fields,help:cooperator_eater.field_product_product__max_nb_eater_allowed
#: model:ir.model.fields,help:cooperator_eater.field_product_template__max_nb_eater_allowed
msgid ""
"Maximum number of eater allowed for the owner of the share. A negative value "
"means no maximum."
msgstr ""
"Nombre maximum de mangeurs autorisés pour le propriétaire de l'action. Une "
"valeur négative signifie qu'il n'y a pas de maximum."

#. module: cooperator_eater
#: model:ir.model,name:cooperator_eater.model_product_template
msgid "Product Template"
msgstr "Modèle de produit"

#. module: cooperator_eater
#: model:ir.model,name:cooperator_eater.model_subscription_request
msgid "Subscription Request"
msgstr "Demande d'abonnement"

#. module: cooperator_eater
#: selection:product.template,eater:0
msgid "Worker and Eater"
msgstr "Travailleur et mangeur"

#. module: cooperator_eater
#: code:addons/cooperator_eater/models/res_partner.py:37
#: code:addons/cooperator_eater/models/res_partner.py:56
#, python-format
msgid "You can only set %d additional eaters per worker"
msgstr "Vous ne pouvez mettre que %d mangeurs supplémentaires par travailleur"
3 changes: 3 additions & 0 deletions cooperator_eater/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_template
from . import res_partner
from . import subscription_request
18 changes: 18 additions & 0 deletions cooperator_eater/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import fields, models


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."
),
)
eater = fields.Selection(
[("eater", "Eater"), ("worker_eater", "Worker and Eater")],
string="Eater/Worker",
)
58 changes: 58 additions & 0 deletions cooperator_eater/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2019-2020 Coop IT Easy SC
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import ValidationError


class Partner(models.Model):
_inherit = "res.partner"

def _check_number_of_eaters(self):
"""
This function has been splitted into two functions:
- _check_max_parent_eaters()
- _check_max_child_eaters()
The purpose of this function is to overwrite the function
defined in beesdoo_base/models/partner.py.
"""

@api.constrains("parent_eater_id")
def _check_max_parent_eaters(self):
"""
Check that the parent_eater_id in partner 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
)
28 changes: 28 additions & 0 deletions cooperator_eater/models/subscription_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo import models

_MAJORITY = 18


class SubscriptionRequest(models.Model):
_inherit = "subscription.request"

def get_eater_vals(self, partner, share_product_id):
eater = share_product_id.eater

# if birthdate_date is not set, age is 0 and lower than _MAJORITY
# in that case, the configuration coming from the share product is kept
if partner.is_company or (partner.birthdate_date and partner.age < _MAJORITY):
eater = "eater"

return {"eater": eater}

def validate_subscription_request(self):
self.ensure_one()

invoice = super().validate_subscription_request()[0]
partner = invoice.partner_id

vals = self.get_eater_vals(partner, self.share_product_id)
partner.write(vals)

return invoice
2 changes: 2 additions & 0 deletions cooperator_eater/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* BEES coop
* Coop IT Easy SC
3 changes: 3 additions & 0 deletions cooperator_eater/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Set new cooperator as eater or worker based on the share configuration
- Add constraint on eaters based on share configuration
- Add eater configuration on share product
Loading
Loading