Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] delivery_carrier_combine_price_rule: migration to 16.0 #332

Open
wants to merge 9 commits into
base: 16.0
Choose a base branch
from
69 changes: 69 additions & 0 deletions delivery_carrier_combine_price_rule/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
===================================
Delivery Carrier Combine Price Rule
===================================

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

.. |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-coopiteasy%2Faddons-lightgray.png?logo=github
:target: https://github.com/coopiteasy/addons/tree/16.0/delivery_carrier_combine_price_rule
:alt: coopiteasy/addons

|badge1| |badge2| |badge3|

When adding price rule to a delivery carrier one can chose how price
rule will be combined. By default it's a OR combinaison, meaning it
stops after the first condition that is true and compute the price based
on this rule.

With this module one can chose AND combinaison, meaning it sums the
price for all the price rules in the deliver carrier and it cannot
compute if there is one rule that is not verified.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/addons/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/coopiteasy/addons/issues/new?body=module:%20delivery_carrier_combine_price_rule%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
~~~~~~~

* Coop IT Easy SC

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

* `Coop IT Easy SC, Odoo Community Association (OCA) <https://github.com/OCA/delivery-carrier/tree/12.0/delivery_carrier_combine_price_rule>`_:

* Rémy Taymans

Maintainers
~~~~~~~~~~~

