mirror of
https://github.com/bringout/oca-ocb-test.git
synced 2026-04-18 04:02:01 +02:00
Initial commit: Test packages
This commit is contained in:
commit
080accd21c
338 changed files with 32413 additions and 0 deletions
46
odoo-bringout-oca-ocb-test_resource/README.md
Normal file
46
odoo-bringout-oca-ocb-test_resource/README.md
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# Test - Resource
|
||||
|
||||
Odoo addon: test_resource
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install odoo-bringout-oca-ocb-test_resource
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
This addon depends on:
|
||||
- resource
|
||||
|
||||
## Manifest Information
|
||||
|
||||
- **Name**: Test - Resource
|
||||
- **Version**: 1.1
|
||||
- **Category**: Hidden
|
||||
- **License**: LGPL-3
|
||||
- **Installable**: False
|
||||
|
||||
## Source
|
||||
|
||||
Based on [OCA/OCB](https://github.com/OCA/OCB) branch 16.0, addon `test_resource`.
|
||||
|
||||
## License
|
||||
|
||||
This package maintains the original LGPL-3 license from the upstream Odoo project.
|
||||
|
||||
## Documentation
|
||||
|
||||
- Overview: doc/OVERVIEW.md
|
||||
- Architecture: doc/ARCHITECTURE.md
|
||||
- Models: doc/MODELS.md
|
||||
- Controllers: doc/CONTROLLERS.md
|
||||
- Wizards: doc/WIZARDS.md
|
||||
- Reports: doc/REPORTS.md
|
||||
- Security: doc/SECURITY.md
|
||||
- Install: doc/INSTALL.md
|
||||
- Usage: doc/USAGE.md
|
||||
- Configuration: doc/CONFIGURATION.md
|
||||
- Dependencies: doc/DEPENDENCIES.md
|
||||
- Troubleshooting: doc/TROUBLESHOOTING.md
|
||||
- FAQ: doc/FAQ.md
|
||||
32
odoo-bringout-oca-ocb-test_resource/doc/ARCHITECTURE.md
Normal file
32
odoo-bringout-oca-ocb-test_resource/doc/ARCHITECTURE.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Architecture
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
U[Users] -->|HTTP| V[Views and QWeb Templates]
|
||||
V --> C[Controllers]
|
||||
V --> W[Wizards – Transient Models]
|
||||
C --> M[Models and ORM]
|
||||
W --> M
|
||||
M --> R[Reports]
|
||||
DX[Data XML] --> M
|
||||
S[Security – ACLs and Groups] -. enforces .-> M
|
||||
|
||||
subgraph Test_resource Module - test_resource
|
||||
direction LR
|
||||
M:::layer
|
||||
W:::layer
|
||||
C:::layer
|
||||
V:::layer
|
||||
R:::layer
|
||||
S:::layer
|
||||
DX:::layer
|
||||
end
|
||||
|
||||
classDef layer fill:#eef8ff,stroke:#6ea8fe,stroke-width:1px
|
||||
```
|
||||
|
||||
Notes
|
||||
- Views include tree/form/kanban templates and report templates.
|
||||
- Controllers provide website/portal routes when present.
|
||||
- Wizards are UI flows implemented with `models.TransientModel`.
|
||||
- Data XML loads data/demo records; Security defines groups and access.
|
||||
3
odoo-bringout-oca-ocb-test_resource/doc/CONFIGURATION.md
Normal file
3
odoo-bringout-oca-ocb-test_resource/doc/CONFIGURATION.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Configuration
|
||||
|
||||
Refer to Odoo settings for test_resource. Configure related models, access rights, and options as needed.
|
||||
3
odoo-bringout-oca-ocb-test_resource/doc/CONTROLLERS.md
Normal file
3
odoo-bringout-oca-ocb-test_resource/doc/CONTROLLERS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Controllers
|
||||
|
||||
This module does not define custom HTTP controllers.
|
||||
5
odoo-bringout-oca-ocb-test_resource/doc/DEPENDENCIES.md
Normal file
5
odoo-bringout-oca-ocb-test_resource/doc/DEPENDENCIES.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Dependencies
|
||||
|
||||
This addon depends on:
|
||||
|
||||
- [resource](../../odoo-bringout-oca-ocb-resource)
|
||||
4
odoo-bringout-oca-ocb-test_resource/doc/FAQ.md
Normal file
4
odoo-bringout-oca-ocb-test_resource/doc/FAQ.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# FAQ
|
||||
|
||||
- Q: Which Odoo version? A: 16.0 (OCA/OCB packaged).
|
||||
- Q: How to enable? A: Start server with --addon test_resource or install in UI.
|
||||
7
odoo-bringout-oca-ocb-test_resource/doc/INSTALL.md
Normal file
7
odoo-bringout-oca-ocb-test_resource/doc/INSTALL.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Install
|
||||
|
||||
```bash
|
||||
pip install odoo-bringout-oca-ocb-test_resource"
|
||||
# or
|
||||
uv pip install odoo-bringout-oca-ocb-test_resource"
|
||||
```
|
||||
12
odoo-bringout-oca-ocb-test_resource/doc/MODELS.md
Normal file
12
odoo-bringout-oca-ocb-test_resource/doc/MODELS.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Models
|
||||
|
||||
Detected core models and extensions in test_resource.
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class resource_test
|
||||
```
|
||||
|
||||
Notes
|
||||
- Classes show model technical names; fields omitted for brevity.
|
||||
- Items listed under _inherit are extensions of existing models.
|
||||
6
odoo-bringout-oca-ocb-test_resource/doc/OVERVIEW.md
Normal file
6
odoo-bringout-oca-ocb-test_resource/doc/OVERVIEW.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Overview
|
||||
|
||||
Packaged Odoo addon: test_resource. Provides features documented in upstream Odoo 16 under this addon.
|
||||
|
||||
- Source: OCA/OCB 16.0, addon test_resource
|
||||
- License: LGPL-3
|
||||
3
odoo-bringout-oca-ocb-test_resource/doc/REPORTS.md
Normal file
3
odoo-bringout-oca-ocb-test_resource/doc/REPORTS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Reports
|
||||
|
||||
This module does not define custom reports.
|
||||
34
odoo-bringout-oca-ocb-test_resource/doc/SECURITY.md
Normal file
34
odoo-bringout-oca-ocb-test_resource/doc/SECURITY.md
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Security
|
||||
|
||||
Access control and security definitions in test_resource.
|
||||
|
||||
## Access Control Lists (ACLs)
|
||||
|
||||
Model access permissions defined in:
|
||||
- **[ir.model.access.csv](../test_resource/security/ir.model.access.csv)**
|
||||
- 1 model access rules
|
||||
|
||||
## Record Rules
|
||||
|
||||
Row-level security rules defined in:
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph "Security Layers"
|
||||
A[Users] --> B[Groups]
|
||||
B --> C[Access Control Lists]
|
||||
C --> D[Models]
|
||||
B --> E[Record Rules]
|
||||
E --> F[Individual Records]
|
||||
end
|
||||
```
|
||||
|
||||
Security files overview:
|
||||
- **[ir.model.access.csv](../test_resource/security/ir.model.access.csv)**
|
||||
- Model access permissions (CRUD rights)
|
||||
|
||||
Notes
|
||||
- Access Control Lists define which groups can access which models
|
||||
- Record Rules provide row-level security (filter records by user/group)
|
||||
- Security groups organize users and define permission sets
|
||||
- All security is enforced at the ORM level by Odoo
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# Troubleshooting
|
||||
|
||||
- Ensure Python and Odoo environment matches repo guidance.
|
||||
- Check database connectivity and logs if startup fails.
|
||||
- Validate that dependent addons listed in DEPENDENCIES.md are installed.
|
||||
7
odoo-bringout-oca-ocb-test_resource/doc/USAGE.md
Normal file
7
odoo-bringout-oca-ocb-test_resource/doc/USAGE.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Usage
|
||||
|
||||
Start Odoo including this addon (from repo root):
|
||||
|
||||
```bash
|
||||
python3 scripts/nix_odoo_web_server.py --db-name mydb --addon test_resource
|
||||
```
|
||||
3
odoo-bringout-oca-ocb-test_resource/doc/WIZARDS.md
Normal file
3
odoo-bringout-oca-ocb-test_resource/doc/WIZARDS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Wizards
|
||||
|
||||
This module does not include UI wizards.
|
||||
42
odoo-bringout-oca-ocb-test_resource/pyproject.toml
Normal file
42
odoo-bringout-oca-ocb-test_resource/pyproject.toml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
[project]
|
||||
name = "odoo-bringout-oca-ocb-test_resource"
|
||||
version = "16.0.0"
|
||||
description = "Test - Resource - Odoo addon"
|
||||
authors = [
|
||||
{ name = "Ernad Husremovic", email = "hernad@bring.out.ba" }
|
||||
]
|
||||
dependencies = [
|
||||
"odoo-bringout-oca-ocb-resource>=16.0.0",
|
||||
"requests>=2.25.1"
|
||||
]
|
||||
readme = "README.md"
|
||||
requires-python = ">= 3.11"
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Topic :: Office/Business",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
homepage = "https://github.com/bringout/0"
|
||||
repository = "https://github.com/bringout/0"
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.metadata]
|
||||
allow-direct-references = true
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["test_resource"]
|
||||
|
||||
[tool.rye]
|
||||
managed = true
|
||||
dev-dependencies = [
|
||||
"pytest>=8.4.1",
|
||||
]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Test - Resource',
|
||||
'version': '1.1',
|
||||
'category': 'Hidden',
|
||||
'depends': ['resource'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_resource
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResourceTest(models.Model):
|
||||
_description = 'Test Resource Model'
|
||||
_name = 'resource.test'
|
||||
_inherit = ['resource.mixin']
|
||||
|
||||
name = fields.Char()
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_resource_test_all,resource.test.all,model_resource_test,base.group_user,1,1,1,1
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_resource
|
||||
from . import test_performance
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestResourceCommon(TransactionCase):
|
||||
|
||||
@classmethod
|
||||
def _define_calendar(cls, name, attendances, tz):
|
||||
return cls.env['resource.calendar'].create({
|
||||
'name': name,
|
||||
'tz': tz,
|
||||
'attendance_ids': [
|
||||
(0, 0, {
|
||||
'name': '%s_%d' % (name, index),
|
||||
'hour_from': att[0],
|
||||
'hour_to': att[1],
|
||||
'dayofweek': str(att[2]),
|
||||
})
|
||||
for index, att in enumerate(attendances)
|
||||
],
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def _define_calendar_2_weeks(cls, name, attendances, tz):
|
||||
return cls.env['resource.calendar'].create({
|
||||
'name': name,
|
||||
'tz': tz,
|
||||
'two_weeks_calendar': True,
|
||||
'attendance_ids': [
|
||||
(0, 0, {
|
||||
'name': '%s_%d' % (name, index),
|
||||
'hour_from': att[0],
|
||||
'hour_to': att[1],
|
||||
'dayofweek': str(att[2]),
|
||||
'week_type': att[3],
|
||||
'display_type': att[4],
|
||||
'sequence': att[5],
|
||||
})
|
||||
for index, att in enumerate(attendances)
|
||||
],
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestResourceCommon, cls).setUpClass()
|
||||
cls.env.company.resource_calendar_id.tz = "Europe/Brussels"
|
||||
|
||||
# UTC+1 winter, UTC+2 summer
|
||||
cls.calendar_jean = cls._define_calendar('40 Hours', [(8, 16, i) for i in range(5)], 'Europe/Brussels')
|
||||
# UTC+6
|
||||
cls.calendar_patel = cls._define_calendar('38 Hours', sum([((9, 12, i), (13, 17, i)) for i in range(5)], ()), 'Etc/GMT-6')
|
||||
# UTC-8 winter, UTC-7 summer
|
||||
cls.calendar_john = cls._define_calendar('8+12 Hours', [(8, 16, 1), (8, 13, 4), (16, 23, 4)], 'America/Los_Angeles')
|
||||
# UTC+1 winter, UTC+2 summer
|
||||
cls.calendar_jules = cls._define_calendar_2_weeks('Week 1: 30 Hours - Week 2: 16 Hours', [
|
||||
(0, 0, 0, '0', 'line_section', 0), (8, 16, 0, '0', False, 1), (9, 17, 1, '0', False, 2),
|
||||
(0, 0, 0, '1', 'line_section', 10), (8, 16, 0, '1', False, 11), (7, 15, 2, '1', False, 12),
|
||||
(8, 16, 3, '1', False, 13), (10, 16, 4, '1', False, 14)], 'Europe/Brussels')
|
||||
|
||||
cls.calendar_paul = cls._define_calendar('Morning and evening shifts', sum([((2, 7, i), (10, 16, i)) for i in range(5)], ()), 'America/Noronha')
|
||||
|
||||
# Employee is linked to a resource.resource via resource.mixin
|
||||
cls.jean = cls.env['resource.test'].create({
|
||||
'name': 'Jean',
|
||||
'resource_calendar_id': cls.calendar_jean.id,
|
||||
})
|
||||
cls.patel = cls.env['resource.test'].create({
|
||||
'name': 'Patel',
|
||||
'resource_calendar_id': cls.calendar_patel.id,
|
||||
})
|
||||
cls.john = cls.env['resource.test'].create({
|
||||
'name': 'John',
|
||||
'resource_calendar_id': cls.calendar_john.id,
|
||||
})
|
||||
cls.jules = cls.env['resource.test'].create({
|
||||
'name': 'Jules',
|
||||
'resource_calendar_id': cls.calendar_jules.id,
|
||||
})
|
||||
|
||||
cls.paul = cls.env['resource.test'].create({
|
||||
'name': 'Paul',
|
||||
'resource_calendar_id': cls.calendar_paul.id,
|
||||
})
|
||||
|
||||
cls.two_weeks_resource = cls._define_calendar_2_weeks(
|
||||
'Two weeks resource',
|
||||
[
|
||||
(0, 0, 0, '0', 'line_section', 0),
|
||||
(8, 16, 0, '0', False, 1),
|
||||
(8, 16, 1, '0', False, 2),
|
||||
(8, 16, 2, '0', False, 3),
|
||||
(8, 16, 3, '0', False, 4),
|
||||
(8, 16, 4, '0', False, 5),
|
||||
(0, 0, 0, '1', 'line_section', 10),
|
||||
(8, 16, 0, '1', False, 11),
|
||||
(8, 16, 1, '1', False, 12),
|
||||
(8, 16, 2, '1', False, 13),
|
||||
(8, 16, 3, '1', False, 14),
|
||||
(8, 16, 4, '1', False, 15)
|
||||
],
|
||||
'Europe/Brussels'
|
||||
)
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import logging
|
||||
import time
|
||||
import pytz
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo.tests import TransactionCase, warmup
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class TestResourcePerformance(TransactionCase):
|
||||
|
||||
@warmup
|
||||
def test_performance_attendance_intervals_batch(self):
|
||||
# Tests the performance of _attendance_intervals_batch with a batch of 100 resources
|
||||
calendar = self.env['resource.calendar'].create({
|
||||
'name': 'Calendar',
|
||||
})
|
||||
resources = self.env['resource.test'].create([
|
||||
{
|
||||
'name': 'Resource ' + str(i),
|
||||
'resource_calendar_id': calendar.id,
|
||||
}
|
||||
for i in range(100)
|
||||
])
|
||||
with self.assertQueryCount(__system__=1):
|
||||
# Generate attendances for a whole year
|
||||
start = pytz.utc.localize(datetime.now() + relativedelta(month=1, day=1))
|
||||
stop = pytz.utc.localize(datetime.now() + relativedelta(month=12, day=31))
|
||||
start_time = time.time()
|
||||
calendar._attendance_intervals_batch(start, stop, resources=resources)
|
||||
_logger.info('Attendance Intervals Batch (100): --- %s seconds ---', time.time() - start_time)
|
||||
# Before
|
||||
#INFO master test_performance: Attendance Intervals Batch (100): --- 2.0667169094085693 seconds ---
|
||||
#INFO master test_performance: Attendance Intervals Batch (100): --- 2.0868310928344727 seconds ---
|
||||
#INFO master test_performance: Attendance Intervals Batch (100): --- 1.9209258556365967 seconds ---
|
||||
#INFO master test_performance: Attendance Intervals Batch (100): --- 1.9474620819091797 seconds ---
|
||||
# After
|
||||
#INFO master test_performance: Attendance Intervals Batch (100): --- 0.4092371463775635 seconds ---
|
||||
#INFO master test_performance: Attendance Intervals Batch (100): --- 0.3598649501800537 seconds ---
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue