Skip to content

Commit

Permalink
[ADD] product_pricelist_overcharge_by_amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-RB committed Sep 28, 2024
1 parent 3101e0b commit ac9bf06
Show file tree
Hide file tree
Showing 18 changed files with 1,047 additions and 0 deletions.
114 changes: 114 additions & 0 deletions product_pricelist_overcharge_by_amount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
=====================================
Amount overcharge in sales pricelists
=====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:59e13141ec33e51f7acc923989e89fbd639e502e2010c1369aa684ccac6ce261
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/14.0/product_pricelist_overcharge_by_amount
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-14-0/product-attribute-14-0-product_pricelist_overcharge_by_amount
: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/product-attribute&target_branch=14.0
:alt: Try me on Runboat

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

This module allows you to add overcharge amount to sales pricelist based on the price result.
You will be able to create multiple rules/options (just the first match will be applied).
This is usefull when you need to add extra charge base on the actual value computed by the pricelist.
For example, based on the product cost I would like to add and extra margin percentage by ranges. So
with this module you could create a regular pricelist by cost and add the overcharge rules to acomplish this.

**Table of contents**

.. contents::
:local:

Installation
============

Although this module doesn't depend technically on **Sales Management**, you
must install it for configuring and seeing the effects of it.

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

To configure pricelists with the new feature of this module, you need to:

#. Go to *Sales > Configuration > Settings* and check
"Pricelists" option and "Advanced price rules (discounts, formulas)"
after that. You must have correct permissions and you must install
**Sales Management** app (sale) to see these settings.
#. Create or edit a Sales Pricelist at *Sales > Products > Pricelists*.
#. Add or edit a pricelist item and check "Overcharge" option in
the new Overcharge section.
#. This will display a new section to add rules based on the computed price,
it will be check by sequence order and apply just the first match.

Usage
=====

For checking pricelists in action, you can (with `sale` module installed):

#. Go to *Sales > Orders > Quotations*
#. Create or edit a quotation.
#. Add a line.
#. Select a product with the criteria to match the pricelist with overcharge.
#. See the proper price appears in the line.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/product-attribute/issues/new?body=module:%20product_pricelist_overcharge_by_amount%0Aversion:%2014.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
~~~~~~~

* Binhex

Contributors
~~~~~~~~~~~~

* `Binhex <https://www.binhex.cloud/>`_:

* Christian Ramos

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/product-attribute <https://github.com/OCA/product-attribute/tree/14.0/product_pricelist_overcharge_by_amount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_pricelist_overcharge_by_amount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions product_pricelist_overcharge_by_amount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Binhex - Christian Ramos
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Amount overcharge in sales pricelists",
"summary": "Allows to add/substract amount to the final priceslists price",
"version": "14.0.0.1.0",
"category": "Sales",
"website": "https://github.com/OCA/product-attribute",
"author": "Binhex, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["product"],
"data": [
"security/ir.model.access.csv",
"views/product_pricelist_item_views.xml",
],
"installable": True,
}
3 changes: 3 additions & 0 deletions product_pricelist_overcharge_by_amount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import product_pricelist
139 changes: 139 additions & 0 deletions product_pricelist_overcharge_by_amount/models/product_pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Copyright 2024 Binhex - Christian Ramos
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import float_compare, float_round


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

def _compute_price_rule(self, products_qty_partner, date=False, uom_id=False):
"""Apply overcharge to the price when applicable."""
rule_obj = self.env["product.pricelist.item"]
result = super()._compute_price_rule(products_qty_partner, date, uom_id)
for product, _qty, _partner in products_qty_partner:
rule = rule_obj.browse(result[product.id][1])
if rule.overcharge:
for overcharge in rule.overcharge_item_ids:
price = result[product.id][0]
if overcharge.can_be_apply(price):
result[product.id] = (
overcharge.apply_overcharge(price),
rule.id,
)
break
return result


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

overcharge = fields.Boolean(
string="Apply overcharge to the final price",
)
overcharge_item_ids = fields.One2many(
"product.pricelist.overcharge.item",
"item_id",
"Overcharge Items",
help="Only match prices from the selected supplier",
copy=True,
)


class ProductPricelistOverchargeItem(models.Model):
_name = "product.pricelist.overcharge.item"

