Skip to content

Commit d959920

Browse files
committed
[ADD] sale_pricelist: add book price to sale order and invoice lines
Purpose: Client requires the ability to see the original pricelist on sale order lines and invoice order lines. This will used to compare between pricelist and any manually adjusted price on the lines. Technical changes: 1. Add a new field book_price on both sale.order.line and account.move.line models. 2. Display the book_price field: - On the Sales Order form (order lines). - On the Account Move form (invoice lines). - In Account Move, the field is visible only when move.type is a Customer Invoice. 3. Business Logic for book_price Calculation: - If no product is not exist then book_price should be 0.0. - If a product exists but is not included in the selected pricelist, book_price should be set to the product’s original sales price. - If the product exists in the selected pricelist, compute book_price based on the pricelist rule, using Selected pricelist, product, quantity task-5382732
1 parent b68a192 commit d959920

File tree

7 files changed

+71
-0
lines changed

7 files changed

+71
-0
lines changed

sale_pricelist/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

sale_pricelist/__manifest__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
'author': 'Odoo S.A.',
3+
'name': 'Purchase Discount',
4+
'description': """
5+
Add a "Book Price" field on Sales Order Lines and Invoice Lines to display the original
6+
pricelist price of a product. This helps users compare the standard pricelist amount
7+
with any manually adjusted line price, ensuring pricing transparency and better control
8+
over discount or custom price modifications.
9+
""",
10+
'depends': ['sale_management'],
11+
'license': 'LGPL-3',
12+
'data': [
13+
'views/sale_order_views.xml',
14+
'views/account_move_views.xml',
15+
],
16+
'application': True,
17+
'installable': True
18+
}

sale_pricelist/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import sale_order_line
2+
from . import account_move_line
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import fields, models
2+
3+
4+
class AccountMoveLine(models.Model):
5+
_inherit = "account.move.line"
6+
7+
book_price = fields.Float(related="sale_line_ids.book_price", readonly=True)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from odoo import models, fields, api
2+
3+
4+
class SaleOrderLine(models.Model):
5+
_inherit = "sale.order.line"
6+
7+
book_price = fields.Float(compute="_compute_pricelist", readonly=True)
8+
9+
@api.depends("product_id", "product_uom_qty", "order_id.pricelist_id", "product_template_id.list_price")
10+
def _compute_pricelist(self):
11+
for record in self:
12+
if not record.product_id:
13+
record.book_price = 0.0
14+
elif not record.order_id.pricelist_id:
15+
record.book_price = record.product_template_id.list_price
16+
else:
17+
record.book_price = record.order_id.pricelist_id._get_product_price(record.product_id, record.product_uom_qty)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="view_move_form" model="ir.ui.view">
4+
<field name="name">account.move.view.form.inherit</field>
5+
<field name="model">account.move</field>
6+
<field name="inherit_id" ref="account.view_move_form"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//field[@name='quantity']" position="before">
9+
<field name="book_price" invisible="move_type != 'out_invoice'"/>
10+
</xpath>
11+
</field>
12+
</record>
13+
</odoo>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="sale_order_from_pricelist" model="ir.ui.view">
4+
<field name="name">sale.order.view.form.inherit</field>
5+
<field name="model">sale.order</field>
6+
<field name="inherit_id" ref="sale.view_order_form"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//list//field[@name='product_uom_qty']" position="before">
9+
<field name="book_price"/>
10+
</xpath>
11+
</field>
12+
</record>
13+
</odoo>

0 commit comments

Comments
 (0)