Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions pricelist_price_base_custom/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
=====================================
Pricelist Price Based on Custom Value
=====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b905cf7130515f61ed680c03986fb1acec9887f9745705ea362936433930db54
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/16.0/pricelist_price_base_custom
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-pricelist_price_base_custom
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module add a new "Custom Value" to the list of pricelist base price
options.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

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.

However by default Odoo has only limited options for a pricelist price
base:

- Sales Price
- Cost
- Other Pricelist

Configuration
=============

Create a new one or select an existing pricelist with "Computation" mode
set to "Formula".

In the pricelist:

- Select "Formula" in the "Computation" selector.
- Select "Custom Value" in the "Based on" field.

Usage
=====

This is a technical module which means it's designed to be used as a
part of custom solutions. You need to add your price as
**custom_base_price**\ ​ kwargs key when calling **\_get_product_price**
function of the **product.pricelist** ​model.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Cetmix

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

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.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions pricelist_price_base_custom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
13 changes: 13 additions & 0 deletions pricelist_price_base_custom/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Pricelist Price Based on Custom Value",
"summary": "Use custom value as a base for pricelist calculation.",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"category": "Sales",
"author": "Cetmix, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": ["product"],
}
4 changes: 4 additions & 0 deletions pricelist_price_base_custom/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import product_pricelist_item
from . import product_pricelist
23 changes: 23 additions & 0 deletions pricelist_price_base_custom/models/product_pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models


class Pricelist(models.Model):
_inherit = "product.pricelist"

def _get_product_price(self, product, quantity, uom=None, date=False, **kwargs):
"""
Overridden method to add custom_base_price
to the context of recordset if it
is specified in the kwargs
"""
self = (
self.with_context(custom_base_price=kwargs["custom_base_price"])
if "custom_base_price" in kwargs
else self
)
return super(
Pricelist,
self,
)._get_product_price(product, quantity, uom, date, **kwargs)
24 changes: 24 additions & 0 deletions pricelist_price_base_custom/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


class PricelistItem(models.Model):
_inherit = "product.pricelist.item"

base = fields.Selection(
selection_add=[("custom_value", "Custom Value")],
ondelete={"custom_value": "set default"},
)

def _compute_base_price(self, product, quantity, uom, date, target_currency):
"""
Override to use custom base price if "custom_value"
is selected as rule base and custom_base_price is
passed in context
"""
if self.base == "custom_value":
return self.env.context.get("custom_base_price", 0.0)
return super()._compute_base_price(
product, quantity, uom, date, target_currency
)
6 changes: 6 additions & 0 deletions pricelist_price_base_custom/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Create a new one or select an existing pricelist with "Computation" mode set to "Formula".

In the pricelist:

- Select "Formula" in the "Computation" selector.
- Select "Custom Value" in the "Based on" field.
7 changes: 7 additions & 0 deletions pricelist_price_base_custom/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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.

However by default Odoo has only limited options for a pricelist price base:

- Sales Price
- Cost
- Other Pricelist
1 change: 1 addition & 0 deletions pricelist_price_base_custom/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module add a new "Custom Value" to the list of pricelist base price options.
2 changes: 2 additions & 0 deletions pricelist_price_base_custom/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a technical module which means it's designed to be used as a part of custom solutions.
You need to add your price as **custom_base_price**​ kwargs key when calling **_get_product_price** function of the **product.pricelist** ​model.
Loading