[FIX] website_sale_aplicoop: Remove redundant string= attributes and fix OCA linting warnings

- Remove redundant string= from 17 field definitions where name matches string value (W8113)
- Convert @staticmethod to instance methods in selection methods for proper self.env._() access
- Fix W8161 (prefer-env-translation) by using self.env._() instead of standalone _()
- Fix W8301/W8115 (translation-not-lazy) by proper placement of % interpolation outside self.env._()
- Remove unused imports of odoo._ from group_order.py and sale_order_extension.py
- All OCA linting warnings in website_sale_aplicoop main models are now resolved

Changes:
- website_sale_aplicoop/models/group_order.py: 21 field definitions cleaned
- website_sale_aplicoop/models/sale_order_extension.py: 5 field definitions cleaned + @staticmethod conversion
- Consistent with OCA standards for addon submission
This commit is contained in:
snt 2026-02-18 17:54:43 +01:00
parent 5c89795e30
commit 6fbc7b9456
73 changed files with 5386 additions and 4354 deletions

View file

@ -1,147 +1,178 @@
# Copyright 2025 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from datetime import datetime, timedelta
from datetime import datetime
from datetime import timedelta
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestMultiCompanyGroupOrder(TransactionCase):
'''Test suite para el soporte multicompañía en group.order.'''
"""Test suite para el soporte multicompañía en group.order."""
def setUp(self):
super().setUp()
# Crear dos compañías
self.company1 = self.env['res.company'].create({
'name': 'Company 1',
})
self.company2 = self.env['res.company'].create({
'name': 'Company 2',
})
self.company1 = self.env["res.company"].create(
{
"name": "Company 1",
}
)
self.company2 = self.env["res.company"].create(
{
"name": "Company 2",
}
)
# Crear grupos en diferentes compañías
self.group1 = self.env['res.partner'].create({
'name': 'Grupo Company 1',
'is_company': True,
'email': 'grupo1@test.com',
'company_id': self.company1.id,
})
self.group1 = self.env["res.partner"].create(
{
"name": "Grupo Company 1",
"is_company": True,
"email": "grupo1@test.com",
"company_id": self.company1.id,
}
)
self.group2 = self.env['res.partner'].create({
'name': 'Grupo Company 2',
'is_company': True,
'email': 'grupo2@test.com',
'company_id': self.company2.id,
})
self.group2 = self.env["res.partner"].create(
{
"name": "Grupo Company 2",
"is_company": True,
"email": "grupo2@test.com",
"company_id": self.company2.id,
}
)
# Crear productos en cada compañía
self.product1 = self.env['product.product'].create({
'name': 'Producto Company 1',
'type': 'consu',
'list_price': 10.0,
'company_id': self.company1.id,
})
self.product1 = self.env["product.product"].create(
{
"name": "Producto Company 1",
"type": "consu",
"list_price": 10.0,
"company_id": self.company1.id,
}
)
self.product2 = self.env['product.product'].create({
'name': 'Producto Company 2',
'type': 'consu',
'list_price': 20.0,
'company_id': self.company2.id,
})
self.product2 = self.env["product.product"].create(
{
"name": "Producto Company 2",
"type": "consu",
"list_price": 20.0,
"company_id": self.company2.id,
}
)
def test_group_order_has_company_id(self):
'''Test que group.order tenga el campo company_id.'''
order = self.env['group.order'].create({
'name': 'Pedido Company 1',
'group_ids': [(6, 0, [self.group1.id])],
'company_id': self.company1.id,
'type': 'regular',
'start_date': datetime.now().date(),
'end_date': (datetime.now() + timedelta(days=7)).date(),
'period': 'weekly',
'pickup_day': '5',
'cutoff_day': '0',
})
"""Test que group.order tenga el campo company_id."""
order = self.env["group.order"].create(
{
"name": "Pedido Company 1",
"group_ids": [(6, 0, [self.group1.id])],
"company_id": self.company1.id,
"type": "regular",
"start_date": datetime.now().date(),
"end_date": (datetime.now() + timedelta(days=7)).date(),
"period": "weekly",
"pickup_day": "5",
"cutoff_day": "0",
}
)
self.assertTrue(order.exists())
self.assertEqual(order.company_id, self.company1)
def test_group_order_default_company(self):
'''Test que company_id por defecto sea la compañía del usuario.'''
"""Test que company_id por defecto sea la compañía del usuario."""
# Crear usuario con compañía específica
user = self.env['res.users'].create({
'name': 'Test User',
'login': 'testuser',
'password': 'test123',
'company_id': self.company1.id,
'company_ids': [(6, 0, [self.company1.id])],
})
user = self.env["res.users"].create(
{
"name": "Test User",
"login": "testuser",
"password": "test123",
"company_id": self.company1.id,
"company_ids": [(6, 0, [self.company1.id])],
}
)
order = self.env['group.order'].with_user(user).create({
'name': 'Pedido Default Company',
'group_ids': [(6, 0, [self.group1.id])],
'type': 'regular',
'start_date': datetime.now().date(),
'end_date': (datetime.now() + timedelta(days=7)).date(),
'period': 'weekly',
'pickup_day': '5',
'cutoff_day': '0',
})
order = (
self.env["group.order"]
.with_user(user)
.create(
{
"name": "Pedido Default Company",
"group_ids": [(6, 0, [self.group1.id])],
"type": "regular",
"start_date": datetime.now().date(),
"end_date": (datetime.now() + timedelta(days=7)).date(),
"period": "weekly",
"pickup_day": "5",
"cutoff_day": "0",
}
)
)
# Verificar que se asignó la compañía del usuario
self.assertEqual(order.company_id, self.company1)
def test_group_order_company_constraint(self):
'''Test que solo grupos de la misma compañía se puedan asignar.'''
"""Test que solo grupos de la misma compañía se puedan asignar."""
# Intentar asignar un grupo de otra compañía
with self.assertRaises(ValidationError):
self.env['group.order'].create({
'name': 'Pedido Mixed Companies',
'group_ids': [(6, 0, [self.group1.id, self.group2.id])],
'company_id': self.company1.id,
'type': 'regular',
'start_date': datetime.now().date(),
'end_date': (datetime.now() + timedelta(days=7)).date(),
'period': 'weekly',
'pickup_day': '5',
'cutoff_day': '0',
})
self.env["group.order"].create(
{
"name": "Pedido Mixed Companies",
"group_ids": [(6, 0, [self.group1.id, self.group2.id])],
"company_id": self.company1.id,
"type": "regular",
"start_date": datetime.now().date(),
"end_date": (datetime.now() + timedelta(days=7)).date(),
"period": "weekly",
"pickup_day": "5",
"cutoff_day": "0",
}
)
def test_group_order_multi_company_filter(self):
'''Test que get_active_orders_for_week() respete company_id.'''
"""Test que get_active_orders_for_week() respete company_id."""
# Crear órdenes en diferentes compañías
order1 = self.env['group.order'].create({
'name': 'Pedido Company 1',
'group_ids': [(6, 0, [self.group1.id])],
'company_id': self.company1.id,
'type': 'regular',
'state': 'open',
'start_date': datetime.now().date(),
'end_date': (datetime.now() + timedelta(days=7)).date(),
'period': 'weekly',
'pickup_day': '5',
'cutoff_day': '0',
})
order1 = self.env["group.order"].create(
{
"name": "Pedido Company 1",
"group_ids": [(6, 0, [self.group1.id])],
"company_id": self.company1.id,
"type": "regular",
"state": "open",
"start_date": datetime.now().date(),
"end_date": (datetime.now() + timedelta(days=7)).date(),
"period": "weekly",
"pickup_day": "5",
"cutoff_day": "0",
}
)
order2 = self.env['group.order'].create({
'name': 'Pedido Company 2',
'group_ids': [(6, 0, [self.group2.id])],
'company_id': self.company2.id,
'type': 'regular',
'state': 'open',
'start_date': datetime.now().date(),
'end_date': (datetime.now() + timedelta(days=7)).date(),
'period': 'weekly',
'pickup_day': '5',
'cutoff_day': '0',
})
order2 = self.env["group.order"].create(
{
"name": "Pedido Company 2",
"group_ids": [(6, 0, [self.group2.id])],
"company_id": self.company2.id,
"type": "regular",
"state": "open",
"start_date": datetime.now().date(),
"end_date": (datetime.now() + timedelta(days=7)).date(),
"period": "weekly",
"pickup_day": "5",
"cutoff_day": "0",
}
)
# Obtener órdenes activas de company1
active_orders = self.env['group.order'].with_context(
allowed_company_ids=[self.company1.id]
).get_active_orders_for_week()
active_orders = (
self.env["group.order"]
.with_context(allowed_company_ids=[self.company1.id])
.get_active_orders_for_week()
)
# Debería contener solo order1
self.assertIn(order1, active_orders)
@ -149,24 +180,28 @@ class TestMultiCompanyGroupOrder(TransactionCase):
# el filtro de compañía correctamente
def test_product_company_isolation(self):
'''Test que los productos de diferentes compañías estén aislados.'''
"""Test que los productos de diferentes compañías estén aislados."""
# Crear categoría para products
category = self.env['product.category'].create({
'name': 'Test Category',
})
category = self.env["product.category"].create(
{
"name": "Test Category",
}
)
order = self.env['group.order'].create({
'name': 'Pedido con Categoría',
'group_ids': [(6, 0, [self.group1.id])],
'category_ids': [(6, 0, [category.id])],
'company_id': self.company1.id,
'type': 'regular',
'start_date': datetime.now().date(),
'end_date': (datetime.now() + timedelta(days=7)).date(),
'period': 'weekly',
'pickup_day': '5',
'cutoff_day': '0',
})
order = self.env["group.order"].create(
{
"name": "Pedido con Categoría",
"group_ids": [(6, 0, [self.group1.id])],
"category_ids": [(6, 0, [category.id])],
"company_id": self.company1.id,
"type": "regular",
"start_date": datetime.now().date(),
"end_date": (datetime.now() + timedelta(days=7)).date(),
"period": "weekly",
"pickup_day": "5",
"cutoff_day": "0",
}
)
self.assertTrue(order.exists())
self.assertEqual(order.company_id, self.company1)