Skip to content

Commit

Permalink
[FIX] purchase_order_type: preserve order type when matches company
Browse files Browse the repository at this point in the history
Before this fix, when onchange event for company_id was fired, type for
purchase order was always set, then sometimes overwritten, even if
former order type was compatible with the new company.

This cause an incompatibility with e.g. purchase_order_type_dashboard.
When PO creation form is accesed coming from PO dashboard, selected
order type was actually igored, because onchange for company was fired
and order type overwritten. This fix it.
  • Loading branch information
dalonsod committed Jun 14, 2024
1 parent a4590ae commit e6ee1fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion purchase_order_type/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ def _default_order_type(self):

@api.onchange("company_id")
def _onchange_company(self):
self.order_type = self._default_order_type()
if not self.order_type or (
self.order_type
and self.order_type.company_id not in [self.company_id, False]
):
self.order_type = self._default_order_type()
3 changes: 3 additions & 0 deletions purchase_order_type/tests/test_purchase_order_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def test_purchase_order_change_company(self):
order.onchange_partner_id()
self.assertEqual(order.order_type, self.type2)
order._onchange_company()
self.assertEqual(order.order_type, self.type2)
order.write({"order_type": False})
order._onchange_company()
self.assertEqual(order.order_type, order._default_order_type())

def test_purchase_order_type_company_error(self):
Expand Down

0 comments on commit e6ee1fd

Please sign in to comment.