Skip to content
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
2 changes: 1 addition & 1 deletion product_supplierinfo_for_customer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"category": "Sales Management",
"license": "AGPL-3",
"maintainers": ["luisg123v"],
"depends": ["product"],
"depends": ["sale"],

Choose a reason for hiding this comment

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

You are adding this on wrong module. It should be added on this one: https://github.com/OCA/sale-workflow/blob/17.0/product_supplierinfo_for_customer_sale/__manifest__.py

That one must not have sale module dependency.

Copy link
Author

Choose a reason for hiding this comment

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

True! PR to sale-workflow

"data": [
"security/ir.model.access.csv",
"views/product_views.xml",
Expand Down
1 change: 1 addition & 0 deletions product_supplierinfo_for_customer/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import product_product
from . import product_template
from . import res_partner
from . import sale_order_line
14 changes: 14 additions & 0 deletions product_supplierinfo_for_customer/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo import models


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

def _get_product_price_context(self):
"""Extend to make sure the partner context is set for price computation."""
self.ensure_one()
context = super()._get_product_price_context()
# Add partner_id to the context
if self.order_id.partner_id:
context.update({"partner_id": self.order_id.partner_id.id})
return context
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def setUpClass(cls):
cls.customerinfo_model = cls.env["product.customerinfo"]
cls.pricelist_item_model = cls.env["product.pricelist.item"]
cls.pricelist_model = cls.env["product.pricelist"]
cls.sale_order_model = cls.env["sale.order"]
cls.sale_order_line_model = cls.env["sale.order.line"]
cls.customer = cls._create_customer("customer1")
cls.unknown = cls._create_customer("customer2")
cls.product = cls.env.ref("product.product_product_4")
Expand All @@ -38,6 +40,27 @@ def setUpClass(cls):
"product_tmpl_id": cls.product.product_tmpl_id.id,
}
)
cls.pricelist_customer = cls.pricelist_model.create(
{
"name": "Test Pricelist Customer",
"currency_id": cls.env.ref("base.USD").id,
}
)
cls.pricelist_item_customer = cls.pricelist_item_model.create(
{
"applied_on": "3_global",
"base": "partner",
"name": "Test Pricelist Item",
"pricelist_id": cls.pricelist_customer.id,
"compute_price": "formula",
}
)
cls.sale_order_1 = cls.sale_order_model.create(
{
"partner_id": cls.customer.id,
"pricelist_id": cls.pricelist_customer.id,
}
)

@classmethod
def _create_customer(cls, name):
Expand Down Expand Up @@ -185,3 +208,37 @@ def test_variant_supplierinfo_price(self):
"partner", product_1.uom_id, self.company.currency_id, self.company
)
self.assertEqual(res[product_1.id], 10.0)

def test_product_supplierinfo_price_with_context_passed(self):
"""Test normal behaviour when context is passed from view."""
# GIVEN / WHEN
self.sale_order_line_w_ctx = self.sale_order_line_model.with_context(
partner_id=self.customer.id
).create(
{
"order_id": self.sale_order_1.id,
"product_id": self.product.id,
"product_uom_qty": 1.0,
}
)
# THEN
self.assertEqual(self.sale_order_line_w_ctx.price_unit, 100.0)

def test_product_supplierinfo_price_without_context_passed(self):
"""Test case when context is not passed during price computation.

The context should be created in the method _get_product_price_context.
"""
# GIVEN / WHEN
self.sale_order_line_wo_ctx = self.sale_order_line_model.create(
{
"order_id": self.sale_order_1.id,
"product_id": self.product.id,
"product_uom_qty": 1.0,
}
)
# THEN
self.assertEqual(
self.sale_order_line_wo_ctx.price_unit,
100.0,
)
Loading