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
47
odoo-bringout-oca-ocb-sale_stock_margin/README.md
Normal file
47
odoo-bringout-oca-ocb-sale_stock_margin/README.md
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Sale Stock Margin
|
||||
|
||||
Once the delivery is validated, update the cost on the SO to have an exact margin computation.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install odoo-bringout-oca-ocb-sale_stock_margin
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
This addon depends on:
|
||||
- sale_stock
|
||||
- sale_margin
|
||||
|
||||
## Manifest Information
|
||||
|
||||
- **Name**: Sale Stock Margin
|
||||
- **Version**: 0.1
|
||||
- **Category**: Sales/Sales
|
||||
- **License**: LGPL-3
|
||||
- **Installable**: True
|
||||
|
||||
## Source
|
||||
|
||||
Based on [OCA/OCB](https://github.com/OCA/OCB) branch 16.0, addon `sale_stock_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
|
||||
32
odoo-bringout-oca-ocb-sale_stock_margin/doc/ARCHITECTURE.md
Normal file
32
odoo-bringout-oca-ocb-sale_stock_margin/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 Sale_stock_margin Module - sale_stock_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_stock_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_stock](../../odoo-bringout-oca-ocb-sale_stock)
|
||||
- [sale_margin](../../odoo-bringout-oca-ocb-sale_margin)
|
||||
4
odoo-bringout-oca-ocb-sale_stock_margin/doc/FAQ.md
Normal file
4
odoo-bringout-oca-ocb-sale_stock_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_stock_margin or install in UI.
|
||||
7
odoo-bringout-oca-ocb-sale_stock_margin/doc/INSTALL.md
Normal file
7
odoo-bringout-oca-ocb-sale_stock_margin/doc/INSTALL.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Install
|
||||
|
||||
```bash
|
||||
pip install odoo-bringout-oca-ocb-sale_stock_margin"
|
||||
# or
|
||||
uv pip install odoo-bringout-oca-ocb-sale_stock_margin"
|
||||
```
|
||||
12
odoo-bringout-oca-ocb-sale_stock_margin/doc/MODELS.md
Normal file
12
odoo-bringout-oca-ocb-sale_stock_margin/doc/MODELS.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Models
|
||||
|
||||
Detected core models and extensions in sale_stock_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.
|
||||
6
odoo-bringout-oca-ocb-sale_stock_margin/doc/OVERVIEW.md
Normal file
6
odoo-bringout-oca-ocb-sale_stock_margin/doc/OVERVIEW.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Overview
|
||||
|
||||
Packaged Odoo addon: sale_stock_margin. Provides features documented in upstream Odoo 16 under this addon.
|
||||
|
||||
- Source: OCA/OCB 16.0, addon sale_stock_margin
|
||||
- License: LGPL-3
|
||||
3
odoo-bringout-oca-ocb-sale_stock_margin/doc/REPORTS.md
Normal file
3
odoo-bringout-oca-ocb-sale_stock_margin/doc/REPORTS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Reports
|
||||
|
||||
This module does not define custom reports.
|
||||
8
odoo-bringout-oca-ocb-sale_stock_margin/doc/SECURITY.md
Normal file
8
odoo-bringout-oca-ocb-sale_stock_margin/doc/SECURITY.md
Normal file
|
|
@ -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_stock_margin/doc/USAGE.md
Normal file
7
odoo-bringout-oca-ocb-sale_stock_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_stock_margin
|
||||
```
|
||||
3
odoo-bringout-oca-ocb-sale_stock_margin/doc/WIZARDS.md
Normal file
3
odoo-bringout-oca-ocb-sale_stock_margin/doc/WIZARDS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Wizards
|
||||
|
||||
This module does not include UI wizards.
|
||||
43
odoo-bringout-oca-ocb-sale_stock_margin/pyproject.toml
Normal file
43
odoo-bringout-oca-ocb-sale_stock_margin/pyproject.toml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
[project]
|
||||
name = "odoo-bringout-oca-ocb-sale_stock_margin"
|
||||
version = "16.0.0"
|
||||
description = "Sale Stock Margin - Odoo addon"
|
||||
authors = [
|
||||
{ name = "Ernad Husremovic", email = "hernad@bring.out.ba" }
|
||||
]
|
||||
dependencies = [
|
||||
"odoo-bringout-oca-ocb-sale_stock>=16.0.0",
|
||||
"odoo-bringout-oca-ocb-sale_margin>=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_stock_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,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': "Sale Stock Margin",
|
||||
'category': 'Sales/Sales',
|
||||
'description': 'Once the delivery is validated, update the cost on the SO to have an exact margin computation.',
|
||||
'version': '0.1',
|
||||
'depends': ['sale_stock', 'sale_margin'],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * sale_stock_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_stock_margin
|
||||
#: model:ir.model,name:sale_stock_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_stock_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_stock_margin
|
||||
#: model:ir.model,name:sale_stock_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,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = 'sale.order.line'
|
||||
|
||||
@api.depends('move_ids', 'move_ids.stock_valuation_layer_ids', 'move_ids.picking_id.state')
|
||||
def _compute_purchase_price(self):
|
||||
lines_without_moves = self.browse()
|
||||
for line in self:
|
||||
product = line.product_id.with_company(line.company_id)
|
||||
if not line.move_ids:
|
||||
lines_without_moves |= line
|
||||
elif product.categ_id.property_cost_method != 'standard':
|
||||
purch_price = product._compute_average_price(0, line.product_uom_qty, line.move_ids.with_company(line.company_id))
|
||||
if line.product_uom and line.product_uom != product.uom_id:
|
||||
purch_price = product.uom_id._compute_price(purch_price, line.product_uom)
|
||||
to_cur = line.currency_id or line.order_id.currency_id
|
||||
line.purchase_price = product.cost_currency_id._convert(
|
||||
from_amount=purch_price,
|
||||
to_currency=to_cur,
|
||||
company=line.company_id or self.env.company,
|
||||
date=line.order_id.date_order or fields.Date.today(),
|
||||
round=False,
|
||||
) if to_cur and purch_price else purch_price
|
||||
return super(SaleOrderLine, lines_without_moves)._compute_purchase_price()
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from . import test_sale_stock_margin
|
||||
|
|
@ -0,0 +1,316 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields
|
||||
|
||||
from odoo.tests import Form, tagged
|
||||
from odoo.addons.stock_account.tests.test_stockvaluationlayer import TestStockValuationCommon
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestSaleStockMargin(TestStockValuationCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestSaleStockMargin, cls).setUpClass()
|
||||
cls.pricelist = cls.env['product.pricelist'].create({'name': 'Simple Pricelist'})
|
||||
cls.env['res.currency.rate'].search([]).unlink()
|
||||
|
||||
#########
|
||||
# UTILS #
|
||||
#########
|
||||
|
||||
def _create_sale_order(self):
|
||||
return self.env['sale.order'].create({
|
||||
'name': 'Sale order',
|
||||
'partner_id': self.env.ref('base.partner_admin').id,
|
||||
'partner_invoice_id': self.env.ref('base.partner_admin').id,
|
||||
'pricelist_id': self.pricelist.id,
|
||||
})
|
||||
|
||||
def _create_sale_order_line(self, sale_order, product, quantity, price_unit=0):
|
||||
return self.env['sale.order.line'].create({
|
||||
'name': 'Sale order',
|
||||
'order_id': sale_order.id,
|
||||
'price_unit': price_unit,
|
||||
'product_id': product.id,
|
||||
'product_uom_qty': quantity,
|
||||
'product_uom': self.env.ref('uom.product_uom_unit').id,
|
||||
})
|
||||
|
||||
def _create_product(self):
|
||||
product_template = self.env['product.template'].create({
|
||||
'name': 'Super product',
|
||||
'type': 'product',
|
||||
})
|
||||
product_template.categ_id.property_cost_method = 'fifo'
|
||||
return product_template.product_variant_ids
|
||||
|
||||
#########
|
||||
# TESTS #
|
||||
#########
|
||||
|
||||
def test_sale_stock_margin_1(self):
|
||||
sale_order = self._create_sale_order()
|
||||
product = self._create_product()
|
||||
|
||||
self._make_in_move(product, 2, 35)
|
||||
self._make_out_move(product, 1)
|
||||
|
||||
order_line = self._create_sale_order_line(sale_order, product, 1, 50)
|
||||
sale_order.action_confirm()
|
||||
|
||||
self.assertEqual(order_line.purchase_price, 35)
|
||||
self.assertEqual(sale_order.margin, 15)
|
||||
|
||||
sale_order.picking_ids.move_ids.quantity_done = 1
|
||||
sale_order.picking_ids.button_validate()
|
||||
|
||||
self.assertEqual(order_line.purchase_price, 35)
|
||||
self.assertEqual(order_line.margin, 15)
|
||||
self.assertEqual(sale_order.margin, 15)
|
||||
|
||||
def test_sale_stock_margin_2(self):
|
||||
sale_order = self._create_sale_order()
|
||||
product = self._create_product()
|
||||
|
||||
self._make_in_move(product, 2, 32)
|
||||
self._make_in_move(product, 5, 17)
|
||||
self._make_out_move(product, 1)
|
||||
|
||||
order_line = self._create_sale_order_line(sale_order, product, 2, 50)
|
||||
sale_order.action_confirm()
|
||||
|
||||
self.assertEqual(order_line.purchase_price, 32)
|
||||
self.assertAlmostEqual(sale_order.margin, 36)
|
||||
|
||||
sale_order.picking_ids.move_ids.quantity_done = 2
|
||||
sale_order.picking_ids.button_validate()
|
||||
|
||||
self.assertAlmostEqual(order_line.purchase_price, 24.5)
|
||||
self.assertAlmostEqual(order_line.margin, 51)
|
||||
self.assertAlmostEqual(sale_order.margin, 51)
|
||||
|
||||
def test_sale_stock_margin_3(self):
|
||||
sale_order = self._create_sale_order()
|
||||
product = self._create_product()
|
||||
|
||||
self._make_in_move(product, 2, 10)
|
||||
self._make_out_move(product, 1)
|
||||
|
||||
order_line = self._create_sale_order_line(sale_order, product, 2, 20)
|
||||
sale_order.action_confirm()
|
||||
|
||||
self.assertEqual(order_line.purchase_price, 10)
|
||||
self.assertAlmostEqual(sale_order.margin, 20)
|
||||
|
||||
sale_order.picking_ids.move_ids.quantity_done = 1
|
||||
sale_order.picking_ids.button_validate()
|
||||
|
||||
self.assertAlmostEqual(order_line.purchase_price, 10)
|
||||
self.assertAlmostEqual(order_line.margin, 20)
|
||||
self.assertAlmostEqual(sale_order.margin, 20)
|
||||
|
||||
def test_sale_stock_margin_4(self):
|
||||
sale_order = self._create_sale_order()
|
||||
product = self._create_product()
|
||||
|
||||
self._make_in_move(product, 2, 10)
|
||||
self._make_in_move(product, 1, 20)
|
||||
self._make_out_move(product, 1)
|
||||
|
||||
order_line = self._create_sale_order_line(sale_order, product, 2, 20)
|
||||
sale_order.action_confirm()
|
||||
|
||||
self.assertEqual(order_line.purchase_price, 10)
|
||||
self.assertAlmostEqual(sale_order.margin, 20)
|
||||
|
||||
sale_order.picking_ids.move_ids.quantity_done = 1
|
||||
res = sale_order.picking_ids.button_validate()
|
||||
Form(self.env[res['res_model']].with_context(res['context'])).save().process()
|
||||
|
||||
self.assertAlmostEqual(order_line.purchase_price, 15)
|
||||
self.assertAlmostEqual(order_line.margin, 10)
|
||||
self.assertAlmostEqual(sale_order.margin, 10)
|
||||
|
||||
def test_sale_stock_margin_5(self):
|
||||
sale_order = self._create_sale_order()
|
||||
product_1 = self._create_product()
|
||||
product_2 = self._create_product()
|
||||
|
||||
self._make_in_move(product_1, 2, 35)
|
||||
self._make_in_move(product_1, 1, 51)
|
||||
self._make_out_move(product_1, 1)
|
||||
|
||||
self._make_in_move(product_2, 2, 17)
|
||||
self._make_in_move(product_2, 1, 11)
|
||||
self._make_out_move(product_2, 1)
|
||||
|
||||
order_line_1 = self._create_sale_order_line(sale_order, product_1, 2, 60)
|
||||
order_line_2 = self._create_sale_order_line(sale_order, product_2, 4, 20)
|
||||
sale_order.action_confirm()
|
||||
|
||||
self.assertAlmostEqual(order_line_1.purchase_price, 35)
|
||||
self.assertAlmostEqual(order_line_2.purchase_price, 17)
|
||||
self.assertAlmostEqual(order_line_1.margin, 25 * 2)
|
||||
self.assertAlmostEqual(order_line_2.margin, 3 * 4)
|
||||
self.assertAlmostEqual(sale_order.margin, 62)
|
||||
|
||||
sale_order.picking_ids.move_ids[0].quantity_done = 2
|
||||
sale_order.picking_ids.move_ids[1].quantity_done = 3
|
||||
|
||||
res = sale_order.picking_ids.button_validate()
|
||||
Form(self.env[res['res_model']].with_context(res['context'])).save().process()
|
||||
|
||||
self.assertAlmostEqual(order_line_1.purchase_price, 43) # (35 + 51) / 2
|
||||
self.assertAlmostEqual(order_line_2.purchase_price, 12.5) # (17 + 11 + 11 + 11) / 4
|
||||
self.assertAlmostEqual(order_line_1.margin, 34) # (60 - 43) * 2
|
||||
self.assertAlmostEqual(order_line_2.margin, 30) # (20 - 12.5) * 4
|
||||
self.assertAlmostEqual(sale_order.margin, 64)
|
||||
|
||||
def test_sale_stock_margin_6(self):
|
||||
""" Test that the purchase price doesn't change when there is a service product in the SO"""
|
||||
service = self.env['product.product'].create({
|
||||
'name': 'Service',
|
||||
'type': 'service',
|
||||
'list_price': 100.0,
|
||||
'standard_price': 50.0})
|
||||
self.product1.list_price = 80.0
|
||||
self.product1.standard_price = 40.0
|
||||
sale_order = self._create_sale_order()
|
||||
order_line_1 = self._create_sale_order_line(sale_order, service, 1, 100)
|
||||
order_line_2 = self._create_sale_order_line(sale_order, self.product1, 1, 80)
|
||||
|
||||
self.assertEqual(order_line_1.purchase_price, 50, "Sales order line cost should be 50.00")
|
||||
self.assertEqual(order_line_2.purchase_price, 40, "Sales order line cost should be 40.00")
|
||||
|
||||
self.assertEqual(order_line_1.margin, 50, "Sales order line profit should be 50.00")
|
||||
self.assertEqual(order_line_2.margin, 40, "Sales order line profit should be 40.00")
|
||||
self.assertEqual(sale_order.margin, 90, "Sales order profit should be 90.00")
|
||||
|
||||
# Change the purchase price of the service product.
|
||||
order_line_1.purchase_price = 100.0
|
||||
self.assertEqual(order_line_1.purchase_price, 100, "Sales order line cost should be 100.00")
|
||||
|
||||
# Confirm the sales order.
|
||||
sale_order.action_confirm()
|
||||
|
||||
self.assertEqual(order_line_1.purchase_price, 100, "Sales order line cost should be 100.00")
|
||||
self.assertEqual(order_line_2.purchase_price, 40, "Sales order line cost should be 40.00")
|
||||
|
||||
def test_so_and_multicurrency(self):
|
||||
ResCurrencyRate = self.env['res.currency.rate']
|
||||
company_currency = self.env.company.currency_id
|
||||
other_currency = self.env.ref('base.EUR') if company_currency == self.env.ref('base.USD') else self.env.ref('base.USD')
|
||||
|
||||
date = fields.Date.today()
|
||||
ResCurrencyRate.create({'currency_id': company_currency.id, 'rate': 1, 'name': date})
|
||||
other_currency_rate = ResCurrencyRate.search([('name', '=', date), ('currency_id', '=', other_currency.id)])
|
||||
if other_currency_rate:
|
||||
other_currency_rate.rate = 2
|
||||
else:
|
||||
ResCurrencyRate.create({'currency_id': other_currency.id, 'rate': 2, 'name': date})
|
||||
|
||||
so = self._create_sale_order()
|
||||
so.pricelist_id = self.env['product.pricelist'].create({
|
||||
'name': 'Super Pricelist',
|
||||
'currency_id': other_currency.id,
|
||||
})
|
||||
|
||||
product = self._create_product()
|
||||
product.standard_price = 100
|
||||
product.list_price = 200
|
||||
|
||||
so_form = Form(so)
|
||||
with so_form.order_line.new() as line:
|
||||
line.product_id = product
|
||||
so = so_form.save()
|
||||
so_line = so.order_line
|
||||
|
||||
self.assertEqual(so_line.purchase_price, 200)
|
||||
self.assertEqual(so_line.price_unit, 400)
|
||||
so.action_confirm()
|
||||
self.assertEqual(so_line.purchase_price, 200)
|
||||
self.assertEqual(so_line.price_unit, 400)
|
||||
|
||||
def test_so_and_multicompany(self):
|
||||
""" In a multicompany environnement, when the user is on company C01 and confirms a SO that
|
||||
belongs to a second company C02, this test ensures that the computations will be based on
|
||||
C02's data"""
|
||||
main_company = self.env['res.company']._get_main_company()
|
||||
main_company_currency = main_company.currency_id
|
||||
new_company_currency = self.env.ref('base.EUR') if main_company_currency == self.env.ref('base.USD') else self.env.ref('base.USD')
|
||||
|
||||
date = fields.Date.today()
|
||||
self.env['res.currency.rate'].create([
|
||||
{'currency_id': main_company_currency.id, 'rate': 1, 'name': date, 'company_id': False},
|
||||
{'currency_id': new_company_currency.id, 'rate': 3, 'name': date, 'company_id': False},
|
||||
])
|
||||
|
||||
new_company = self.env['res.company'].create({
|
||||
'name': 'Super Company',
|
||||
'currency_id': new_company_currency.id,
|
||||
})
|
||||
self.env.user.company_id = new_company.id
|
||||
|
||||
self.pricelist.currency_id = new_company_currency.id
|
||||
|
||||
product = self._create_product()
|
||||
|
||||
incoming_picking_type = self.env['stock.picking.type'].search([('company_id', '=', new_company.id), ('code', '=', 'incoming')], limit=1)
|
||||
production_location = self.env['stock.location'].search([('company_id', '=', new_company.id), ('usage', '=', 'production')])
|
||||
|
||||
picking = self.env['stock.picking'].create({
|
||||
'picking_type_id': incoming_picking_type.id,
|
||||
'location_id': production_location.id,
|
||||
'location_dest_id': incoming_picking_type.default_location_dest_id.id,
|
||||
})
|
||||
self.env['stock.move'].create({
|
||||
'name': 'Incoming Product',
|
||||
'product_id': product.id,
|
||||
'location_id': production_location.id,
|
||||
'location_dest_id': incoming_picking_type.default_location_dest_id.id,
|
||||
'product_uom': product.uom_id.id,
|
||||
'product_uom_qty': 1,
|
||||
'price_unit': 100,
|
||||
'picking_type_id': incoming_picking_type.id,
|
||||
'picking_id': picking.id,
|
||||
})
|
||||
picking.action_confirm()
|
||||
res_dict = picking.button_validate()
|
||||
wizard = Form(self.env[(res_dict.get('res_model'))].with_context(res_dict['context'])).save()
|
||||
wizard.process()
|
||||
|
||||
self.pricelist.currency_id = new_company_currency.id
|
||||
partner = self.env['res.partner'].create({'name': 'Super Partner'})
|
||||
so = self.env['sale.order'].create({
|
||||
'name': 'Sale order',
|
||||
'partner_id': partner.id,
|
||||
'partner_invoice_id': partner.id,
|
||||
'pricelist_id': self.pricelist.id,
|
||||
})
|
||||
sol = self._create_sale_order_line(so, product, 1, price_unit=200)
|
||||
|
||||
self.env.user.company_id = main_company.id
|
||||
so.action_confirm()
|
||||
|
||||
self.assertEqual(sol.purchase_price, 100)
|
||||
self.assertEqual(sol.margin, 100)
|
||||
|
||||
def test_purchase_price_changes(self):
|
||||
so = self._create_sale_order()
|
||||
product = self._create_product()
|
||||
product.categ_id.property_cost_method = 'standard'
|
||||
product.standard_price = 20
|
||||
self._create_sale_order_line(so, product, 1, product.list_price)
|
||||
|
||||
so_form = Form(so)
|
||||
with so_form.order_line.edit(0) as line:
|
||||
line.purchase_price = 15
|
||||
so = so_form.save()
|
||||
email_act = so.action_quotation_send()
|
||||
email_ctx = email_act.get('context', {})
|
||||
so.with_context(**email_ctx).message_post_with_template(email_ctx.get('default_template_id'))
|
||||
|
||||
self.assertEqual(so.state, 'sent')
|
||||
self.assertEqual(so.order_line[0].purchase_price, 15)
|
||||
Loading…
Add table
Add a link
Reference in a new issue