Skip to content

Commit

Permalink
Merge commit 'refs/pull/1562/head' of https://github.com/oca/sale-wor…
Browse files Browse the repository at this point in the history
…kflow into 13.0-2020
  • Loading branch information
docker-odoo committed Apr 9, 2023
2 parents 0f08cb3 + 7f12120 commit f1cb8fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions sale_order_type/models/sale.py
Expand Up @@ -102,6 +102,15 @@ def onchange_type_id(self):
line_vals.update({"route_id": order_type.route_id.id})
order.order_line.update(line_vals)

@api.onchange("company_id")
def _onchange_company_id(self):
super(SaleOrder, self)._onchange_company_id()
if (
self.type_id.warehouse_id
and self.type_id.warehouse_id.company_id == self.company_id
):
self.warehouse_id = self.type_id.warehouse_id

@api.model
def create(self, vals):
if vals.get("name", "/") == "/" and vals.get("type_id"):
Expand Down
8 changes: 7 additions & 1 deletion sale_order_type/tests/test_sale_order_type.py
Expand Up @@ -43,7 +43,7 @@ def setUp(self):
self.default_sale_type_id = self.env["sale.order.type"].search([], limit=1)
self.default_sale_type_id.sequence_id = False
self.warehouse = self.env["stock.warehouse"].create(
{"name": "Warehouse Test", "code": "WT"}
{"name": "Warehouse Test", "code": "WT", "company_id": self.env.company.id}
)
self.product = self.env["product.product"].create(
{"type": "service", "invoice_policy": "order", "name": "Test product"}
Expand Down Expand Up @@ -169,6 +169,12 @@ def test_invoice_onchange_type(self):
self.assertEqual(invoice.invoice_payment_term_id, sale_type.payment_term_id)
self.assertEqual(invoice.journal_id, sale_type.journal_id)

def test_sale_onchange_company_id(self):
order = self.create_sale_order()
order.company_id = self.env.company.id
order._onchange_company_id()
self.assertEqual(order.company_id, self.sale_type.company_id)

def test_invoice_change_partner(self):
invoice = self.create_invoice()
self.assertEqual(invoice.sale_type_id, self.sale_type)
Expand Down

0 comments on commit f1cb8fc

Please sign in to comment.