Skip to content
Open
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 purchase_sale_inter_company/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def action_confirm(self):
for order in self.filtered("auto_purchase_order_id"):
for line in order.order_line.sudo():
if line.auto_purchase_line_id:
line.auto_purchase_line_id.price_unit = line.price_unit
line._intercompany_update_purchase_line_price()
return super().action_confirm()
11 changes: 11 additions & 0 deletions purchase_sale_inter_company/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ class SaleOrderLine(models.Model):
readonly=True,
copy=False,
)

def _intercompany_update_purchase_line_price(self):
"""Writes the net price (price_unit after discount) to the purchase line.

Can be inherited in other modules to change the behavior, for example
if discounts are available in the purchase order.
"""
self.ensure_one()
self.auto_purchase_line_id.price_unit = self.price_unit * (
1 - self.discount / 100
)
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ def test_so_change_price(self):
sale.action_confirm()
self.assertEqual(self.purchase_company_a.order_line.price_unit, 10)

def test_so_change_price_with_discount(self):
self.company_b.sale_auto_validation = False
sale = self._approve_po()
sale.order_line.price_unit = 100
sale.order_line.discount = 10
sale.action_confirm()
self.assertEqual(self.purchase_company_a.order_line.price_unit, 90.0)

def test_po_with_contact_as_partner(self):
contact = self.env["res.partner"].create(
{"name": "Test contact", "parent_id": self.partner_company_b.id}
Expand Down
Loading