Skip to content
Open
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
3 changes: 2 additions & 1 deletion cooperator/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
{
"name": "Cooperators",
"summary": "Manage your cooperators",
"version": "16.0.1.2.4",
"version": "16.0.2.0.0",
"depends": [
"account",
"base_iban",
"mail",
"web",
# todo split into cooperator_partner_firstname
"partner_firstname",
"partner_company_type",
# todo split into cooperator partner_contact_birthdate
"partner_contact_birthdate",
# todo split into cooperator_partner_contact_gender
Expand Down
21 changes: 21 additions & 0 deletions cooperator/migrations/16.0.2.0.0/end-legal_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later


def migrate(cr, version):
# remove temp column after l10n modules used it to map the previous values
cr.execute(
"""
ALTER TABLE res_partner
DROP COLUMN legal_form_deprecated;
"""
)

# same operations for subscription_request
cr.execute(
"""
ALTER TABLE subscription_request
DROP COLUMN company_type_deprecated;
"""
)
21 changes: 21 additions & 0 deletions cooperator/migrations/16.0.2.0.0/pre-legal_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later


def migrate(cr, version):
# temp column to keep the values of legal_form after we removed it
cr.execute(
"""
ALTER TABLE res_partner
RENAME COLUMN legal_form to legal_form_deprecated;
"""
)

# same operations for subscription_request
cr.execute(
"""
ALTER TABLE subscription_request
RENAME COLUMN company_type to company_type_deprecated;
"""
)
1 change: 0 additions & 1 deletion cooperator/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def _search_representative_of_member_company(self, operator, value):
subscription_request_ids = fields.One2many(
"subscription.request", "partner_id", string="Subscription request"
)
legal_form = fields.Selection([], string="Legal form")
data_policy_approved = cooperative_membership_field(
"data_policy_approved",
fields.Boolean,
Expand Down
6 changes: 3 additions & 3 deletions cooperator/models/subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ def _compute_subscription_amount(self):
readonly=True,
states={"draft": [("readonly", False)]},
)
company_type = fields.Selection(
[],
partner_company_type_id = fields.Many2one(
"res.partner.company.type",
string="Company type",
readonly=True,
states={"draft": [("readonly", False)]},
Expand Down Expand Up @@ -627,7 +627,7 @@ def get_partner_company_vals(self):
"name": self.company_name,
"is_company": self.is_company,
"company_register_number": self.company_register_number,
"legal_form": self.company_type,
"partner_company_type_id": self.partner_company_type_id.id,
"street": self.address,
"zip": self.zip_code,
"city": self.city,
Expand Down
1 change: 1 addition & 0 deletions cooperator/readme/newsfragments/167.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the ``partner_company_type`` module to define company types instead of using a custom selection field.
30 changes: 14 additions & 16 deletions cooperator/tests/test_cooperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,27 +1426,25 @@ def test_company_type_to_legal_form(self):
is copied to the legal form field of the created partner.
"""
subscription_request_vals = self.get_dummy_company_subscription_requests_vals()
# an existing type cannot be used because they are only defined in
# localization modules.
subscription_request_model = self.env["subscription.request"]
res_partner_model = self.env["res.partner"]
subscription_request_company_type = subscription_request_model._fields[
"company_type"
]
subscription_request_company_types = subscription_request_company_type.selection
subscription_request_company_type.selection = [("dummy_type", "Dummy Type")]
res_partner_legal_form = res_partner_model._fields["legal_form"]
res_partner_legal_forms = res_partner_legal_form.selection
res_partner_legal_form.selection = [("dummy_type", "Dummy Type")]
subscription_request_vals["company_type"] = "dummy_type"
partner_company_type_model = self.env["res.partner.company.type"]
dummy_partner_company_type_id = partner_company_type_model.create(
{
"name": "Dummy Record",
"shortcut": "DR",
}
)
subscription_request_vals[
"partner_company_type_id"
] = dummy_partner_company_type_id.id
subscription_request = subscription_request_model.create(
subscription_request_vals
)
self.validate_subscription_request_and_pay(subscription_request)
self.assertEqual(subscription_request.partner_id.legal_form, "dummy_type")
# restore previous values
subscription_request_company_type.selection = subscription_request_company_types
res_partner_legal_form.selection = res_partner_legal_forms
self.assertEqual(
subscription_request.partner_id.partner_company_type_id,
dummy_partner_company_type_id,
)

def test_cooperator_register_number_sequence_per_company(self):
"""
Expand Down
4 changes: 0 additions & 4 deletions cooperator/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ SPDX-License-Identifier: AGPL-3.0-or-later
name="representative"
attrs="{'invisible': ['|', ('parent_id', '=', False), ('is_company', '=', True)]}"
/>
<field
name="legal_form"
attrs="{'invisible': [('is_company', '=', False)]}"
/>
<field
name="company_register_number"
attrs="{'invisible': [('is_company', '=', False)], 'readonly': [('id', '!=', False)]}"
Expand Down
2 changes: 1 addition & 1 deletion cooperator/views/subscription_request_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
attrs="{'invisible': [('is_company', '=', False)], 'required': [('is_company', '=', True)]}"
/>
<field
name="company_type"
name="partner_company_type_id"
attrs="{'invisible': [('is_company', '=', False)]}"
/>
<field
Expand Down
11 changes: 10 additions & 1 deletion cooperator_website/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===================
Cooperators Website
===================
Expand All @@ -13,7 +17,7 @@ Cooperators Website
.. |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
.. |badge2| image:: https://img.shields.io/badge/license-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-OCA%2Fcooperative-lightgray.png?logo=github
Expand All @@ -36,6 +40,11 @@ shares online.
.. contents::
:local:

Known issues / Roadmap
======================

- Update the available company types in the form when a country has been selected

Changelog
=========

Expand Down
2 changes: 1 addition & 1 deletion cooperator_website/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
"name": "Cooperators Website",
"version": "16.0.1.0.0",
"version": "16.0.2.0.0",
"depends": [
"cooperator",
"website",
Expand Down
36 changes: 20 additions & 16 deletions cooperator_website/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"nb_parts",
"total_parts",
"error_msg",
"company_type",
"partner_company_type_id",
]


Expand Down Expand Up @@ -152,7 +152,7 @@ def get_values_from_user(self, values, is_company):
values["company_register_number"] = partner.company_register_number
values["company_name"] = partner.name
values["company_email"] = partner.email
values["company_type"] = partner.legal_form
values["partner_company_type_id"] = partner.partner_company_type_id.id
# contact person values
representative = partner.get_representative()
values["firstname"] = representative.firstname
Expand Down Expand Up @@ -186,11 +186,19 @@ def fill_values(self, values, is_company, logged, load_from_user=False):
values["is_company"] = "on"
if logged:
values["logged"] = "on"

values["countries"] = self.get_countries()
if company.default_country_id:
country_id = company.default_country_id.id
else:
country_id = company.country_id.id
if not values.get("country_id"):
values["country_id"] = country_id

values["langs"] = self.get_langs()
values["products"] = products
fields_desc = sub_req_obj.sudo().fields_get(["company_type", "gender"])
values["company_types"] = fields_desc["company_type"]["selection"]
values["partner_company_type_ids"] = self.get_company_types(country_id)
fields_desc = sub_req_obj.sudo().fields_get(["gender"])
values["genders"] = fields_desc["gender"]["selection"]
values["company"] = company

Expand All @@ -201,16 +209,6 @@ def fill_values(self, values, is_company, logged, load_from_user=False):
break
if not values.get("share_product_id", False) and products:
values["share_product_id"] = products[0].id
if not values.get("country_id"):
if company.default_country_id:
values["country_id"] = company.default_country_id.id
else:
values["country_id"] = "20"
if not values.get("activities_country_id"):
if company.default_country_id:
values["activities_country_id"] = company.default_country_id.id
else:
values["activities_country_id"] = "20"
if not values.get("lang"):
if company.default_lang_id:
values["lang"] = company.default_lang_id.code
Expand All @@ -236,18 +234,24 @@ def fill_values(self, values, is_company, logged, load_from_user=False):
def get_products_share(self, is_company):
product_obj = request.env["product.template"]
products = product_obj.sudo().get_web_share_products(is_company)

return products

def get_countries(self):
countries = request.env["res.country"].sudo().search([])

return countries

def get_langs(self):
langs = request.env["res.lang"].sudo().search([])
return langs

def get_company_types(self, country_id):
company_types = (
request.env["res.partner.company.type"]
.sudo()
.search([("country_ids", "in", country_id)])
)
return company_types

def get_selected_share(self, kwargs):
prod_obj = request.env["product.template"]
product_id = kwargs.get("share_product_id")
Expand Down
1 change: 1 addition & 0 deletions cooperator_website/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Update the available company types in the form when a country has been selected
1 change: 1 addition & 0 deletions cooperator_website/readme/newsfragments/167.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the ``partner_company_type`` module to define company types instead of using a custom selection field.
Loading
Loading