From 15f22da6d99ab74ff54449f585a6e27b96f8dd22 Mon Sep 17 00:00:00 2001 From: isgos-odoo Date: Fri, 13 Feb 2026 18:13:27 +0530 Subject: [PATCH] [ADD] add_pricelist_price: add book price to sale and invoice lines Implemented a new module to compute and display the 'Book Price' (pricelist price) on Sale Order and Account Move lines for comparison with the actual unit price. Changes: - Models: Added `book_price` computed field to `sale.order.line` to fetch price from the order's pricelist. - Models: Added `book_price` computed field to `account.move.line` with fallback logic for related sale orders or partner pricelists. - Views: Extended Sale Order form to display `book_price` after quantity. - Views: Extended Invoice form to display `book_price` before unit price (for customer invoices only). --- add_pricelist_price/__init__.py | 1 + add_pricelist_price/__manifest__.py | 15 +++++++++ add_pricelist_price/models/__init__.py | 2 ++ .../models/account_move_line.py | 31 +++++++++++++++++++ add_pricelist_price/models/sale_order_line.py | 22 +++++++++++++ .../views/account_move_views.xml | 13 ++++++++ .../views/sale_order_line_views.xml | 13 ++++++++ 7 files changed, 97 insertions(+) create mode 100644 add_pricelist_price/__init__.py create mode 100644 add_pricelist_price/__manifest__.py create mode 100644 add_pricelist_price/models/__init__.py create mode 100644 add_pricelist_price/models/account_move_line.py create mode 100644 add_pricelist_price/models/sale_order_line.py create mode 100644 add_pricelist_price/views/account_move_views.xml create mode 100644 add_pricelist_price/views/sale_order_line_views.xml diff --git a/add_pricelist_price/__init__.py b/add_pricelist_price/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/add_pricelist_price/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/add_pricelist_price/__manifest__.py b/add_pricelist_price/__manifest__.py new file mode 100644 index 00000000000..0ece82d7cdb --- /dev/null +++ b/add_pricelist_price/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': 'Add pricelist price', + 'version': '0.1.0', + 'description': 'Add pricelist price field.', + 'depends': [ + 'sale', 'account' + ], + 'data': [ + 'views/sale_order_line_views.xml', + 'views/account_move_views.xml' + ], + 'author': 'Ishwar Goswami', + 'license': 'LGPL-3', + 'installable': True +} diff --git a/add_pricelist_price/models/__init__.py b/add_pricelist_price/models/__init__.py new file mode 100644 index 00000000000..ea3d9579546 --- /dev/null +++ b/add_pricelist_price/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order_line +from . import account_move_line diff --git a/add_pricelist_price/models/account_move_line.py b/add_pricelist_price/models/account_move_line.py new file mode 100644 index 00000000000..5db4d5039d0 --- /dev/null +++ b/add_pricelist_price/models/account_move_line.py @@ -0,0 +1,31 @@ +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + book_price = fields.Monetary( + string="Book Price", + compute="_compute_book_price", + readonly=True, + ) + + @api.depends('product_id', 'quantity', 'move_id.partner_id') + def _compute_book_price(self): + for line in self: + if not line.product_id: + line.book_price = 0.0 + continue + + if line.sale_line_ids: + pricelist = line.sale_line_ids[0].order_id.pricelist_id + else: + pricelist = line.move_id.partner_id.property_product_pricelist + + if pricelist: + line.book_price = pricelist._get_product_price( + product=line.product_id, + quantity=line.quantity, + ) + else: + line.book_price = line.product_id.list_price diff --git a/add_pricelist_price/models/sale_order_line.py b/add_pricelist_price/models/sale_order_line.py new file mode 100644 index 00000000000..66c3c551fa1 --- /dev/null +++ b/add_pricelist_price/models/sale_order_line.py @@ -0,0 +1,22 @@ +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = ["sale.order.line"] + + book_price = fields.Monetary(compute="_compute_book_price", readonly=True) + + @api.depends('order_id.pricelist_id', 'product_id', 'product_uom_qty') + def _compute_book_price(self): + for line in self: + if not line.product_id: + line.book_price = 0 + continue + pricelist = line.order_id.pricelist_id + if line.product_id and pricelist: + line.book_price = pricelist._get_product_price( + product=line.product_id, + quantity=line.product_uom_qty, + ) + else: + line.book_price = line.product_id.lst_price diff --git a/add_pricelist_price/views/account_move_views.xml b/add_pricelist_price/views/account_move_views.xml new file mode 100644 index 00000000000..3becdb35c55 --- /dev/null +++ b/add_pricelist_price/views/account_move_views.xml @@ -0,0 +1,13 @@ + + + + account.move.form + account.move + + + + + + + + diff --git a/add_pricelist_price/views/sale_order_line_views.xml b/add_pricelist_price/views/sale_order_line_views.xml new file mode 100644 index 00000000000..8b7202dfa61 --- /dev/null +++ b/add_pricelist_price/views/sale_order_line_views.xml @@ -0,0 +1,13 @@ + + + + sale.order.form.inherit.book.price + sale.order + + + + + + + +