Skip to content

Commit 4ced243

Browse files
dmitriypaulovivs-cetmix
authored andcommitted
[ADD] pricelist_price_base_custom: add module
This is a technical module that makes possible to use custom base_price (e.g. from external sources) in your product prices computation
1 parent 9366a7d commit 4ced243

File tree

15 files changed

+691
-0
lines changed

15 files changed

+691
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
=====================================
2+
Pricelist Price Based on Custom Value
3+
=====================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:b905cf7130515f61ed680c03986fb1acec9887f9745705ea362936433930db54
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
20+
:target: https://github.com/OCA/sale-workflow/tree/16.0/pricelist_price_base_custom
21+
:alt: OCA/sale-workflow
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-pricelist_price_base_custom
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module add a new "Custom Value" to the list of pricelist base price
32+
options.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Use Cases / Context
40+
===================
41+
42+
Sometimes you need to compute sales price based on values obtained from
43+
custom sources. Eg you receive your purchase prices dynamically from a
44+
vendor using API.
45+
46+
However by default Odoo has only limited options for a pricelist price
47+
base:
48+
49+
- Sales Price
50+
- Cost
51+
- Other Pricelist
52+
53+
Configuration
54+
=============
55+
56+
Create a new one or select an existing pricelist with "Computation" mode
57+
set to "Formula".
58+
59+
In the pricelist:
60+
61+
- Select "Formula" in the "Computation" selector.
62+
- Select "Custom Value" in the "Based on" field.
63+
64+
Usage
65+
=====
66+
67+
This is a technical module which means it's designed to be used as a
68+
part of custom solutions. You need to add your price as
69+
**custom_base_price**\ ​ kwargs key when calling **\_get_product_price**
70+
function of the **product.pricelist** ​model.
71+
72+
Bug Tracker
73+
===========
74+
75+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
76+
In case of trouble, please check there if your issue has already been reported.
77+
If you spotted it first, help us to smash it by providing a detailed and welcomed
78+
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20pricelist_price_base_custom%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
79+
80+
Do not contact contributors directly about support or help with technical issues.
81+
82+
Credits
83+
=======
84+
85+
Authors
86+
-------
87+
88+
* Cetmix
89+
90+
Maintainers
91+
-----------
92+
93+
This module is maintained by the OCA.
94+
95+
.. image:: https://odoo-community.org/logo.png
96+
:alt: Odoo Community Association
97+
:target: https://odoo-community.org
98+
99+
OCA, or the Odoo Community Association, is a nonprofit organization whose
100+
mission is to support the collaborative development of Odoo features and
101+
promote its widespread use.
102+
103+
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/pricelist_price_base_custom>`_ project on GitHub.
104+
105+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright (C) 2024 Cetmix OÜ
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from . import models
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (C) 2024 Cetmix OÜ
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Pricelist Price Based on Custom Value",
6+
"summary": "Use custom value as a base for pricelist calculation.",
7+
"version": "16.0.1.0.0",
8+
"license": "AGPL-3",
9+
"category": "Sales",
10+
"author": "Cetmix, Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/sale-workflow",
12+
"depends": ["product"],
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (C) 2024 Cetmix OÜ
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from . import product_pricelist_item
4+
from . import product_pricelist
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (C) 2024 Cetmix OÜ
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from odoo import models
4+
5+
6+
class Pricelist(models.Model):
7+
_inherit = "product.pricelist"
8+
9+
def _get_product_price(self, product, quantity, uom=None, date=False, **kwargs):
10+
"""
11+
Overridden method to add custom_base_price
12+
to the context of recordset if it
13+
is specified in the kwargs
14+
"""
15+
self = (
16+
self.with_context(custom_base_price=kwargs["custom_base_price"])
17+
if "custom_base_price" in kwargs
18+
else self
19+
)
20+
return super(
21+
Pricelist,
22+
self,
23+
)._get_product_price(product, quantity, uom, date, **kwargs)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (C) 2024 Cetmix OÜ
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from odoo import fields, models
4+
5+
6+
class PricelistItem(models.Model):
7+
_inherit = "product.pricelist.item"
8+
9+
base = fields.Selection(
10+
selection_add=[("custom_value", "Custom Value")],
11+
ondelete={"custom_value": "set default"},
12+
)
13+
14+
def _compute_base_price(self, product, quantity, uom, date, target_currency):
15+
"""
16+
Override to use custom base price if "custom_value"
17+
is selected as rule base and custom_base_price is
18+
passed in context
19+
"""
20+
if self.base == "custom_value":
21+
return (
22+
self.env.context["custom_base_price"]
23+
if "custom_base_price" in self.env.context
24+
else 0.0
25+
)
26+
return super()._compute_base_price(
27+
product, quantity, uom, date, target_currency
28+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Create a new one or select an existing pricelist with "Computation" mode set to "Formula".
2+
3+
In the pricelist:
4+
5+
- Select "Formula" in the "Computation" selector.
6+
- Select "Custom Value" in the "Based on" field.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sometimes you need to compute sales price based on values obtained from custom sources. Eg you receive your purchase prices dynamically from a vendor using API.
2+
3+
However by default Odoo has only limited options for a pricelist price base:
4+
5+
- Sales Price
6+
- Cost
7+
- Other Pricelist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module add a new "Custom Value" to the list of pricelist base price options.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a technical module which means it's designed to be used as a part of custom solutions.
2+
You need to add your price as **custom_base_price**​ kwargs key when calling **_get_product_price** function of the **product.pricelist** ​model.

0 commit comments

Comments
 (0)