Skip to content

[ADD] book_pricelist: Added book price based on price lsit #831

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

Draft
wants to merge 2 commits into
base: 18.0
Choose a base branch
from
Draft
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 book_pricelist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions book_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
'name': "Book Pricelist",
'category': '',
'version': '0.1',
'depends': ['sale'],
'sequence': 1,
'application': True,
'installable': True,
'data': [
'views/sale_order_views.xml',
'views/account_move_view.xml',
],
'license': 'AGPL-3'
}
2 changes: 2 additions & 0 deletions book_pricelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order_line
from . import account_move_line
21 changes: 21 additions & 0 deletions book_pricelist/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo import fields, models, api


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

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

@api.depends('product_id', 'quantity', 'sale_line_ids')
def _compute_book_price(self):
for rec in self:
if rec.product_id:
pricelist = rec.sale_line_ids.order_id.pricelist_id
if pricelist:
rec.book_price = pricelist._get_product_price(
rec.product_id, rec.quantity
)
else:
rec.book_price = rec.product_id.lst_price
else:
rec.book_price = 0
21 changes: 21 additions & 0 deletions book_pricelist/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo import fields, models, api


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 rec in self:
if not rec.product_id:
rec.book_price = 0
continue
pricelist = rec.order_id.pricelist_id
if rec.product_id and pricelist:
rec.book_price = pricelist._get_product_price(
rec.product_id, rec.product_uom_qty
)
else:
rec.book_price = rec.product_id.lst_price
15 changes: 15 additions & 0 deletions book_pricelist/views/account_move_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<record id="account_move_view_form_inherit" model="ir.ui.view">
<field name="name">account.move.view.form.inherit</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='product_id']" position="after">
<field name="book_price"/>
</xpath>
</field>
</record>
</data>
</odoo>
13 changes: 13 additions & 0 deletions book_pricelist/views/sale_order_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_pricelist" model="ir.ui.view">
<field name="name">sale.order.inherited.form.pricelist</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//list//field[@name='product_template_id']" position="after">
<field name="book_price"/>
</xpath>
</field>
</record>
</odoo>