diff --git a/sale_margin_delivery_cost/README.rst b/sale_margin_delivery_cost/README.rst new file mode 100644 index 000000000..e483f606c --- /dev/null +++ b/sale_margin_delivery_cost/README.rst @@ -0,0 +1,126 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================================== +Sales Margin after other estimated costs +======================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:93b580f0184d40b8bb5153159fc5efcdadb8c31eba514f1ffa31554189e0ad4a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fmargin--analysis-lightgray.png?logo=github + :target: https://github.com/OCA/margin-analysis/tree/19.0/sale_margin_delivery_cost + :alt: OCA/margin-analysis +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/margin-analysis-19-0/margin-analysis-19-0-sale_margin_delivery_cost + :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/margin-analysis&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Track expected shipping costs, allowing more accurate margin +calculations. + +Costs could include packaging, documentation or customs expenses. These +may be consumables or services, not directly included in sales order +lines nor accounted with the invoice. But we may still ant the Sales +Order margin to consider these costs, especially if business margins are +tight. + +Also allows for carrier shipping costs to be estimated separately, +instead of being automatically added as a sales order line, to charge +the customer. + +This is useful in the case the customer is charge with a shipping fee +that can be very different from the actual shipping cost, or when no +shipping fee is charged at all. + +In this case the expected shipping costs, computed by the UPDATE +SHIPPING COSTS button, can be stored as Other Costs and considered for +the sales order margin, instead being added as a sales order line and +charged to the customer. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +On Shipping Methods there is a field to configure them to be tracked +under Other Costs instead of Sales Order Lines. + +Navigate to *Sales > Configuration > Sales Orders > Shipping Methods*: + +On a *Shipping Method*, set the *Charging Policy* field: + +- "As SO Line" is the standard behaviour +- "As Other Cost" add the cost as *Other Costs* sale order line. + +Usage +===== + +In the Sales Order, add other sales costs in the "Other Costs" field, +after the sales order lines. + +Using the DUPDATE SHIPPING COSTS button will update the estimated cost +in the Other Costs field instead of a sales order line, if the selected +Shipping Method is configured that way. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Open Source Integrators + +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. + +.. |maintainer-dreispt| image:: https://github.com/dreispt.png?size=40px + :target: https://github.com/dreispt + :alt: dreispt + +Current `maintainer `__: + +|maintainer-dreispt| + +This module is part of the `OCA/margin-analysis `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_margin_delivery_cost/__init__.py b/sale_margin_delivery_cost/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sale_margin_delivery_cost/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_margin_delivery_cost/__manifest__.py b/sale_margin_delivery_cost/__manifest__.py new file mode 100644 index 000000000..5834c30b1 --- /dev/null +++ b/sale_margin_delivery_cost/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sales Margin after other estimated costs", + "summary": ( + "See sales margins after other expected costs, such as shipping and delivery" + ), + "version": "19.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/margin-analysis", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "license": "AGPL-3", + "maintainers": ["dreispt"], + "development_status": "Beta", + "depends": ["sale_margin", "delivery"], + "data": [ + "security/ir.model.access.csv", + "views/delivery_carrier.xml", + "views/sale_order.xml", + ], + "installable": True, +} diff --git a/sale_margin_delivery_cost/i18n/sale_margin_delivery_cost.pot b/sale_margin_delivery_cost/i18n/sale_margin_delivery_cost.pot new file mode 100644 index 000000000..a855955c2 --- /dev/null +++ b/sale_margin_delivery_cost/i18n/sale_margin_delivery_cost.pot @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_margin_delivery_cost +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: sale_margin_delivery_cost +#: model:ir.model.fields.selection,name:sale_margin_delivery_cost.selection__delivery_carrier__charge_policy__other +msgid "As Other Cost" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields.selection,name:sale_margin_delivery_cost.selection__delivery_carrier__charge_policy__sale +msgid "As SO Line" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_delivery_carrier__charge_policy +msgid "Charging Policy" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__company_id +msgid "Company" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__price_unit +msgid "Cost" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__create_uid +msgid "Created by" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__create_date +msgid "Created on" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__recompute_delivery_price +msgid "Delivery cost should be recomputed" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__name +msgid "Description" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_delivery_carrier__display_name +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order__display_name +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__display_name +msgid "Display Name" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,help:sale_margin_delivery_cost.field_delivery_carrier__charge_policy +msgid "" +"How shipping costs are added to the sales order: charged in a sales order " +"line, estimated on an other costs line." +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_delivery_carrier__id +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order__id +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__id +msgid "ID" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__is_delivery +msgid "Is a Delivery" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_delivery_carrier____last_update +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order____last_update +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__write_date +msgid "Last Updated on" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order__other_cost_ids +#: model_terms:ir.ui.view,arch_db:sale_margin_delivery_cost.view_order_form_inherit +msgid "Other Costs" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__product_id +msgid "Product" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model,name:sale_margin_delivery_cost.model_sale_order +#: model:ir.model.fields,field_description:sale_margin_delivery_cost.field_sale_order_other_cost__order_id +msgid "Sales Order" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model,name:sale_margin_delivery_cost.model_sale_order_other_cost +msgid "Sales Order Other Cost" +msgstr "" + +#. module: sale_margin_delivery_cost +#: model:ir.model,name:sale_margin_delivery_cost.model_delivery_carrier +msgid "Shipping Methods" +msgstr "" diff --git a/sale_margin_delivery_cost/models/__init__.py b/sale_margin_delivery_cost/models/__init__.py new file mode 100644 index 000000000..d568efbc2 --- /dev/null +++ b/sale_margin_delivery_cost/models/__init__.py @@ -0,0 +1,3 @@ +from . import delivery_carrier +from . import sale_order_other_cost +from . import sale_order diff --git a/sale_margin_delivery_cost/models/delivery_carrier.py b/sale_margin_delivery_cost/models/delivery_carrier.py new file mode 100644 index 000000000..7dbb1587e --- /dev/null +++ b/sale_margin_delivery_cost/models/delivery_carrier.py @@ -0,0 +1,21 @@ +# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class DeliveryCarrier(models.Model): + _inherit = "delivery.carrier" + + charge_policy = fields.Selection( + [ + ("sale", "As SO Line"), + ("other", "As Other Cost"), + ], + string="Charging Policy", + default="sale", + required=True, + help="How shipping costs are added to the sales order:" + " charged in a sales order line, estimated on an other costs line.", + ) diff --git a/sale_margin_delivery_cost/models/sale_order.py b/sale_margin_delivery_cost/models/sale_order.py new file mode 100644 index 000000000..cfaeebabd --- /dev/null +++ b/sale_margin_delivery_cost/models/sale_order.py @@ -0,0 +1,62 @@ +# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + other_cost_ids = fields.One2many( + "sale.order.other.cost", + "order_id", + string="Other Costs", + copy=True, + ) + + @api.depends("order_line.margin", "amount_untaxed", "other_cost_ids.price_unit") + def _compute_margin(self): + super()._compute_margin() + # Subtract other costs from the Sales Order margin + for order in self.filtered("other_cost_ids"): + other_costs = sum(order.mapped("other_cost_ids.price_unit")) + order.margin -= other_costs + order.margin_percent = ( + order.amount_untaxed and order.margin / order.amount_untaxed + ) + return True + + def set_delivery_line(self, carrier, amount): + # Using the UPDATE SHIPPING COST button sets an Other Costs line with the cost, + # instead of a Sales Order line. + # This is because we are not charging this cost to the customer. + # We use it to have a better Sales Order margin calculation. + + # For "sale" charging policy, use standard logic - shipping as an SO line. + # For "other" charging policy, set the delivery cost in the Other Costs field. + if carrier.charge_policy == "sale": + super().set_delivery_line(carrier, amount) + else: + for order in self: + order.carrier_id = carrier.id + carrier_with_partner_lang = carrier.with_context( + lang=self.partner_id.lang + ) + if carrier_with_partner_lang.product_id.description_sale: + so_description = ( + f"{carrier_with_partner_lang.name}: " + f"{carrier_with_partner_lang.product_id.description_sale}" + ) + else: + so_description = carrier_with_partner_lang.name + values = { + "order_id": self.id, + "name": so_description, + "product_id": carrier.product_id.id, + "is_delivery": True, + "price_unit": amount, + } + order.other_cost_ids.filtered("is_delivery").unlink() + order.other_cost_ids.create(values) + return True diff --git a/sale_margin_delivery_cost/models/sale_order_other_cost.py b/sale_margin_delivery_cost/models/sale_order_other_cost.py new file mode 100644 index 000000000..faee2392b --- /dev/null +++ b/sale_margin_delivery_cost/models/sale_order_other_cost.py @@ -0,0 +1,44 @@ +# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class SaleOrderOtherCost(models.Model): + _name = "sale.order.other.cost" + _description = "Sales Order Other Cost" + + order_id = fields.Many2one( + "sale.order", + string="Sales Order", + required=True, + ondelete="cascade", + index=True, + copy=False, + ) + name = fields.Text(string="Description", required=True) + product_id = fields.Many2one( + "product.product", + string="Product", + domain=( + "[('type', 'in', ('consu', 'service')), " + "'|', ('company_id', '=', False), ('company_id', '=', company_id)]" + ), + change_default=True, + ondelete="restrict", + check_company=True, + ) + price_unit = fields.Float("Cost", digits="Product Price") + company_id = fields.Many2one( + related="order_id.company_id", store=True, readonly=True, index=True + ) + is_delivery = fields.Boolean(string="Is a Delivery", default=False) + recompute_delivery_price = fields.Boolean( + related="order_id.recompute_delivery_price" + ) + + @api.onchange("product_id") + def product_id_change(self): + if self.product_id: + self.name = self.product_id.display_name diff --git a/sale_margin_delivery_cost/pyproject.toml b/sale_margin_delivery_cost/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/sale_margin_delivery_cost/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_margin_delivery_cost/readme/CONFIGURE.md b/sale_margin_delivery_cost/readme/CONFIGURE.md new file mode 100644 index 000000000..26ccbdebb --- /dev/null +++ b/sale_margin_delivery_cost/readme/CONFIGURE.md @@ -0,0 +1,9 @@ +On Shipping Methods there is a field to configure them to be +tracked under Other Costs instead of Sales Order Lines. + +Navigate to *Sales > Configuration > Sales Orders > Shipping Methods*: + +On a *Shipping Method*, set the *Charging Policy* field: + + - "As SO Line" is the standard behaviour + - "As Other Cost" add the cost as *Other Costs* sale order line. diff --git a/sale_margin_delivery_cost/readme/DESCRIPTION.md b/sale_margin_delivery_cost/readme/DESCRIPTION.md new file mode 100644 index 000000000..1288d9349 --- /dev/null +++ b/sale_margin_delivery_cost/readme/DESCRIPTION.md @@ -0,0 +1,21 @@ +Track expected shipping costs, allowing more accurate margin +calculations. + +Costs could include packaging, documentation or customs expenses. These +may be consumables or services, not directly included in sales order +lines nor accounted with the invoice. But we may still ant the Sales +Order margin to consider these costs, especially if business margins are +tight. + +Also allows for carrier shipping costs to be estimated separately, +instead of being automatically added as a sales order line, to charge +the customer. + +This is useful in the case the customer is charge with a shipping fee +that can be very different from the actual shipping cost, or when no +shipping fee is charged at all. + +In this case the expected shipping costs, computed by the UPDATE +SHIPPING COSTS button, can be stored as Other Costs and considered for +the sales order margin, instead being added as a sales order line and +charged to the customer. diff --git a/sale_margin_delivery_cost/readme/USAGE.md b/sale_margin_delivery_cost/readme/USAGE.md new file mode 100644 index 000000000..9b2128aae --- /dev/null +++ b/sale_margin_delivery_cost/readme/USAGE.md @@ -0,0 +1,6 @@ +In the Sales Order, add other sales costs in the "Other Costs" field, +after the sales order lines. + +Using the DUPDATE SHIPPING COSTS button will update the estimated cost +in the Other Costs field instead of a sales order line, if the selected +Shipping Method is configured that way. diff --git a/sale_margin_delivery_cost/security/ir.model.access.csv b/sale_margin_delivery_cost/security/ir.model.access.csv new file mode 100644 index 000000000..e24fbaa6b --- /dev/null +++ b/sale_margin_delivery_cost/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_order_other_cost,access_sale_order_other_cost,model_sale_order_other_cost,sales_team.group_sale_salesman,1,1,1,1 diff --git a/sale_margin_delivery_cost/static/description/icon.png b/sale_margin_delivery_cost/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sale_margin_delivery_cost/static/description/icon.png differ diff --git a/sale_margin_delivery_cost/static/description/index.html b/sale_margin_delivery_cost/static/description/index.html new file mode 100644 index 000000000..65d1feb8f --- /dev/null +++ b/sale_margin_delivery_cost/static/description/index.html @@ -0,0 +1,461 @@ + + + + + +Sales Margin after other estimated costs + + + +
+ + + +Odoo Community Association + +
+

Sales Margin after other estimated costs

+ +

Beta License: AGPL-3 OCA/margin-analysis Translate me on Weblate Try me on Runboat

+

Track expected shipping costs, allowing more accurate margin +calculations.

+

Costs could include packaging, documentation or customs expenses. These +may be consumables or services, not directly included in sales order +lines nor accounted with the invoice. But we may still ant the Sales +Order margin to consider these costs, especially if business margins are +tight.

+

Also allows for carrier shipping costs to be estimated separately, +instead of being automatically added as a sales order line, to charge +the customer.

+

This is useful in the case the customer is charge with a shipping fee +that can be very different from the actual shipping cost, or when no +shipping fee is charged at all.

+

In this case the expected shipping costs, computed by the UPDATE +SHIPPING COSTS button, can be stored as Other Costs and considered for +the sales order margin, instead being added as a sales order line and +charged to the customer.

+

Table of contents

+ +
+

Configuration

+

On Shipping Methods there is a field to configure them to be tracked +under Other Costs instead of Sales Order Lines.

+

Navigate to Sales > Configuration > Sales Orders > Shipping Methods:

+

On a Shipping Method, set the Charging Policy field:

+
    +
  • “As SO Line” is the standard behaviour
  • +
  • “As Other Cost” add the cost as Other Costs sale order line.
  • +
+
+
+

Usage

+

In the Sales Order, add other sales costs in the “Other Costs” field, +after the sales order lines.

+

Using the DUPDATE SHIPPING COSTS button will update the estimated cost +in the Other Costs field instead of a sales order line, if the selected +Shipping Method is configured that way.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Open Source Integrators
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

dreispt

+

This module is part of the OCA/margin-analysis project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/sale_margin_delivery_cost/tests/__init__.py b/sale_margin_delivery_cost/tests/__init__.py new file mode 100644 index 000000000..fdb371d88 --- /dev/null +++ b/sale_margin_delivery_cost/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_margin_delivery_cost diff --git a/sale_margin_delivery_cost/tests/test_sale_margin_delivery_cost.py b/sale_margin_delivery_cost/tests/test_sale_margin_delivery_cost.py new file mode 100644 index 000000000..f9f5e4e9f --- /dev/null +++ b/sale_margin_delivery_cost/tests/test_sale_margin_delivery_cost.py @@ -0,0 +1,89 @@ +# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestSaleMarginDeliveryCost(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.product = cls.env["product.product"].create( + { + "name": "Test Product", + "type": "service", + "list_price": 100.0, + "standard_price": 60.0, + } + ) + cls.carrier_product = cls.env["product.product"].create( + { + "name": "Carrier Product", + "type": "service", + "list_price": 15.0, + } + ) + cls.carrier = cls.env["delivery.carrier"].create( + { + "name": "Test Carrier", + "product_id": cls.carrier_product.id, + "delivery_type": "fixed", + "charge_policy": "other", + } + ) + + def _create_sale_order(self): + return self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_qty": 1, + "product_uom_id": self.uom_unit.id, + "price_unit": 100.0, + }, + ) + ], + } + ) + + def test_margin_with_other_cost(self): + order = self._create_sale_order() + order._compute_margin() + self.assertEqual(order.margin, 40.0) + self.env["sale.order.other.cost"].create( + { + "order_id": order.id, + "name": "Packaging", + "price_unit": 10.0, + } + ) + order._compute_margin() + self.assertEqual(order.margin, 30.0) + self.assertEqual(order.margin_percent, 0.3) + + def test_set_delivery_line_other_policy(self): + order = self._create_sale_order() + order.set_delivery_line(self.carrier, 15.0) + self.assertEqual(order.carrier_id, self.carrier) + self.assertFalse(order.order_line.filtered("is_delivery")) + self.assertEqual(len(order.other_cost_ids), 1) + self.assertEqual(order.other_cost_ids.price_unit, 15.0) + self.assertEqual(order.other_cost_ids.product_id, self.carrier_product) + order._compute_margin() + self.assertEqual(order.margin, 25.0) + + def test_set_delivery_line_sale_policy(self): + order = self._create_sale_order() + carrier = self.carrier.copy({"charge_policy": "sale"}) + order.set_delivery_line(carrier, 15.0) + delivery_lines = order.order_line.filtered("is_delivery") + self.assertEqual(len(delivery_lines), 1) + self.assertEqual(delivery_lines.price_unit, 15.0) + self.assertFalse(order.other_cost_ids) diff --git a/sale_margin_delivery_cost/views/delivery_carrier.xml b/sale_margin_delivery_cost/views/delivery_carrier.xml new file mode 100644 index 000000000..d6900f6c6 --- /dev/null +++ b/sale_margin_delivery_cost/views/delivery_carrier.xml @@ -0,0 +1,12 @@ + + + Delivery Carrier: charge policy + delivery.carrier + + + + + + + + diff --git a/sale_margin_delivery_cost/views/sale_order.xml b/sale_margin_delivery_cost/views/sale_order.xml new file mode 100644 index 000000000..524686ede --- /dev/null +++ b/sale_margin_delivery_cost/views/sale_order.xml @@ -0,0 +1,26 @@ + + + Sale Order: other costs + sale.order + + + + + + + + + + + + + + + + +