sequence = fields.Integer(string="Sequence", default=1)
item_id = fields.Many2one(
"product.pricelist.item",
"Pricelist Item",
ondelete="cascade",
)
applied_on = fields.Selection(
[
("allways", "Allways"),
("equal", "Equal than"),
("smaller", "Smaller/Equal than"),
("bigger", "Bigger/Equal than"),
("between", "Between"),
],
"Apply",
default="allways",
required=True,
help="Overcharge applicable on selected option",
)
min_price = fields.Float(
"Min price",
digits="Product Price",
help="Minimal price to apply the overcharge.",
)
max_price = fields.Float(
"Max price",
digits="Product Price",
help="Maximun price to apply the overcharge.",
)
overcharge_surcharge = fields.Float(
"Overcharge Surcharge",
digits="Product Price",
help="Specify the fixed amount to add or subtract(if negative) to the result amount",
)
overcharge_discount = fields.Float("Overcharge Discount", default=0, digits=(16, 2))
currency_id = fields.Many2one(
"res.currency",
"Currency",
readonly=True,
related="item_id.currency_id",
store=True,
)

@api.constrains("min_price", "max_price")
def _check_margin(self):
if any(
overc_item.applied_on == "between"
and overc_item.min_price > overc_item.max_price
for overc_item in self
):
raise ValidationError(
_("The minimum price should be lower than the maximum price.")
)
return True

def can_be_apply(self, price):
"""Check if the overcharge is applicable"""
self.ensure_one()
if hasattr(self, "%s_can_be_apply" % self.applied_on):
return getattr(self, "%s_can_be_apply" % self.applied_on)(price)

def allways_can_be_apply(self, price):
self.ensure_one()
return True

def equal_can_be_apply(self, price):
self.ensure_one()
return float_compare(price, self.min_price, self.currency_id.rounding) == 0

def smaller_can_be_apply(self, price):
self.ensure_one()
return float_compare(price, self.max_price, self.currency_id.rounding) <= 0

def bigger_can_be_apply(self, price):
self.ensure_one()
return float_compare(price, self.min_price, self.currency_id.rounding) >= 0

def between_can_be_apply(self, price):
self.ensure_one()
return (
float_compare(price, self.max_price, self.currency_id.rounding) <= 0
and float_compare(price, self.min_price, self.currency_id.rounding) >= 0
)

def apply_overcharge(self, price):
"""Apply overcharge"""
self.ensure_one()
price = (price - (price * (self.overcharge_discount / 100))) or 0.0
if self.item_id.price_round:
price = float_round(price, precision_rounding=self.item_id.price_round)
price += self.overcharge_surcharge
return price
11 changes: 11 additions & 0 deletions product_pricelist_overcharge_by_amount/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To configure pricelists with the new feature of this module, you need to:

#. Go to *Sales > Configuration > Settings* and check
"Pricelists" option and "Advanced price rules (discounts, formulas)"
after that. You must have correct permissions and you must install
**Sales Management** app (sale) to see these settings.
#. Create or edit a Sales Pricelist at *Sales > Products > Pricelists*.
#. Add or edit a pricelist item and check "Overcharge" option in
the new Overcharge section.
#. This will display a new section to add rules based on the computed price,
it will be check by sequence order and apply just the first match.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Binhex <https://www.binhex.cloud/>`_:

* Christian Ramos
5 changes: 5 additions & 0 deletions product_pricelist_overcharge_by_amount/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module allows you to add overcharge amount to sales pricelist based on the price result.
You will be able to create multiple rules/options (just the first match will be applied).
This is usefull when you need to add extra charge base on the actual value computed by the pricelist.
For example, based on the product cost I would like to add and extra margin percentage by ranges. So
with this module you could create a regular pricelist by cost and add the overcharge rules to acomplish this.
2 changes: 2 additions & 0 deletions product_pricelist_overcharge_by_amount/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Although this module doesn't depend technically on **Sales Management**, you
must install it for configuring and seeing the effects of it.
7 changes: 7 additions & 0 deletions product_pricelist_overcharge_by_amount/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
For checking pricelists in action, you can (with `sale` module installed):

#. Go to *Sales > Orders > Quotations*
#. Create or edit a quotation.
#. Add a line.
#. Select a product with the criteria to match the pricelist with overcharge.
#. See the proper price appears in the line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_pricelist_overcharge_item_user,product.pricelist.overcharge.item.user,model_product_pricelist_overcharge_item,base.group_user,1,0,0,0
access_product_pricelist_overcharge_item_manager,product.pricelist.overcharge.item.manager,model_product_pricelist_overcharge_item,base.group_system,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ac9bf06

Please sign in to comment.