Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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': ['base', '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
22 changes: 22 additions & 0 deletions product_pricelist/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import api, fields, models


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

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

@api.depends('product_id', 'quantity', 'move_id.invoice_origin')
def _compute_book_price(self):
for record in self:
if not record.product_id:
record.book_price = 0.0
continue

sale_order = self.env['sale.order'].search([('name', '=', record.move_id.invoice_origin)], limit=1)
if sale_order:
record.book_price = sale_order.pricelist_id._get_product_price(
record.product_id, record.quantity
) * record.quantity
else:
record.book_price = record.product_id.lst_price * record.quantity
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
) * record.product_uom_qty

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why multiply again with uom_qty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated
now it will display only for 1 quantity

else:
record.book_price = record.product_id.lst_price * record.product_uom_qty
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('move_id.move_type') != 'out_inovice'"/>
</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>