Skip to content

[ADD] product_pricelist: Book price added in Sale Order Line #398

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

Closed
Closed
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
1 change: 1 addition & 0 deletions product_pricelist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions product_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
'name': "Book Price (Pricelist Price)",
'version': '1.0',
'depends': ['sale_management'],
'author': "ppch",
'category': 'Category',
'description': """
Book Price (Pricelist Price) on sales order lines and invoice lines
which will be used to compare between Book Price (Pricelist Price) and
manually adjusted price on the lines.
""",
'license': "LGPL-3",
'data': [
'views/sale_order_line_views.xml',
'views/account_move_line_views.xml',
],
'installable': True,
}
2 changes: 2 additions & 0 deletions product_pricelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move_line
from . import sale_order_line
7 changes: 7 additions & 0 deletions product_pricelist/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import api, fields, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

book_price = fields.Float(related='sale_line_ids.book_price')
22 changes: 22 additions & 0 deletions product_pricelist/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import api, fields, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

book_price = fields.Float(string="Book Price", compute='_compute_book_price')

@api.depends('product_id', 'product_uom_qty', 'order_id.pricelist_id')
def _compute_book_price(self):
for record in self:
if not record.product_id:
record.book_price = 0.0
continue

pricelist = record.order_id.pricelist_id if record.order_id else None
if pricelist:
record.book_price = pricelist._get_product_price(
record.product_id, record.product_uom_qty
)
else:
record.book_price = record.product_id.lst_price
13 changes: 13 additions & 0 deletions product_pricelist/views/account_move_line_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_move_form_inherit_book_price" model="ir.ui.view">
<field name="name">account.move.form.inherite.book.price</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook//page//field[@name='invoice_line_ids']//list//field[@name='quantity']" position="before">
<field name="book_price" readonly="True" column_invisible="context.get('default_move_type') != 'out_invoice'"/>
</xpath>
</field>
</record>
</odoo>
13 changes: 13 additions & 0 deletions product_pricelist/views/sale_order_line_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="sale_order_form_inherit_book_price" model="ir.ui.view">
<field name="name">sale.order.form.inherite.book.price</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook//page//list//field[@name='product_uom_qty']" position="before">
<field name="book_price" readonly="True"/>
</xpath>
</field>
</record>
</odoo>