This module is part of the `coopiteasy/addons <https://github.com/coopiteasy/addons/tree/16.0/delivery_carrier_combine_price_rule>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions delivery_carrier_combine_price_rule/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions delivery_carrier_combine_price_rule/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Coop IT Easy SC, Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Delivery Carrier Combine Price Rule",
"summary": """
Chose how to combine price rule on a delivery carrier.""",
"version": "16.0.1.0.0",
"category": "Stock",
"website": "https://github.com/coopiteasy/addons",
"author": "Coop IT Easy SC",
"license": "AGPL-3",
"application": False,
"depends": ["delivery"],
"excludes": [],
"data": ["views/delivery_carrier.xml"],
"demo": ["demo/delivery_carrier.xml"],
"qweb": [],
}
52 changes: 52 additions & 0 deletions delivery_carrier_combine_price_rule/demo/delivery_carrier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 Coop IT Easy SC
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record id="product_product_delivery_and_combined" model="product.product">
<field name="name">AND Combined Delivery</field>
<field name="default_code">Delivery_100</field>
<field name="type">service</field>
<field name="categ_id" ref="delivery.product_category_deliveries" />
<field name="sale_ok" eval="False" />
<field name="purchase_ok" eval="False" />
<field name="list_price">10.0</field>
</record>

<record id="delivery_carrier" model="delivery.carrier">
<field name="name">AND Combined Delivery</field>
<field name="fixed_price">20.0</field>
<field name="sequence">2</field>
<field name="delivery_type">base_on_rule</field>
<field
name="product_id"
ref="delivery_carrier_combine_price_rule.product_product_delivery_and_combined"
/>
<field name="combine_type">and</field>
</record>

<!-- Rule for package under 10kg -->
<record id="delivery_price_rule1" model="delivery.price.rule">
<field
name="carrier_id"
ref="delivery_carrier_combine_price_rule.delivery_carrier"
/>
<field name="operator">&lt;=</field>
<field eval="10" name="max_value" />
<field eval="20" name="list_base_price" />
<field name="variable">weight</field>
</record>

<!-- add fix charge if price more than 1000 -->
<record id="delivery_price_rule2" model="delivery.price.rule">
<field
name="carrier_id"
ref="delivery_carrier_combine_price_rule.delivery_carrier"
/>
<field eval="1000" name="max_value" />
<field name="operator">&gt;=</field>
<field name="variable">price</field>
<field eval="10" name="list_base_price" />
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * delivery_carrier_combine_price_rule
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \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: delivery_carrier_combine_price_rule
#: selection:delivery.carrier,combine_type:0
msgid "AND"
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: model:delivery.carrier,name:delivery_carrier_combine_price_rule.delivery_carrier
#: model:product.product,name:delivery_carrier_combine_price_rule.product_product_delivery_and_combined
#: model:product.template,name:delivery_carrier_combine_price_rule.product_product_delivery_and_combined_product_template
msgid "AND Combined Delivery"
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: code:addons/delivery_carrier_combine_price_rule/models/delivery_carrier.py:52
#, python-format
msgid "At least one price rule does not match this order; delivery cost cannot be computed."
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: model:ir.model.fields,field_description:delivery_carrier_combine_price_rule.field_delivery_carrier__combine_type
msgid "Combine Type"
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: model:ir.model,name:delivery_carrier_combine_price_rule.model_delivery_carrier
msgid "Delivery Methods"
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: selection:delivery.carrier,combine_type:0
msgid "OR (default)"
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: model:ir.model.fields,help:delivery_carrier_combine_price_rule.field_delivery_carrier__combine_type
msgid "OR: compute price based on the first rule that is evaluate true. AND: compute price by summing price for each rule. All rules must be evaluated true else the delivery cannot apply."
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: model:product.product,uom_name:delivery_carrier_combine_price_rule.product_product_delivery_and_combined
#: model:product.template,uom_name:delivery_carrier_combine_price_rule.product_product_delivery_and_combined_product_template
msgid "Unit(s)"
msgstr ""

#. module: delivery_carrier_combine_price_rule
#: model:product.product,weight_uom_name:delivery_carrier_combine_price_rule.product_product_delivery_and_combined
#: model:product.template,weight_uom_name:delivery_carrier_combine_price_rule.product_product_delivery_and_combined_product_template
msgid "kg"
msgstr ""

1 change: 1 addition & 0 deletions delivery_carrier_combine_price_rule/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import delivery_carrier
57 changes: 57 additions & 0 deletions delivery_carrier_combine_price_rule/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2022 Coop IT Easy SC
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, fields, models
from odoo.exceptions import UserError
from odoo.tools.safe_eval import safe_eval


class DeliveryCarrier(models.Model):

_inherit = "delivery.carrier"

combine_type = fields.Selection(
[("or", "OR (default)"), ("and", "AND")],
required=True,
default="or",
help=(
"OR: compute price based on the first rule that is evaluate true. "
"AND: compute price by summing price for each rule. All rules "
"must be evaluated true else the delivery cannot apply."
),
)

def _get_price_from_picking(self, total, weight, volume, quantity):
if self.combine_type == "or":
price = super()._get_price_from_picking(total, weight, volume, quantity)
elif self.combine_type == "and":
price = 0.0
criteria_false = False
price_dict = {
"price": total,
"volume": volume,
"weight": weight,
"wv": volume * weight,
"quantity": quantity,
}
for line in self.price_rule_ids:
test = safe_eval(
line.variable + line.operator + str(line.max_value),
price_dict,
)
if test:
price += (
line.list_base_price
+ line.list_price * price_dict[line.variable_factor]
)
else:
criteria_false = True
break
if criteria_false:
raise UserError(
_(
"At least one price rule does not match this order; "
"delivery cost cannot be computed."
)
)
return price
3 changes: 3 additions & 0 deletions delivery_carrier_combine_price_rule/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Coop IT Easy SC, Odoo Community Association (OCA) <https://github.com/OCA/delivery-carrier/tree/12.0/delivery_carrier_combine_price_rule>`_:

* Rémy Taymans
8 changes: 8 additions & 0 deletions delivery_carrier_combine_price_rule/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
When adding price rule to a delivery carrier one can chose how price
rule will be combined. By default it's a OR combinaison, meaning it
stops after the first condition that is true and compute the price based
on this rule.

With this module one can chose AND combinaison, meaning it sums the
price for all the price rules in the deliver carrier and it cannot
compute if there is one rule that is not verified.
Loading
Loading