Skip to content

Commit d2c702a

Browse files
committed
[IMP] product_pricelist: defined _compute_book_price for invoice line
Defined _compute_book_price function which will be depends on product_id, quantity and invoice_origin whenever above mentioned field will change on that time based on condition book_price will be calculated task - 4602859
1 parent b94791c commit d2c702a

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

product_pricelist/__manifest__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
2-
'name': "Book Price Pricelist",
2+
'name': "Book Price (Pricelist Price)",
33
'version': '1.0',
4-
'depends': ['base', 'sale_management', 'account'],
4+
'depends': ['base', 'sale_management'],
55
'author': "ppch",
66
'category': 'Category',
77
'description': """
8-
Book Price on Sales order line and accunt move line
8+
Book Price (Pricelist Price) on sales order lines and invoice lines
9+
which will be used to compare between Book Price (Pricelist Price) and manually adjusted price on the lines
910
""",
1011
'license': "LGPL-3",
1112
'data': [
1213
'views/sale_order_line_views.xml',
1314
'views/account_move_line_views.xml',
1415
],
1516
'installable': True,
16-
}
17+
}

product_pricelist/models/account_move_line.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
class AccountMoveLine(models.Model):
55
_inherit = "account.move.line"
66

7-
book_price = fields.Float(
8-
string="Book Price",
9-
compute="_compute_book_price",
10-
store=True
11-
)
7+
book_price = fields.Float(string="Book Price", compute="_compute_book_price", store=True)
128

139
@api.depends('product_id', 'quantity', 'move_id.invoice_origin')
1410
def _compute_book_price(self):
15-
pass
16-
#define
11+
for record in self:
12+
if not record.product_id:
13+
record.book_price = 0.0
14+
continue
15+
16+
sale_order = self.env['sale.order'].search([('name', '=', record.move_id.invoice_origin)], limit=1)
17+
if sale_order:
18+
record.book_price = sale_order.pricelist_id._get_product_price(
19+
record.product_id, record.quantity
20+
) * record.quantity
21+
else:
22+
record.book_price = record.product_id.lst_price * record.quantity

product_pricelist/models/sale_order_line.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
class SaleOrderLine(models.Model):
55
_inherit = "sale.order.line"
66

7-
book_price = fields.Float(
8-
string="Book Price",
9-
compute="_compute_book_price",
10-
store=True
11-
)
7+
book_price = fields.Float(string="Book Price", compute="_compute_book_price", store=True)
128

13-
@api.depends('product_id', 'product_uom_qty')
9+
@api.depends('product_id', 'product_uom_qty', 'order_id.pricelist_id')
1410
def _compute_book_price(self):
1511
for record in self:
1612
if not record.product_id:
1713
record.book_price = 0.0
14+
continue
15+
16+
pricelist = record.order_id.pricelist_id if record.order_id else None
17+
if pricelist:
18+
record.book_price = pricelist._get_product_price(
19+
record.product_id, record.product_uom_qty
20+
) * record.product_uom_qty
1821
else:
19-
record.book_price = record._get_pricelist_price() * record.product_uom_qty
22+
record.book_price = record.product_id.lst_price * record.product_uom_qty

product_pricelist/views/account_move_line_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<odoo>
3-
<record id="account_move_form_inherite_book_price" model="ir.ui.view">
3+
<record id="account_move_form_inherit_book_price" model="ir.ui.view">
44
<field name="name">account.move.form.inherite.book.price</field>
55
<field name="model">account.move</field>
66
<field name="inherit_id" ref="account.view_move_form"/>

product_pricelist/views/sale_order_line_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<odoo>
3-
<record id="sale_order_form_inherite_book_price" model="ir.ui.view">
3+
<record id="sale_order_form_inherit_book_price" model="ir.ui.view">
44
<field name="name">sale.order.form.inherite.book.price</field>
55
<field name="model">sale.order</field>
66
<field name="inherit_id" ref="sale.view_order_form"/>

0 commit comments

Comments
 (0)