mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-18 04:12:06 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
50
odoo-bringout-oca-ocb-sale_timesheet_margin/README.md
Normal file
50
odoo-bringout-oca-ocb-sale_timesheet_margin/README.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Service Margins in Sales Orders
|
||||
|
||||
|
||||
Allows to compute accurate margin for Service sales.
|
||||
======================================================
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install odoo-bringout-oca-ocb-sale_timesheet_margin
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
This addon depends on:
|
||||
- sale_margin
|
||||
- sale_timesheet
|
||||
|
||||
## Manifest Information
|
||||
|
||||
- **Name**: Service Margins in Sales Orders
|
||||
- **Version**: 1.0
|
||||
- **Category**: Hidden
|
||||
- **License**: LGPL-3
|
||||
- **Installable**: False
|
||||
|
||||
## Source
|
||||
|
||||
Based on [OCA/OCB](https://github.com/OCA/OCB) branch 16.0, addon `sale_timesheet_margin`.
|
||||
|
||||
## 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
|
||||
|
|
@ -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 Sale_timesheet_margin Module - sale_timesheet_margin
|
||||
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.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Configuration
|
||||
|
||||
Refer to Odoo settings for sale_timesheet_margin. Configure related models, access rights, and options as needed.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Controllers
|
||||
|
||||
This module does not define custom HTTP controllers.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Dependencies
|
||||
|
||||
This addon depends on:
|
||||
|
||||
- [sale_margin](../../odoo-bringout-oca-ocb-sale_margin)
|
||||
- [sale_timesheet](../../odoo-bringout-oca-ocb-sale_timesheet)
|
||||
4
odoo-bringout-oca-ocb-sale_timesheet_margin/doc/FAQ.md
Normal file
4
odoo-bringout-oca-ocb-sale_timesheet_margin/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 sale_timesheet_margin or install in UI.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Install
|
||||
|
||||
```bash
|
||||
pip install odoo-bringout-oca-ocb-sale_timesheet_margin"
|
||||
# or
|
||||
uv pip install odoo-bringout-oca-ocb-sale_timesheet_margin"
|
||||
```
|
||||
12
odoo-bringout-oca-ocb-sale_timesheet_margin/doc/MODELS.md
Normal file
12
odoo-bringout-oca-ocb-sale_timesheet_margin/doc/MODELS.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Models
|
||||
|
||||
Detected core models and extensions in sale_timesheet_margin.
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class sale_order_line
|
||||
```
|
||||
|
||||
Notes
|
||||
- Classes show model technical names; fields omitted for brevity.
|
||||
- Items listed under _inherit are extensions of existing models.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Overview
|
||||
|
||||
Packaged Odoo addon: sale_timesheet_margin. Provides features documented in upstream Odoo 16 under this addon.
|
||||
|
||||
- Source: OCA/OCB 16.0, addon sale_timesheet_margin
|
||||
- License: LGPL-3
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Reports
|
||||
|
||||
This module does not define custom reports.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# Security
|
||||
|
||||
This module does not define custom security rules or access controls beyond Odoo defaults.
|
||||
|
||||
Default Odoo security applies:
|
||||
- Base user access through standard groups
|
||||
- Model access inherited from dependencies
|
||||
- No custom row-level security rules
|
||||
|
|
@ -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-sale_timesheet_margin/doc/USAGE.md
Normal file
7
odoo-bringout-oca-ocb-sale_timesheet_margin/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 sale_timesheet_margin
|
||||
```
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Wizards
|
||||
|
||||
This module does not include UI wizards.
|
||||
43
odoo-bringout-oca-ocb-sale_timesheet_margin/pyproject.toml
Normal file
43
odoo-bringout-oca-ocb-sale_timesheet_margin/pyproject.toml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
[project]
|
||||
name = "odoo-bringout-oca-ocb-sale_timesheet_margin"
|
||||
version = "16.0.0"
|
||||
description = "Service Margins in Sales Orders - Bridge module between Sales Margin and Sales Timesheet"
|
||||
authors = [
|
||||
{ name = "Ernad Husremovic", email = "hernad@bring.out.ba" }
|
||||
]
|
||||
dependencies = [
|
||||
"odoo-bringout-oca-ocb-sale_margin>=16.0.0",
|
||||
"odoo-bringout-oca-ocb-sale_timesheet>=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 = ["sale_timesheet_margin"]
|
||||
|
||||
[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,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Service Margins in Sales Orders',
|
||||
'version': '1.0',
|
||||
'summary': 'Bridge module between Sales Margin and Sales Timesheet',
|
||||
'description': """
|
||||
Allows to compute accurate margin for Service sales.
|
||||
======================================================
|
||||
""",
|
||||
'category': 'Hidden',
|
||||
'depends': ['sale_margin', 'sale_timesheet'],
|
||||
'auto_install': True,
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * sale_timesheet_margin
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 16.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-02-06 13:32+0000\n"
|
||||
"PO-Revision-Date: 2024-02-06 13:32+0000\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: sale_timesheet_margin
|
||||
#: model:ir.model,name:sale_timesheet_margin.model_sale_order_line
|
||||
msgid "Sales Order Line"
|
||||
msgstr "Stavka prodajne narudžbe"
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * sale_timesheet_margin
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 16.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-02-06 13:32+0000\n"
|
||||
"PO-Revision-Date: 2024-02-06 13:32+0000\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: sale_timesheet_margin
|
||||
#: model:ir.model,name:sale_timesheet_margin.model_sale_order_line
|
||||
msgid "Sales Order Line"
|
||||
msgstr ""
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import sale_order_line
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, models
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
@api.depends('analytic_line_ids.amount', 'qty_delivered_method')
|
||||
def _compute_purchase_price(self):
|
||||
timesheet_sols = self.filtered(
|
||||
lambda sol: sol.qty_delivered_method == 'timesheet' and not sol.product_id.standard_price
|
||||
)
|
||||
# filter out the sale.order.lines called by this override of _compute_purchase_price for which
|
||||
# we don't want the purchase price to be recomputed. Without filtring out the sale.order.lines
|
||||
# for which the recomputation was triggered by a depency from another override of _compute_purchase_price
|
||||
service_non_timesheet_sols = self.filtered(
|
||||
lambda sol: not sol.is_expense and sol.is_service and
|
||||
sol.product_id.service_policy == 'ordered_prepaid' and sol.state == 'sale'
|
||||
)
|
||||
super(SaleOrderLine, self - timesheet_sols - service_non_timesheet_sols)._compute_purchase_price()
|
||||
if timesheet_sols:
|
||||
group_amount = self.env['account.analytic.line'].read_group(
|
||||
[('so_line', 'in', timesheet_sols.ids), ('project_id', '!=', False)],
|
||||
['so_line', 'amount:sum', 'unit_amount:sum'],
|
||||
['so_line'])
|
||||
mapped_sol_timesheet_amount = {
|
||||
amount['so_line'][0]: -amount['amount'] / amount['unit_amount'] if amount['unit_amount'] else 0.0
|
||||
for amount in group_amount
|
||||
}
|
||||
for line in timesheet_sols:
|
||||
line = line.with_company(line.company_id)
|
||||
product_cost = mapped_sol_timesheet_amount.get(line.id, line.product_id.standard_price)
|
||||
product_uom = line.product_uom or line.product_id.uom_id
|
||||
if product_uom != line.company_id.project_time_mode_id and\
|
||||
product_uom.category_id.id == line.company_id.project_time_mode_id.category_id.id:
|
||||
product_cost = product_uom._compute_quantity(
|
||||
product_cost,
|
||||
line.company_id.project_time_mode_id
|
||||
)
|
||||
line.purchase_price = line._convert_price(product_cost, product_uom)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_sale_timesheet_margin
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.sale_timesheet.tests.common import TestCommonSaleTimesheet
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSaleTimesheetMargin, self).setUp()
|
||||
uom_day_id = self.ref('uom.product_uom_day')
|
||||
self.uom_day = self.env['uom.uom'].browse(uom_day_id)
|
||||
self.product_1 = self.env['product.product'].create({
|
||||
'name': "Service Ordered, create no task, uom day",
|
||||
'list_price': 1.0,
|
||||
'type': 'service',
|
||||
'invoice_policy': 'order',
|
||||
'uom_id': uom_day_id,
|
||||
'uom_po_id': uom_day_id,
|
||||
'default_code': 'SERV-ORDERED-DAY',
|
||||
'service_type': 'timesheet',
|
||||
'service_tracking': 'task_in_project',
|
||||
'project_id': False,
|
||||
'taxes_id': False,
|
||||
})
|
||||
self.employee_manager.hourly_cost = 10
|
||||
|
||||
def test_sale_timesheet_margin(self):
|
||||
""" Test the timesheet cost is reported correctly in sale order line. """
|
||||
sale_order = self.env['sale.order'].create({
|
||||
'name': 'Test_SO0001',
|
||||
'order_line': [
|
||||
Command.create({
|
||||
'product_id': self.product_1.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom': self.uom_day.id,
|
||||
'product_uom_qty': 1.0,
|
||||
})],
|
||||
'partner_id': self.partner_b.id,
|
||||
'partner_invoice_id': self.partner_b.id,
|
||||
'partner_shipping_id': self.partner_b.id,
|
||||
})
|
||||
# Confirm the sales order, create project and task.
|
||||
sale_order.action_confirm()
|
||||
|
||||
# Add timesheet line
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'unit_amount': 2,
|
||||
'employee_id': self.employee_manager.id,
|
||||
'project_id': sale_order.project_ids.id,
|
||||
'task_id': sale_order.order_line.task_id.id,
|
||||
'account_id': self.analytic_account_sale.id,
|
||||
'so_line': sale_order.order_line.id,
|
||||
})
|
||||
sale_order.order_line._compute_purchase_price()
|
||||
# Cost is expressed in SO line uom
|
||||
expected_cost = self.uom_day._compute_quantity(
|
||||
self.employee_manager.hourly_cost,
|
||||
self.env.company.project_time_mode_id
|
||||
)
|
||||
self.assertEqual(sale_order.order_line.purchase_price, expected_cost, "Sale order line cost should be number of working hours on one day * timesheet cost of the employee set on the timesheet linked to the SOL.")
|
||||
|
||||
def test_no_recompute_purchase_price_not_timesheet(self):
|
||||
project = self.env['project.project'].create({
|
||||
'name': "Test",
|
||||
})
|
||||
self.product_1.write({
|
||||
'uom_id': self.ref('uom.product_uom_unit'),
|
||||
'uom_po_id': self.ref('uom.product_uom_unit'),
|
||||
'service_type': 'timesheet',
|
||||
'service_policy': 'ordered_prepaid',
|
||||
'service_tracking': 'task_global_project',
|
||||
'project_id': project.id,
|
||||
'standard_price': 2,
|
||||
})
|
||||
sale_order = self.env['sale.order'].create({
|
||||
'name': 'Test_SO0002',
|
||||
'order_line': [
|
||||
Command.create({
|
||||
'product_id': self.product_1.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom': self.ref('uom.product_uom_unit'),
|
||||
'product_uom_qty': 1.0,
|
||||
})],
|
||||
'partner_id': self.partner_b.id,
|
||||
'partner_invoice_id': self.partner_b.id,
|
||||
'partner_shipping_id': self.partner_b.id,
|
||||
})
|
||||
sale_order.order_line.purchase_price = 3
|
||||
# Confirm the sales order, create project and task.
|
||||
sale_order.action_confirm()
|
||||
|
||||
# Add timesheet line
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line 222',
|
||||
'unit_amount': 2,
|
||||
'amount': 1,
|
||||
'employee_id': self.employee_manager.id,
|
||||
'project_id': project.id,
|
||||
'task_id': sale_order.order_line.task_id.id,
|
||||
'account_id': self.analytic_account_sale.id,
|
||||
'so_line': sale_order.order_line.id,
|
||||
})
|
||||
self.env.flush_all()
|
||||
self.assertEqual(sale_order.order_line.purchase_price, 3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue