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 deltatech_purchase_add_extra_line/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
=======================
Purchase Add Extra Line
=======================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fdeltatech-lightgray.png?logo=github
:target: https://github.com/dhongu/deltatech/tree/18.0/deltatech_purchase_add_extra_line
:alt: dhongu/deltatech

|badge1| |badge2| |badge3|

Purchase Add Extra Line Extension
=================================

This module introduces an automated process for adding extra lines
(e.g., service fees, handling charges, or supplementary products) to
Purchase Orders in Odoo. It's designed to help procurement teams
consistently apply additional costs or items based on the primary
products being purchased.

Key Features
============

1. **Configurable Extra Products**:

- Allows users to define an **Extra Product** directly on the product
template.
- Enables automated adding of this extra line whenever the primary
product is added to a Purchase Order.

2. **Flexible Pricing Logic**:

- The unit price for the extra line can be computed as a
**percentage** of the primary product's price.
- If the percentage is set to zero, the system uses the standard
**List Price** of the extra product.

3. **Procurement Efficiency**:

- Reduces manual entry errors and ensures that all mandatory
supplementary costs or items are included in every relevant
Purchase Order.

Usage
=====

1. Go to **Purchase > Products > Products**.
2. Open a product and locate the **Extra Line Configuration** (typically
in the Purchase or a dedicated tab).
3. Select the **Extra Product** you want to associate and set the
**Percentage** (if applicable).
4. Create a new **Purchase Order** and add the primary product to the
order lines.
5. The system will automatically add the extra product as a separate
line with the pre-calculated price.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `Terrabit Issues <https://www.terrabit.ro/helpdesk>`_.
In case of trouble, please check there if your issue has already been reported.

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

Credits
=======

Authors
-------

* Terrabit
* Dorin Hongu

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

.. |maintainer-dhongu| image:: https://github.com/dhongu.png?size=40px
:target: https://github.com/dhongu
:alt: dhongu

Current maintainer:

|maintainer-dhongu|

This module is part of the `dhongu/deltatech <https://github.com/dhongu/deltatech/tree/18.0/deltatech_purchase_add_extra_line>`_ project on GitHub.

You are welcome to contribute.
4 changes: 4 additions & 0 deletions deltatech_purchase_add_extra_line/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2025 Deltatech
# See README.rst file on addons root folder for license details

from . import models
17 changes: 17 additions & 0 deletions deltatech_purchase_add_extra_line/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# © 2025 Deltatech
# See README.rst file on addons root folder for license details

{
"name": "Purchase Add Extra Line",
"summary": "Purchase Add Extra Line",
"version": "19.0.1.0.2",
"category": "Sales",
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
"depends": ["purchase"],
"license": "LGPL-3",
"data": ["views/product_view.xml", "views/purchase_view.xml"],
"images": ["static/description/main_screenshot.png"],
"development_status": "Production/Stable",
"maintainers": ["dhongu"],
}
6 changes: 6 additions & 0 deletions deltatech_purchase_add_extra_line/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# © 2025 Deltatech
# See README.rst file on addons root folder for license details


from . import product_template
from . import purchase
14 changes: 14 additions & 0 deletions deltatech_purchase_add_extra_line/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# © 2025 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

extra_product_id = fields.Many2one("product.product")
extra_percent = fields.Float()
extra_qty = fields.Float(default=1.0)
82 changes: 82 additions & 0 deletions deltatech_purchase_add_extra_line/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# © 2025 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details

import uuid

from odoo import api, fields, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

def action_rfq_send(self):
self.order_line.with_context(backend=True).check_extra_product()
return super().action_rfq_send()

def print_quotation(self):
self.order_line.with_context(backend=True).check_extra_product()
return super().print_quotation()

@api.onchange("order_line")
def onchange_order_line(self):
"""
Update extra product in backend
:return: super
"""
self.order_line.with_context(backend=True).check_extra_product()


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

line_uuid = fields.Char()

@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
for line in res:
line.check_extra_product()
return res

def unlink(self):
for line in self:
if line.product_id.extra_product_id:
extra_line_id = line.order_id.order_line.filtered(
lambda l: line.line_uuid is not False and l.line_uuid == line.line_uuid and l.id != line.id
)
if extra_line_id:
extra_line_id.unlink()
return super().unlink()

def check_extra_product(self):
for line in self:
if line.order_id.state not in ["draft", "sent"]:
continue
if not line.product_id.extra_product_id:
continue
extra_product = line.product_id.extra_product_id
extra_line_id = line.order_id.order_line.filtered(
lambda l: line.line_uuid is not False and l.line_uuid == line.line_uuid and l.id != line.id
)
if not extra_line_id:
new_uuid = str(uuid.uuid4())
values = {
"product_qty": line.product_qty * (line.product_id.extra_qty or 1.0),
"product_id": extra_product.id,
"product_uom_id": extra_product.uom_id.id,
"order_id": line.order_id.id,
"sequence": line.sequence + 1,
"line_uuid": new_uuid,
}
backend = self.env.context.get("backend", False)
if backend:
extra_line_id = line.order_id.order_line.new(values)
else:
extra_line_id = line.order_id.order_line.create(values)
line.line_uuid = new_uuid
product_qty = line.product_qty * (line.product_id.extra_qty or 1.0)
if product_qty != extra_line_id.product_qty:
extra_line_id.product_qty = product_qty
if line.product_id.extra_percent:
extra_line_id.price_unit = line.price_unit * (line.product_id.extra_percent or 0.0) / 100.0
8 changes: 8 additions & 0 deletions deltatech_purchase_add_extra_line/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
requires = [
"whool",
]
build-backend = "whool.buildapi"

[project]
name = "odoo-addon-deltatech-purchase-add-extra-line"
27 changes: 27 additions & 0 deletions deltatech_purchase_add_extra_line/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Purchase Add Extra Line Extension
=================================

This module introduces an automated process for adding extra lines (e.g., service fees, handling charges, or supplementary products) to Purchase Orders in Odoo. It's designed to help procurement teams consistently apply additional costs or items based on the primary products being purchased.

Key Features
============

1. **Configurable Extra Products**:
* Allows users to define an **Extra Product** directly on the product template.
* Enables automated adding of this extra line whenever the primary product is added to a Purchase Order.

2. **Flexible Pricing Logic**:
* The unit price for the extra line can be computed as a **percentage** of the primary product's price.
* If the percentage is set to zero, the system uses the standard **List Price** of the extra product.

3. **Procurement Efficiency**:
* Reduces manual entry errors and ensures that all mandatory supplementary costs or items are included in every relevant Purchase Order.

Usage
=====

1. Go to **Purchase > Products > Products**.
2. Open a product and locate the **Extra Line Configuration** (typically in the Purchase or a dedicated tab).
3. Select the **Extra Product** you want to associate and set the **Percentage** (if applicable).
4. Create a new **Purchase Order** and add the primary product to the order lines.
5. The system will automatically add the extra product as a separate line with the pre-calculated price.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading